diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolConfig.java b/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolConfig.java index 517cf6f1..cb1acd17 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolConfig.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolConfig.java @@ -14,6 +14,8 @@ class ProtocolConfig { private static final String SECTION_GLOBAL = "global"; private static final String SECTION_AUTOUPDATER = "auto updater"; + private static final String METRICS_ENABLED = "metrics"; + private static final String UPDATER_NOTIFY = "notify"; private static final String UPDATER_DOWNLAD = "download"; private static final String UPDATER_DELAY = "delay"; @@ -119,6 +121,25 @@ class ProtocolConfig { return updater.getLong(UPDATER_LAST_TIME, 0); } + /** + * Retrieve whether or not metrics is enabled. + * @return TRUE if metrics is enabled, FALSE otherwise. + */ + public boolean isMetricsEnabled() { + return global.getBoolean(METRICS_ENABLED, true); + } + + /** + * Set whether or not metrics is enabled. + *
+ * This setting will take effect next time ProtocolLib is started. + * + * @param enabled - whether or not metrics is enabled. + */ + public void setMetricsEnabled(boolean enabled) { + global.set(METRICS_ENABLED, enabled); + } + /** * Set the last time we updated, in seconds since 1970.01.01 00:00. * @param lastTimeSeconds - new last update time. diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java b/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java index eb713965..6547a959 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java @@ -189,7 +189,9 @@ public class ProtocolLibrary extends JavaPlugin { // Try to enable statistics try { - statistisc = new Statistics(this); + if (config.isMetricsEnabled()) { + statistisc = new Statistics(this); + } } catch (IOException e) { reporter.reportDetailed(this, "Unable to enable metrics.", e, statistisc); } catch (Throwable e) { @@ -310,7 +312,8 @@ public class ProtocolLibrary extends JavaPlugin { /** * Retrieve the metrics instance used to measure users of this library. *
- * Note that this method may return NULL when the server is reloading or shutting down. + * Note that this method may return NULL when the server is reloading or shutting down. It is also + * NULL if metrics has been disabled. * @return Metrics instance container. */ public Statistics getStatistics() { diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/metrics/Statistics.java b/ProtocolLib/src/main/java/com/comphenix/protocol/metrics/Statistics.java index 5bf12478..0cc29faa 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/metrics/Statistics.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/metrics/Statistics.java @@ -36,10 +36,11 @@ public class Statistics { public Statistics(Plugin plugin) throws IOException { metrics = new Metrics(plugin); - metrics.start(); // Determine who is using this library addPluginUserGraph(metrics); + + metrics.start(); } private void addPluginUserGraph(Metrics metrics) { diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/metrics/Updater.java b/ProtocolLib/src/main/java/com/comphenix/protocol/metrics/Updater.java index f3f18939..dee8708e 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/metrics/Updater.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/metrics/Updater.java @@ -333,7 +333,7 @@ public class Updater downloaded += count; fout.write(data, 0, count); int percent = (int) (downloaded * 100 / fileLength); - if(announce & (percent % 10 == 0)) + if(announce && (percent % 10 == 0)) { logger.info("Downloading update: " + percent + "% of " + fileLength + " bytes."); } diff --git a/ProtocolLib/src/main/resources/config.yml b/ProtocolLib/src/main/resources/config.yml index aa16c45f..8bc3ca2d 100644 --- a/ProtocolLib/src/main/resources/config.yml +++ b/ProtocolLib/src/main/resources/config.yml @@ -7,4 +7,6 @@ global: # Number of seconds to wait until a new update is downloaded delay: 43200 # 12 hours # Last update time - last: 0 \ No newline at end of file + last: 0 + + metrics: true \ No newline at end of file