From bdfb1e1e24d13e5f41b5b0671c14bbfb49f21ef1 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Fri, 28 Jun 2019 20:06:56 +0800 Subject: [PATCH] Revert the changes for getServerData Former-commit-id: daf6c4096f89053a91ca8a4f87c486d58071c3d4 [formerly 43e31b1db9fa7181fe9495645ea42834bb78e8df] Former-commit-id: 32ac36b7a3081e140ffd4222146a3c77698b35e6 --- .../org/maxgamer/quickshop/QuickShop.java | 6 +-- .../org/maxgamer/quickshop/Util/Paste.java | 2 +- .../quickshop/Util/SentryErrorReporter.java | 2 +- .../org/maxgamer/quickshop/Util/Util.java | 49 ------------------- 4 files changed, 4 insertions(+), 55 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/QuickShop.java b/src/main/java/org/maxgamer/quickshop/QuickShop.java index ba264c9f4..d5b53406d 100644 --- a/src/main/java/org/maxgamer/quickshop/QuickShop.java +++ b/src/main/java/org/maxgamer/quickshop/QuickShop.java @@ -218,14 +218,12 @@ public class QuickShop extends JavaPlugin { getConfig().set("config-version", 1); updateConfig(getConfig().getInt("config-version")); - /* It will generate a new UUID above updateConfig */ //noinspection ConstantConditions - serverUniqueID = UUID.fromString(getConfig().getString("server-uuid")); - sentryErrorReporter = new SentryErrorReporter(this); - /* Process Metrics and Sentry error reporter. */ metrics = new Metrics(this); + serverUniqueID = UUID.fromString(getConfig().getString("server-uuid")); + sentryErrorReporter = new SentryErrorReporter(this); diff --git a/src/main/java/org/maxgamer/quickshop/Util/Paste.java b/src/main/java/org/maxgamer/quickshop/Util/Paste.java index e324eadd2..6ad30e515 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/Paste.java +++ b/src/main/java/org/maxgamer/quickshop/Util/Paste.java @@ -45,7 +45,7 @@ public class Paste { //finalReport.append("Fork: "+plugin.+"\n"); finalReport.append("================================================\n"); finalReport.append("System:\n"); - JSONObject serverData = Util.getServerData(); + JSONObject serverData = plugin.getMetrics().getServerData(); finalReport.append("\tOS: ").append(serverData.get("osName")).append("\n"); finalReport.append("\tArch: ").append(serverData.get("osArch")).append("\n"); finalReport.append("\tVersion: ").append(serverData.get("osVersion")).append("\n"); diff --git a/src/main/java/org/maxgamer/quickshop/Util/SentryErrorReporter.java b/src/main/java/org/maxgamer/quickshop/Util/SentryErrorReporter.java index 49ec66141..ccac6a85d 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/SentryErrorReporter.java +++ b/src/main/java/org/maxgamer/quickshop/Util/SentryErrorReporter.java @@ -40,7 +40,7 @@ public class SentryErrorReporter { sentryClient = SentryClientFactory.sentryClient(this.dsn); context = sentryClient.getContext(); Util.debugLog("Setting basic report data..."); - JSONObject serverData = Util.getServerData(); + JSONObject serverData = plugin.getMetrics().getPluginData(); //context.addTag("plugin_version", QuickShop.getVersion()); context.addTag("system_os", String.valueOf(serverData.get("osName"))); context.addTag("system_arch", String.valueOf(serverData.get("osArch"))); diff --git a/src/main/java/org/maxgamer/quickshop/Util/Util.java b/src/main/java/org/maxgamer/quickshop/Util/Util.java index 79b565f67..9c97dff4b 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/Util.java +++ b/src/main/java/org/maxgamer/quickshop/Util/Util.java @@ -3,7 +3,6 @@ package org.maxgamer.quickshop.Util; import java.io.*; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.text.DecimalFormat; import java.util.AbstractMap.SimpleEntry; import java.util.*; @@ -26,7 +25,6 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.potion.PotionEffect; import org.jetbrains.annotations.*; -import org.json.simple.JSONObject; import org.maxgamer.quickshop.Database.MySQLCore; import org.maxgamer.quickshop.QuickShop; import org.maxgamer.quickshop.Shop.DisplayItem; @@ -253,53 +251,6 @@ public class Util { return null; } - /** - * Gets the server specific data. - * - * @return The server specific data. - * author by bStats - */ - public static JSONObject getServerData() { - // Minecraft specific data - int playerAmount; - try { - // Around MC 1.8 the return type was changed to a collection from an array, - // This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection; - Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers"); - playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class) - ? ((Collection) onlinePlayersMethod.invoke(Bukkit.getServer())).size() - : ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length; - } catch (Exception e) { - playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed - } - int onlineMode = Bukkit.getOnlineMode() ? 1 : 0; - String bukkitVersion = org.bukkit.Bukkit.getVersion(); - bukkitVersion = bukkitVersion.substring(bukkitVersion.indexOf("MC: ") + 4, bukkitVersion.length() - 1); - - // OS/Java specific data - String javaVersion = System.getProperty("java.version"); - String osName = System.getProperty("os.name"); - String osArch = System.getProperty("os.arch"); - String osVersion = System.getProperty("os.version"); - int coreCount = Runtime.getRuntime().availableProcessors(); - - JSONObject data = new JSONObject(); - - data.put("serverUUID", plugin.getServerUniqueID()); - - data.put("playerAmount", playerAmount); - data.put("onlineMode", onlineMode); - data.put("bukkitVersion", bukkitVersion); - - data.put("javaVersion", javaVersion); - data.put("osName", osName); - data.put("osArch", osArch); - data.put("osVersion", osVersion); - data.put("coreCount", coreCount); - - return data; - } - /** * Returns the chest attached to the given chest. The given block must be a * chest.