Package cn.lanink.gamecore.utils
Class MetricsLite
java.lang.Object
cn.lanink.gamecore.utils.MetricsLite
bStats collects some data for plugin authors.
Check out https://bStats.org/ to learn more about bStats!
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intprivate booleanprivate static booleanprivate static booleanprivate static booleanprivate final cn.nukkit.plugin.Pluginprivate final intprivate final ScheduledExecutorServiceprivate static Stringprivate final ThreadFactoryprivate static final String -
Constructor Summary
ConstructorsConstructorDescriptionMetricsLite(cn.nukkit.plugin.Plugin plugin, int pluginId) Class constructor. -
Method Summary
Modifier and TypeMethodDescriptionprivate static byte[]Gzips the given String.com.google.gson.JsonObjectGets the plugin specific data.private com.google.gson.JsonObjectGets the server specific data.booleanChecks if bStats is enabled.private voidLoads the bStats configuration.private static voidsendData(cn.nukkit.plugin.Plugin plugin, com.google.gson.JsonObject data) Sends the data to the bStats server.private voidStarts the Scheduler which submits our data every 30 minutes.private voidCollects the data and sends it afterwards.private voidWrites a String to a file.
-
Field Details
-
threadFactory
-
scheduler
-
B_STATS_VERSION
public static final int B_STATS_VERSION- See Also:
-
URL
- See Also:
-
enabled
private boolean enabled -
logFailedRequests
private static boolean logFailedRequests -
logSentData
private static boolean logSentData -
logResponseStatusText
private static boolean logResponseStatusText -
serverUUID
-
plugin
private final cn.nukkit.plugin.Plugin plugin -
pluginId
private final int pluginId
-
-
Constructor Details
-
MetricsLite
public MetricsLite(cn.nukkit.plugin.Plugin plugin, int pluginId) Class constructor.- Parameters:
plugin- The plugin which stats should be submitted.pluginId- The id of the plugin. It can be found at What is my plugin id?
-
-
Method Details
-
isEnabled
public boolean isEnabled()Checks if bStats is enabled.- Returns:
- Whether bStats is enabled or not.
-
startSubmitting
private void startSubmitting()Starts the Scheduler which submits our data every 30 minutes. -
getPluginData
public com.google.gson.JsonObject getPluginData()Gets the plugin specific data. This method is called using Reflection.- Returns:
- The plugin specific data.
-
getServerData
private com.google.gson.JsonObject getServerData()Gets the server specific data.- Returns:
- The server specific data.
-
submitData
private void submitData()Collects the data and sends it afterwards. -
loadConfig
Loads the bStats configuration.- Throws:
IOException- If something did not work :(
-
writeFile
Writes a String to a file. It also adds a note for the user.- Parameters:
file- The file to write to. Cannot be null.lines- The lines to write.- Throws:
IOException- If something did not work :(
-
sendData
private static void sendData(cn.nukkit.plugin.Plugin plugin, com.google.gson.JsonObject data) throws Exception Sends the data to the bStats server.- Parameters:
plugin- Any plugin. It's just used to get a logger instance.data- The data to send.- Throws:
Exception- If the request failed.
-
compress
Gzips the given String.- Parameters:
str- The string to gzip.- Returns:
- The gzipped String.
- Throws:
IOException- If the compression failed.
-