diff --git a/Jenkinsfile b/Jenkinsfile
index 878cb8a..63136b8 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -10,7 +10,7 @@ pipeline {
post {
always {
- archiveArtifacts artifacts: 'target/*.jar', fingerprint: true
+ archiveArtifacts artifacts: 'target/MelonScoop-*.jar', fingerprint: true
cleanWs()
}
}
diff --git a/pom.xml b/pom.xml
index 40ecd2e..23e3614 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
moe.langua.lab.minecraft
MelonScoop
- 1.0.1-SNAPSHOT
+ 1.0.2
1.8
1.8
@@ -19,6 +19,10 @@
spigot-repo
https://hub.spigotmc.org/nexus/content/repositories/snapshots/
+
+ CodeMC
+ https://repo.codemc.org/repository/maven-public
+
@@ -38,6 +42,13 @@
com.google.guava
guava
21.0
+ provided
+
+
+ org.bstats
+ bstats-bukkit
+ 1.7
+ compile
@@ -58,6 +69,31 @@
1.8
+
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+ 3.2.0
+
+ true
+
+
+ org.bstats
+ moe.langua.lab.minecraft.scoop.bstats
+
+
+ false
+
+
+
+ package
+
+ shade
+
+
+
+
+
diff --git a/src/main/java/moe/langua/lab/minecraft/scoop/BootStrap.java b/src/main/java/moe/langua/lab/minecraft/scoop/BootStrap.java
index 57f0e04..aa2b4f3 100644
--- a/src/main/java/moe/langua/lab/minecraft/scoop/BootStrap.java
+++ b/src/main/java/moe/langua/lab/minecraft/scoop/BootStrap.java
@@ -2,18 +2,19 @@
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
-import org.bukkit.Bukkit;
+import org.bstats.bukkit.Metrics;
import org.bukkit.ChatColor;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.*;
import java.net.InetAddress;
-import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Pattern;
import java.util.zip.GZIPInputStream;
+import static java.nio.charset.StandardCharsets.UTF_8;
+
public class BootStrap extends JavaPlugin {
public SimpleDateFormat dateFormatter = new SimpleDateFormat("MM/dd/yyyy");
@@ -52,9 +53,10 @@ public void onEnable() {
//register commands and listeners
this.getServer().getScheduler().runTaskTimerAsynchronously(this, this::save, 6000, 6000/*Auto saving per five minute*/);
this.getServer().getPluginManager().registerEvents(new LoginListener(this), this);
+ this.getServer().getPluginManager().registerEvents(new UpdateChecker(this),this);
this.getCommand("dig").setExecutor(new DigCommand(this));
this.getLogger().info(ChatColor.DARK_AQUA + "Done! " + uniqueIDIndexMap.size() + " players with " + addressIndexMap.size() + " IP addresses loaded.");
-
+ new Metrics(this, 6823); // setup bStats
}
private void setup() throws IOException {
@@ -79,9 +81,9 @@ private void setup() throws IOException {
this.getLogger().info(ChatColor.DARK_AQUA +"Processing log file generated in "+dateFormatter.format(new Date(x))+" ("+(read++) + " out of "+ fileNumber + " files completed)");
File file = fileHashMap.get(x);
if (!file.getName().endsWith(".gz")) {
- reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));
+ reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), UTF_8));
} else {
- reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(file)), StandardCharsets.UTF_8));
+ reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(file)), UTF_8));
}
String line;
while ((line = reader.readLine()) != null) {
diff --git a/src/main/java/moe/langua/lab/minecraft/scoop/DigCommand.java b/src/main/java/moe/langua/lab/minecraft/scoop/DigCommand.java
index 2aae38f..e0b9cd9 100644
--- a/src/main/java/moe/langua/lab/minecraft/scoop/DigCommand.java
+++ b/src/main/java/moe/langua/lab/minecraft/scoop/DigCommand.java
@@ -16,11 +16,12 @@
public class DigCommand implements CommandExecutor {
+ /*
private static final String IPV4_ADDRESS_REGEX = "^(([01]?\\\\d\\\\d?|2[0-4]\\\\d|25[0-5])\\\\.){3}([01]?\\\\d\\\\d?|2[0-4]\\\\d|25[0-5])$";
private static final Pattern IPV4_ADDRESS_REGEX_PATTERN = Pattern.compile(IPV4_ADDRESS_REGEX);
private static final String IPV6_ADDRESS_REGEX = "(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]+|::(ffff(:0{1,4})?:)?((25[0-5]|(2[0-4]|1?[0-9])?[0-9])\\.){3}(25[0-5]|(2[0-4]|1?[0-9])?[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1?[0-9])?[0-9])\\.){3}(25[0-5]|(2[0-4]|1?[0-9])?[0-9]))";
private static final Pattern IPV6_ADDRESS_REGEX_PATTERN = Pattern.compile(IPV6_ADDRESS_REGEX);
-
+ */
private BootStrap instance;
@@ -120,7 +121,7 @@ public boolean onCommand(CommandSender commandSender, Command command, String s,
for (long x : timeList) {
OfflinePlayer player = Bukkit.getOfflinePlayer(result.get(x));
stringBuilder.append(ChatColor.YELLOW).append(" -").append(player.getName());
- if(player.isBanned()) stringBuilder.append(ChatColor.RED).append(" (Banned)");
+ if (player.isBanned()) stringBuilder.append(ChatColor.RED).append(" (Banned)");
stringBuilder.append(ChatColor.GRAY).append(ChatColor.ITALIC).append(" (").append(instance.dateFormatter.format(new Date(x))).append(")").append("\n");
}
stringBuilder.delete(stringBuilder.length() - 1, stringBuilder.length());
diff --git a/src/main/java/moe/langua/lab/minecraft/scoop/LoginListener.java b/src/main/java/moe/langua/lab/minecraft/scoop/LoginListener.java
index aca97c8..96ec45b 100644
--- a/src/main/java/moe/langua/lab/minecraft/scoop/LoginListener.java
+++ b/src/main/java/moe/langua/lab/minecraft/scoop/LoginListener.java
@@ -6,7 +6,6 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
-import org.bukkit.event.player.PlayerLoginEvent;
import java.net.InetAddress;
import java.util.ArrayList;
@@ -45,7 +44,7 @@ public void onLogin(AsyncPlayerPreLoginEvent event) {
stringBuilder.delete(stringBuilder.length() - 1, stringBuilder.length());
instance.getLogger().warning(stringBuilder.toString());
for (Player x : Bukkit.getOnlinePlayers()) {
- if (x.hasPermission("melonscoop.dig")) x.sendMessage(stringBuilder.toString());
+ if (x.hasPermission("melonscoop.alarm")) x.sendMessage(stringBuilder.toString());
}
}
}
diff --git a/src/main/java/moe/langua/lab/minecraft/scoop/UpdateChecker.java b/src/main/java/moe/langua/lab/minecraft/scoop/UpdateChecker.java
new file mode 100644
index 0000000..4237ac5
--- /dev/null
+++ b/src/main/java/moe/langua/lab/minecraft/scoop/UpdateChecker.java
@@ -0,0 +1,67 @@
+package moe.langua.lab.minecraft.scoop;
+
+import org.bukkit.ChatColor;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.player.PlayerJoinEvent;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import javax.net.ssl.HttpsURLConnection;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+
+public class UpdateChecker implements Listener {
+ BootStrap instance;
+ private boolean hasUpdate = false;
+ private String latestVersion = "";
+ private URL repoAPIURL = null;
+
+ public UpdateChecker(BootStrap instance) {
+ this.instance = instance;
+ try {
+ repoAPIURL = new URL("https://api.github.com/repos/NyaaCat/MelonScoop/releases/latest");
+ } catch (MalformedURLException ignore) {
+ }
+
+ instance.getServer().getScheduler().runTaskTimerAsynchronously(instance, () -> {
+ try {
+ JSONObject result = new JSONObject(jsonAPIGet(repoAPIURL));
+ latestVersion = result.getString("tag_name");
+ if (!instance.getDescription().getVersion().equalsIgnoreCase(latestVersion)) hasUpdate = true;
+ } catch (IOException ignore) {
+ }
+ }, 0, 20 * 3600 * 12/*Check update every 12 hour*/);
+ }
+
+ @EventHandler
+ public void onOperatorLogin(PlayerJoinEvent event) {
+ if (!event.getPlayer().hasPermission("melonscoop.update")) return;
+ if (!hasUpdate) return;
+ instance.getServer().getScheduler().runTaskLater(instance,()->event.getPlayer().sendMessage(ChatColor.YELLOW + "[MelonScoop] " + ChatColor.WHITE + "A new version of MelonScoop(" + latestVersion + ") is available. Click the link to download now: https://github.com/NyaaCat/MelonScoop/releases/" + latestVersion),20);
+ }
+
+ private static String jsonAPIGet(URL reqURL) throws JSONException, IOException {
+ HttpsURLConnection connection = (HttpsURLConnection) reqURL.openConnection();
+ connection.setRequestMethod("GET");
+ connection.setRequestProperty("Content-type", "application/json");
+ connection.setInstanceFollowRedirects(false);
+ InputStream inputStream = connection.getInputStream();
+ InputStreamReader inputStreamReader = new InputStreamReader(inputStream, UTF_8);
+ BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
+ String tmpString;
+ StringBuilder stringBuilder = new StringBuilder();
+ while (true) {
+ tmpString = bufferedReader.readLine();
+ if (tmpString == null) break;
+ stringBuilder.append(tmpString);
+ }
+ return stringBuilder.toString();
+ }
+}