Class MetricsLite

java.lang.Object
cn.lanink.gamecore.utils.MetricsLite

public class MetricsLite extends Object
bStats collects some data for plugin authors.

Check out https://bStats.org/ to learn more about bStats!

  • Field Details

    • threadFactory

      private final ThreadFactory threadFactory
    • scheduler

      private final ScheduledExecutorService scheduler
    • B_STATS_VERSION

      public static final int B_STATS_VERSION
      See Also:
    • URL

      private static final String URL
      See Also:
    • enabled

      private boolean enabled
    • logFailedRequests

      private static boolean logFailedRequests
    • logSentData

      private static boolean logSentData
    • logResponseStatusText

      private static boolean logResponseStatusText
    • serverUUID

      private static String 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

      private void loadConfig() throws IOException
      Loads the bStats configuration.
      Throws:
      IOException - If something did not work :(
    • writeFile

      private void writeFile(File file, String... lines) throws IOException
      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

      private static byte[] compress(String str) throws IOException
      Gzips the given String.
      Parameters:
      str - The string to gzip.
      Returns:
      The gzipped String.
      Throws:
      IOException - If the compression failed.