Class MetricsLoader

java.lang.Object
me.croabeast.common.MetricsLoader

public final class MetricsLoader extends Object
A utility class for integrating bStats metrics into a Bukkit/Spigot/Paper plugin.

This class simplifies the process of adding custom charts to track plugin usage and statistics through bStats. It provides methods for adding various types of charts including simple pie charts, drilldown pie charts, and single-line charts.

Example usage:


 MetricsLoader metrics = MetricsLoader.initialize(this, ${bStatsID});
 metrics.addSimplePie("plugin_usage", () -> "active")
        .addSingleLine("command_count", 42)
        .addDrillDownPie("active_plugins", "Using Metrics", pluginList);
 

  • Method Details

    • addChart

      public MetricsLoader addChart(org.bstats.charts.CustomChart chart)
      Adds a custom chart to the metrics dashboard.
      Parameters:
      chart - the custom chart to add (must not be null)
      Returns:
      the current MetricsLoader instance for method chaining
    • addSimplePie

      public MetricsLoader addSimplePie(String id, Object value)
      Adds a simple pie chart to the metrics.

      The value is converted to a string via its toString() method.

      Parameters:
      id - the identifier for the pie chart
      value - the value to be tracked in the pie chart (must not be null)
      Returns:
      the current MetricsLoader instance for method chaining
    • addSingleLine

      public MetricsLoader addSingleLine(String id, int value)
      Adds a single-line chart to the metrics.
      Parameters:
      id - the identifier for the chart
      value - the integer value to be tracked on the chart
      Returns:
      the current MetricsLoader instance for method chaining
    • addDrillDownPie

      public MetricsLoader addDrillDownPie(String id, String title, Collection<?> list)
      Adds a drilldown pie chart to the metrics based on a collection of objects.

      Each object in the collection is converted to its string representation, and the chart displays the count of occurrences under the specified title.

      Parameters:
      id - the identifier for the drilldown pie chart
      title - the title of the drilldown category
      list - the collection of objects to track; if empty, no chart is added.
      Returns:
      the current MetricsLoader instance for method chaining
    • addDrillDownPie

      public MetricsLoader addDrillDownPie(String id, String title, Object value)
      Adds a drilldown pie chart to the metrics based on a single object.
      Parameters:
      id - the identifier for the drilldown pie chart
      title - the title of the drilldown category
      value - the value to track; must not be null
      Returns:
      the current MetricsLoader instance for method chaining
    • initialize

      public static MetricsLoader initialize(org.bukkit.plugin.java.JavaPlugin plugin, int id)
      Initializes the MetricsLoader for a given plugin.
      Parameters:
      plugin - the JavaPlugin instance integrating bStats metrics
      id - the bStats plugin ID (use a variable for version control)
      Returns:
      a new MetricsLoader instance