public class MetricsLite extends Object
Check out https://bStats.org/ to learn more about bStats!
| Modifier and Type | Field and Description |
|---|---|
static int |
B_STATS_VERSION |
private boolean |
enabled |
private static boolean |
logFailedRequests |
private static boolean |
logResponseStatusText |
private static boolean |
logSentData |
private cn.nukkit.plugin.Plugin |
plugin |
private int |
pluginId |
private ScheduledExecutorService |
scheduler |
private static String |
serverUUID |
private ThreadFactory |
threadFactory |
private static String |
URL |
| Constructor and Description |
|---|
MetricsLite(cn.nukkit.plugin.Plugin plugin,
int pluginId)
Class constructor.
|
| Modifier and Type | Method and Description |
|---|---|
private static byte[] |
compress(String str)
Gzips the given String.
|
com.google.gson.JsonObject |
getPluginData()
Gets the plugin specific data.
|
private com.google.gson.JsonObject |
getServerData()
Gets the server specific data.
|
boolean |
isEnabled()
Checks if bStats is enabled.
|
private void |
loadConfig()
Loads the bStats configuration.
|
private static void |
sendData(cn.nukkit.plugin.Plugin plugin,
com.google.gson.JsonObject data)
Sends the data to the bStats server.
|
private void |
startSubmitting()
Starts the Scheduler which submits our data every 30 minutes.
|
private void |
submitData()
Collects the data and sends it afterwards.
|
private void |
writeFile(File file,
String... lines)
Writes a String to a file.
|
private final ThreadFactory threadFactory
private final ScheduledExecutorService scheduler
public static final int B_STATS_VERSION
private static final String URL
private boolean enabled
private static boolean logFailedRequests
private static boolean logSentData
private static boolean logResponseStatusText
private static String serverUUID
private final cn.nukkit.plugin.Plugin plugin
private final int pluginId
public MetricsLite(cn.nukkit.plugin.Plugin plugin,
int pluginId)
plugin - The plugin which stats should be submitted.pluginId - The id of the plugin.
It can be found at What is my plugin id?public boolean isEnabled()
private void startSubmitting()
public com.google.gson.JsonObject getPluginData()
private com.google.gson.JsonObject getServerData()
private void submitData()
private void loadConfig()
throws IOException
IOException - If something did not work :(private void writeFile(File file, String... lines) throws IOException
file - The file to write to. Cannot be null.lines - The lines to write.IOException - If something did not work :(private static void sendData(cn.nukkit.plugin.Plugin plugin,
com.google.gson.JsonObject data)
throws Exception
plugin - Any plugin. It's just used to get a logger instance.data - The data to send.Exception - If the request failed.private static byte[] compress(String str) throws IOException
str - The string to gzip.IOException - If the compression failed.Copyright © 2022. All rights reserved.