mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-12-28 03:57:33 +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_GLOBAL = "global";
|
||||||
private static final String SECTION_AUTOUPDATER = "auto updater";
|
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_NOTIFY = "notify";
|
||||||
private static final String UPDATER_DOWNLAD = "download";
|
private static final String UPDATER_DOWNLAD = "download";
|
||||||
private static final String UPDATER_DELAY = "delay";
|
private static final String UPDATER_DELAY = "delay";
|
||||||
@ -119,6 +121,25 @@ class ProtocolConfig {
|
|||||||
return updater.getLong(UPDATER_LAST_TIME, 0);
|
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.
|
* Set the last time we updated, in seconds since 1970.01.01 00:00.
|
||||||
* @param lastTimeSeconds - new last update time.
|
* @param lastTimeSeconds - new last update time.
|
||||||
|
@ -189,7 +189,9 @@ public class ProtocolLibrary extends JavaPlugin {
|
|||||||
|
|
||||||
// Try to enable statistics
|
// Try to enable statistics
|
||||||
try {
|
try {
|
||||||
statistisc = new Statistics(this);
|
if (config.isMetricsEnabled()) {
|
||||||
|
statistisc = new Statistics(this);
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
reporter.reportDetailed(this, "Unable to enable metrics.", e, statistisc);
|
reporter.reportDetailed(this, "Unable to enable metrics.", e, statistisc);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
@ -310,7 +312,8 @@ public class ProtocolLibrary extends JavaPlugin {
|
|||||||
/**
|
/**
|
||||||
* Retrieve the metrics instance used to measure users of this library.
|
* Retrieve the metrics instance used to measure users of this library.
|
||||||
* <p>
|
* <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.
|
* @return Metrics instance container.
|
||||||
*/
|
*/
|
||||||
public Statistics getStatistics() {
|
public Statistics getStatistics() {
|
||||||
|
@ -36,10 +36,11 @@ public class Statistics {
|
|||||||
|
|
||||||
public Statistics(Plugin plugin) throws IOException {
|
public Statistics(Plugin plugin) throws IOException {
|
||||||
metrics = new Metrics(plugin);
|
metrics = new Metrics(plugin);
|
||||||
metrics.start();
|
|
||||||
|
|
||||||
// Determine who is using this library
|
// Determine who is using this library
|
||||||
addPluginUserGraph(metrics);
|
addPluginUserGraph(metrics);
|
||||||
|
|
||||||
|
metrics.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addPluginUserGraph(Metrics metrics) {
|
private void addPluginUserGraph(Metrics metrics) {
|
||||||
|
@ -333,7 +333,7 @@ public class Updater
|
|||||||
downloaded += count;
|
downloaded += count;
|
||||||
fout.write(data, 0, count);
|
fout.write(data, 0, count);
|
||||||
int percent = (int) (downloaded * 100 / fileLength);
|
int percent = (int) (downloaded * 100 / fileLength);
|
||||||
if(announce & (percent % 10 == 0))
|
if(announce && (percent % 10 == 0))
|
||||||
{
|
{
|
||||||
logger.info("Downloading update: " + percent + "% of " + fileLength + " bytes.");
|
logger.info("Downloading update: " + percent + "% of " + fileLength + " bytes.");
|
||||||
}
|
}
|
||||||
|
@ -8,3 +8,5 @@ global:
|
|||||||
delay: 43200 # 12 hours
|
delay: 43200 # 12 hours
|
||||||
# Last update time
|
# Last update time
|
||||||
last: 0
|
last: 0
|
||||||
|
|
||||||
|
metrics: true
|
Loading…
Reference in New Issue
Block a user