From a38b7ca9fa42391b3805a9d90ef6b90897c05248 Mon Sep 17 00:00:00 2001 From: NuclearW Date: Fri, 15 Feb 2013 11:11:47 -0500 Subject: [PATCH] Move metrics to a class of its own --- src/main/java/com/gmail/nossr50/mcMMO.java | 179 +--------------- .../nossr50/util/metrics/MetricsManager.java | 191 ++++++++++++++++++ 2 files changed, 194 insertions(+), 176 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/util/metrics/MetricsManager.java diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index c39e2bfdc..bc1c7e6ab 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -1,13 +1,10 @@ package com.gmail.nossr50; -import java.io.BufferedReader; import java.io.File; import java.io.IOException; -import java.io.InputStreamReader; import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import java.util.Locale; import net.shatteredlands.shatt.backup.ZipLibrary; @@ -18,11 +15,9 @@ import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitScheduler; -import com.turt2live.metrics.Metrics; -import com.turt2live.metrics.Metrics.Graph; - import com.gmail.nossr50.util.blockmeta.chunkmeta.ChunkManager; import com.gmail.nossr50.util.blockmeta.chunkmeta.ChunkManagerFactory; +import com.gmail.nossr50.util.metrics.MetricsManager; import com.gmail.nossr50.commands.CommandRegistrationHelper; import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.Config; @@ -37,7 +32,6 @@ import com.gmail.nossr50.listeners.EntityListener; import com.gmail.nossr50.listeners.InventoryListener; import com.gmail.nossr50.listeners.PlayerListener; import com.gmail.nossr50.listeners.WorldListener; -import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.mods.config.CustomArmorConfig; import com.gmail.nossr50.mods.config.CustomBlocksConfig; import com.gmail.nossr50.mods.config.CustomEntityConfig; @@ -121,7 +115,8 @@ public class mcMMO extends JavaPlugin { scheduleTasks(); registerCommands(); - setupMetrics(); + + MetricsManager.setup(); placeStore = ChunkManagerFactory.getChunkManager(); // Get our ChunkletManager @@ -342,174 +337,6 @@ public class mcMMO extends JavaPlugin { } } - private void setupMetrics() { - if (Config.getInstance().getStatsTrackingEnabled()) { - try { - Metrics metrics = new Metrics(this); - - // Timings Graph - Graph timingsGraph = metrics.createGraph("Percentage of servers using timings"); - - if (getServer().getPluginManager().useTimings()) { - timingsGraph.addPlotter(new Metrics.Plotter("Enabled") { - @Override - public int getValue() { - return 1; - } - }); - } - else { - timingsGraph.addPlotter(new Metrics.Plotter("Disabled") { - @Override - public int getValue() { - return 1; - } - }); - } - - // Donut Version Graph - Graph versionDonutGraph = metrics.createGraph("Donut Version"); - - boolean haveVersionInformation = false; - boolean isOfficialBuild = false; - String officialKey = "e14cfacdd442a953343ebd8529138680"; - - String version = getDescription().getVersion(); - - InputStreamReader isr = new InputStreamReader(getResource(".jenkins")); - BufferedReader br = new BufferedReader(isr); - char[] key = new char[32]; - br.read(key); - if (officialKey.equals(String.valueOf(key))) { - isOfficialBuild = true; - } - - if (version.contains("-")) { - String majorVersion = version.substring(0, version.indexOf("-")); - String subVersion = ""; - if (isOfficialBuild) { - int startIndex = version.indexOf("-"); - if (version.substring(startIndex + 1).contains("-")) { - subVersion = version.substring(startIndex, version.indexOf("-", startIndex + 1)); - } else { - subVersion = "-release"; - } - } else { - subVersion = "-custom"; - } - - version = majorVersion + "~=~" + subVersion; - haveVersionInformation = true; - } else { - haveVersionInformation = false; - } - - if (haveVersionInformation) { - versionDonutGraph.addPlotter(new Metrics.Plotter(version) { - @Override - public int getValue() { - return 1; - } - }); - } - - // Official v Custom build Graph - Graph officialGraph = metrics.createGraph("Built by official ci"); - - if (isOfficialBuild) { - officialGraph.addPlotter(new Metrics.Plotter("Yes") { - @Override - public int getValue() { - return 1; - } - }); - } - else { - officialGraph.addPlotter(new Metrics.Plotter("No") { - @Override - public int getValue() { - return 1; - } - }); - } - - // Chunkmeta enabled Graph - Graph chunkmetaGraph = metrics.createGraph("Uses Chunkmeta"); - - if (HiddenConfig.getInstance().getChunkletsEnabled()) { - chunkmetaGraph.addPlotter(new Metrics.Plotter("Yes") { - @Override - public int getValue() { - return 1; - } - }); - } - else { - chunkmetaGraph.addPlotter(new Metrics.Plotter("No") { - @Override - public int getValue() { - return 1; - } - }); - } - - // Storage method Graph - Graph storageGraph = metrics.createGraph("Storage method"); - - if (Config.getInstance().getUseMySQL()) { - storageGraph.addPlotter(new Metrics.Plotter("SQL") { - @Override - public int getValue() { - return 1; - } - }); - } - else { - storageGraph.addPlotter(new Metrics.Plotter("Flatfile") { - @Override - public int getValue() { - return 1; - } - }); - } - - // Locale Graph - Graph localeGraph = metrics.createGraph("Locale"); - - localeGraph.addPlotter(new Metrics.Plotter(LocaleLoader.getCurrentLocale().getDisplayLanguage(Locale.US)) { - @Override - public int getValue() { - return 1; - } - }); - - // GlobalMultiplier Graph - Graph globalMultiplierGraph = metrics.createGraph("Global Multiplier Graph"); - - globalMultiplierGraph.addPlotter(new Metrics.Plotter(Config.getInstance().getExperienceGainsGlobalMultiplier() + "") { - @Override - public int getValue() { - return 1; - } - }); - - // GlobalCurveModifier Graph - Graph globalCurveModifierGraph = metrics.createGraph("Global Curve Modifier Graph"); - - globalCurveModifierGraph.addPlotter(new Metrics.Plotter(Config.getInstance().getFormulaMultiplierCurve() + "") { - @Override - public int getValue() { - return 1; - } - }); - - metrics.start(); - } - catch (IOException e) { - mcMMO.p.getLogger().warning("Failed to submit stats."); - } - } - } /** * Add a set of values to the TNT tracker. * diff --git a/src/main/java/com/gmail/nossr50/util/metrics/MetricsManager.java b/src/main/java/com/gmail/nossr50/util/metrics/MetricsManager.java new file mode 100644 index 000000000..ed063b63c --- /dev/null +++ b/src/main/java/com/gmail/nossr50/util/metrics/MetricsManager.java @@ -0,0 +1,191 @@ +package com.gmail.nossr50.util.metrics; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Locale; + +import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.config.Config; +import com.gmail.nossr50.config.HiddenConfig; +import com.gmail.nossr50.locale.LocaleLoader; + +import com.turt2live.metrics.Metrics; +import com.turt2live.metrics.Metrics.Graph; + +public class MetricsManager { + private static boolean setup = false; + + public static void setup() { + if (setup) { + return; + } + + if (Config.getInstance().getStatsTrackingEnabled()) { + try { + Metrics metrics = new Metrics(mcMMO.p); + + // Timings Graph + Graph timingsGraph = metrics.createGraph("Percentage of servers using timings"); + + if (mcMMO.p.getServer().getPluginManager().useTimings()) { + timingsGraph.addPlotter(new Metrics.Plotter("Enabled") { + @Override + public int getValue() { + return 1; + } + }); + } + else { + timingsGraph.addPlotter(new Metrics.Plotter("Disabled") { + @Override + public int getValue() { + return 1; + } + }); + } + + // Donut Version Graph + Graph versionDonutGraph = metrics.createGraph("Donut Version"); + + boolean haveVersionInformation = false; + boolean isOfficialBuild = false; + String officialKey = "e14cfacdd442a953343ebd8529138680"; + + String version = mcMMO.p.getDescription().getVersion(); + + InputStreamReader isr = new InputStreamReader(mcMMO.p.getResource(".jenkins")); + BufferedReader br = new BufferedReader(isr); + char[] key = new char[32]; + br.read(key); + if (officialKey.equals(String.valueOf(key))) { + isOfficialBuild = true; + } + + if (version.contains("-")) { + String majorVersion = version.substring(0, version.indexOf("-")); + String subVersion = ""; + if (isOfficialBuild) { + int startIndex = version.indexOf("-"); + if (version.substring(startIndex + 1).contains("-")) { + subVersion = version.substring(startIndex, version.indexOf("-", startIndex + 1)); + } else { + subVersion = "-release"; + } + } else { + subVersion = "-custom"; + } + + version = majorVersion + "~=~" + subVersion; + haveVersionInformation = true; + } else { + haveVersionInformation = false; + } + + if (haveVersionInformation) { + versionDonutGraph.addPlotter(new Metrics.Plotter(version) { + @Override + public int getValue() { + return 1; + } + }); + } + + // Official v Custom build Graph + Graph officialGraph = metrics.createGraph("Built by official ci"); + + if (isOfficialBuild) { + officialGraph.addPlotter(new Metrics.Plotter("Yes") { + @Override + public int getValue() { + return 1; + } + }); + } + else { + officialGraph.addPlotter(new Metrics.Plotter("No") { + @Override + public int getValue() { + return 1; + } + }); + } + + // Chunkmeta enabled Graph + Graph chunkmetaGraph = metrics.createGraph("Uses Chunkmeta"); + + if (HiddenConfig.getInstance().getChunkletsEnabled()) { + chunkmetaGraph.addPlotter(new Metrics.Plotter("Yes") { + @Override + public int getValue() { + return 1; + } + }); + } + else { + chunkmetaGraph.addPlotter(new Metrics.Plotter("No") { + @Override + public int getValue() { + return 1; + } + }); + } + + // Storage method Graph + Graph storageGraph = metrics.createGraph("Storage method"); + + if (Config.getInstance().getUseMySQL()) { + storageGraph.addPlotter(new Metrics.Plotter("SQL") { + @Override + public int getValue() { + return 1; + } + }); + } + else { + storageGraph.addPlotter(new Metrics.Plotter("Flatfile") { + @Override + public int getValue() { + return 1; + } + }); + } + + // Locale Graph + Graph localeGraph = metrics.createGraph("Locale"); + + localeGraph.addPlotter(new Metrics.Plotter(LocaleLoader.getCurrentLocale().getDisplayLanguage(Locale.US)) { + @Override + public int getValue() { + return 1; + } + }); + + // GlobalMultiplier Graph + Graph globalMultiplierGraph = metrics.createGraph("Global Multiplier Graph"); + + globalMultiplierGraph.addPlotter(new Metrics.Plotter(Config.getInstance().getExperienceGainsGlobalMultiplier() + "") { + @Override + public int getValue() { + return 1; + } + }); + + // GlobalCurveModifier Graph + Graph globalCurveModifierGraph = metrics.createGraph("Global Curve Modifier Graph"); + + globalCurveModifierGraph.addPlotter(new Metrics.Plotter(Config.getInstance().getFormulaMultiplierCurve() + "") { + @Override + public int getValue() { + return 1; + } + }); + + metrics.start(); + } + catch (IOException e) { + mcMMO.p.getLogger().warning("Failed to submit stats."); + } + } + } +}