mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-12-26 11:08:12 +01:00
Add the ability to disable metrics in the config file.
This commit is contained in:
parent
2f2eb148fa
commit
64e3ba7f14
@ -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.
|
||||
* <p>
|
||||
* 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.
|
||||
|
@ -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.
|
||||
* <p>
|
||||
* 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() {
|
||||
|
@ -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) {
|
||||
|
@ -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.");
|
||||
}
|
||||
|
@ -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
|
||||
last: 0
|
||||
|
||||
metrics: true
|
Loading…
Reference in New Issue
Block a user