From 8882e0214c388e09ff6e4125d4e1c6c92eec67f7 Mon Sep 17 00:00:00 2001 From: md678685 Date: Sat, 5 Jan 2019 17:48:44 +0000 Subject: [PATCH] Add bStats metrics for each EssentialsX module (#2333) Does what it says on the tin. --- .../src/com/earth2me/essentials/metrics/Metrics.java | 2 +- .../earth2me/essentials/antibuild/EssentialsAntiBuild.java | 6 ++++++ .../src/com/earth2me/essentials/chat/EssentialsChat.java | 6 ++++++ .../src/com/earth2me/essentials/geoip/EssentialsGeoIP.java | 7 +++++++ .../com/earth2me/essentials/protect/EssentialsProtect.java | 6 ++++++ .../src/com/earth2me/essentials/spawn/EssentialsSpawn.java | 6 ++++++ .../src/com/earth2me/essentials/xmpp/EssentialsXMPP.java | 7 +++++++ .../src/com/earth2me/essentials/xmpp/XMPPManager.java | 5 +++++ 8 files changed, 44 insertions(+), 1 deletion(-) diff --git a/Essentials/src/com/earth2me/essentials/metrics/Metrics.java b/Essentials/src/com/earth2me/essentials/metrics/Metrics.java index 2c55f608f..00f640e9f 100644 --- a/Essentials/src/com/earth2me/essentials/metrics/Metrics.java +++ b/Essentials/src/com/earth2me/essentials/metrics/Metrics.java @@ -189,7 +189,7 @@ public class Metrics { public JSONObject getPluginData() { JSONObject data = new JSONObject(); - String pluginName = "EssentialsX"; + String pluginName = plugin.getDescription().getName().replace("Essentials", "EssentialsX"); String pluginVersion = plugin.getDescription().getVersion(); data.put("pluginName", pluginName); // Append the name of the plugin diff --git a/EssentialsAntiBuild/src/com/earth2me/essentials/antibuild/EssentialsAntiBuild.java b/EssentialsAntiBuild/src/com/earth2me/essentials/antibuild/EssentialsAntiBuild.java index e19078f99..59aa5828b 100644 --- a/EssentialsAntiBuild/src/com/earth2me/essentials/antibuild/EssentialsAntiBuild.java +++ b/EssentialsAntiBuild/src/com/earth2me/essentials/antibuild/EssentialsAntiBuild.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.antibuild; +import com.earth2me.essentials.metrics.Metrics; import org.bukkit.Material; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; @@ -14,6 +15,7 @@ public class EssentialsAntiBuild extends JavaPlugin implements IAntiBuild { private final transient Map settingsBoolean = new EnumMap<>(AntiBuildConfig.class); private final transient Map> settingsList = new EnumMap<>(AntiBuildConfig.class); private transient EssentialsConnect ess = null; + private transient Metrics metrics = null; @Override public void onEnable() { @@ -26,6 +28,10 @@ public class EssentialsAntiBuild extends JavaPlugin implements IAntiBuild { final EssentialsAntiBuildListener blockListener = new EssentialsAntiBuildListener(this); pm.registerEvents(blockListener, this); + + if (metrics == null) { + metrics = new Metrics(this); + } } @Override diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java index 4374f56cd..f2963064f 100644 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java +++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.chat; +import com.earth2me.essentials.metrics.Metrics; import net.ess3.api.IEssentials; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.plugin.PluginManager; @@ -16,6 +17,7 @@ import static com.earth2me.essentials.I18n.tl; public class EssentialsChat extends JavaPlugin { private static final Logger LOGGER = Logger.getLogger("Minecraft"); + private transient Metrics metrics = null; @Override public void onEnable() { @@ -38,5 +40,9 @@ public class EssentialsChat extends JavaPlugin { pluginManager.registerEvents(playerListenerNormal, this); pluginManager.registerEvents(playerListenerHighest, this); + if (metrics == null) { + metrics = new Metrics(this); + } + } } diff --git a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIP.java b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIP.java index cfd0ff9c0..9460d3a04 100644 --- a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIP.java +++ b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIP.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.geoip; +import com.earth2me.essentials.metrics.Metrics; import net.ess3.api.IEssentials; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; @@ -10,6 +11,8 @@ import static com.earth2me.essentials.I18n.tl; public class EssentialsGeoIP extends JavaPlugin { + private transient Metrics metrics = null; + public EssentialsGeoIP() { } @@ -33,5 +36,9 @@ public class EssentialsGeoIP extends JavaPlugin { getLogger().log(Level.INFO, "This product includes GeoLite2 data created by MaxMind, available from http://www.maxmind.com/."); + + if (metrics == null) { + metrics = new Metrics(this); + } } } diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java index 0053e498e..56c1d3186 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.protect; +import com.earth2me.essentials.metrics.Metrics; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; @@ -20,6 +21,7 @@ public class EssentialsProtect extends JavaPlugin implements IProtect { private final Map settingsString = new EnumMap<>(ProtectConfig.class); private final Map> settingsList = new EnumMap<>(ProtectConfig.class); private EssentialsConnect ess = null; + private transient Metrics metrics = null; private final EmergencyListener emListener = new EmergencyListener(this); @@ -33,6 +35,10 @@ public class EssentialsProtect extends JavaPlugin implements IProtect { } initialize(pm, essPlugin); + + if (metrics == null) { + metrics = new Metrics(this); + } } private void initialize(final PluginManager pm, final Plugin essPlugin) { diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawn.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawn.java index 0d592550a..a0b3d4334 100644 --- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawn.java +++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawn.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.spawn; +import com.earth2me.essentials.metrics.Metrics; import net.ess3.api.IEssentials; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -25,6 +26,7 @@ public class EssentialsSpawn extends JavaPlugin implements IEssentialsSpawn { private static final Logger LOGGER = Bukkit.getLogger(); private transient IEssentials ess; private transient SpawnStorage spawns; + private transient Metrics metrics = null; @Override public void onEnable() { @@ -62,6 +64,10 @@ public class EssentialsSpawn extends JavaPlugin implements IEssentialsSpawn { } }, this); } + + if (metrics == null) { + metrics = new Metrics(this); + } } @Override diff --git a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPP.java b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPP.java index 59df3c632..9a02042ca 100644 --- a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPP.java +++ b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPP.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.xmpp; import com.earth2me.essentials.IEssentials; +import com.earth2me.essentials.metrics.Metrics; import net.ess3.api.IUser; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -22,6 +23,7 @@ public class EssentialsXMPP extends JavaPlugin implements IEssentialsXMPP { private transient UserManager users; private transient XMPPManager xmpp; private transient IEssentials ess; + private transient Metrics metrics = null; public static IEssentialsXMPP getInstance() { return instance; @@ -49,6 +51,11 @@ public class EssentialsXMPP extends JavaPlugin implements IEssentialsXMPP { ess.addReloadListener(users); ess.addReloadListener(xmpp); + + if (metrics == null) { + metrics = new Metrics(this); + metrics.addCustomChart(new Metrics.SimplePie("config-valid", () -> xmpp.isConfigValid() ? "yes" : "no")); + } } @Override diff --git a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/XMPPManager.java b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/XMPPManager.java index 95f987280..28a2d64f9 100644 --- a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/XMPPManager.java +++ b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/XMPPManager.java @@ -318,4 +318,9 @@ public class XMPPManager extends Handler implements MessageListener, ChatManager chats.remove(address); } } + + public boolean isConfigValid() { + final String server = config.getString("xmpp.server"); + return server != null && server.equals("example.com"); + } }