public class Metrics
extends java.lang.Object
The metrics class obtains data about a plugin and submits statistics about it to the metrics backend.
Public methods provided by this class:
Graph createGraph(String name);
void addCustomData(Metrics.Plotter plotter);
void start();
| Modifier and Type | Class and Description |
|---|---|
static class |
Metrics.Graph
Represents a custom graph on the website
|
static class |
Metrics.Plotter
Interface used to collect custom data for a plugin
|
| Modifier and Type | Field and Description |
|---|---|
private static java.lang.String |
BASE_URL
The base url of the metrics domain
|
private org.bukkit.configuration.file.YamlConfiguration |
configuration
The plugin configuration file
|
private java.io.File |
configurationFile
The plugin configuration file
|
private static java.lang.String |
CUSTOM_DATA_SEPARATOR
The separator to use for custom data.
|
private Metrics.Graph |
defaultGraph
The default graph, used for addCustomData when you don't want a specific graph
|
private java.util.Set<Metrics.Graph> |
graphs
All of the custom graphs to submit to metrics
|
private java.lang.String |
guid
Unique server id
|
private java.lang.Object |
optOutLock
Lock for synchronization
|
private static int |
PING_INTERVAL
Interval of time to ping (in minutes)
|
private org.bukkit.plugin.Plugin |
plugin
The plugin this metrics submits for
|
private static java.lang.String |
REPORT_URL
The url used to report a server's status
|
private static int |
REVISION
The current revision number
|
private int |
taskId
Id of the scheduled task
|
| Constructor and Description |
|---|
Metrics(org.bukkit.plugin.Plugin plugin) |
| Modifier and Type | Method and Description |
|---|---|
void |
addCustomData(Metrics.Plotter plotter)
Adds a custom data plotter to the default graph
|
void |
addGraph(Metrics.Graph graph)
Add a Graph object to Metrics that represents data for the plugin that should be sent to the backend
|
Metrics.Graph |
createGraph(java.lang.String name)
Construct and create a Graph that can be used to separate specific plotters to their own graphs
on the metrics website.
|
void |
disable()
Disables metrics for the server by setting "opt-out" to true in the config file and canceling the metrics task.
|
void |
enable()
Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task.
|
private static java.lang.String |
encode(java.lang.String text)
Encode text as UTF-8
|
private static void |
encodeDataPair(java.lang.StringBuilder buffer,
java.lang.String key,
java.lang.String value)
Encode a key/value data pair to be used in a HTTP post request.
|
java.io.File |
getConfigFile()
Gets the File object of the config file that should be used to store data such as the GUID and opt-out status
|
private boolean |
isMineshafterPresent()
Check if mineshafter is present.
|
boolean |
isOptOut()
Has the server owner denied plugin metrics?
|
private void |
postPlugin(boolean isPing)
Generic method that posts a plugin to the metrics website
|
boolean |
start()
Start measuring statistics.
|
private static final int REVISION
private static final java.lang.String BASE_URL
private static final java.lang.String REPORT_URL
private static final java.lang.String CUSTOM_DATA_SEPARATOR
private static final int PING_INTERVAL
private final org.bukkit.plugin.Plugin plugin
private final java.util.Set<Metrics.Graph> graphs
private final Metrics.Graph defaultGraph
private final org.bukkit.configuration.file.YamlConfiguration configuration
private final java.io.File configurationFile
private final java.lang.String guid
private final java.lang.Object optOutLock
private volatile int taskId
public Metrics(org.bukkit.plugin.Plugin plugin)
throws java.io.IOException
java.io.IOExceptionpublic Metrics.Graph createGraph(java.lang.String name)
name - The name of the graphpublic void addGraph(Metrics.Graph graph)
graph - The name of the graphpublic void addCustomData(Metrics.Plotter plotter)
plotter - The plotter to use to plot custom datapublic boolean start()
public boolean isOptOut()
public void enable()
throws java.io.IOException
java.io.IOExceptionpublic void disable()
throws java.io.IOException
java.io.IOExceptionpublic java.io.File getConfigFile()
private void postPlugin(boolean isPing)
throws java.io.IOException
java.io.IOExceptionprivate boolean isMineshafterPresent()
private static void encodeDataPair(java.lang.StringBuilder buffer,
java.lang.String key,
java.lang.String value)
throws java.io.UnsupportedEncodingException
Encode a key/value data pair to be used in a HTTP post request. This INCLUDES a & so the first key/value pair MUST be included manually, e.g:
StringBuffer data = new StringBuffer();
data.append(encode("guid")).append('=').append(encode(guid));
encodeDataPair(data, "version", description.getVersion());
buffer - the stringbuilder to append the data pair ontokey - the key valuevalue - the valuejava.io.UnsupportedEncodingExceptionprivate static java.lang.String encode(java.lang.String text)
throws java.io.UnsupportedEncodingException
text - the text to encodejava.io.UnsupportedEncodingException