Package me.croabeast.common
Class MetricsLoader
java.lang.Object
me.croabeast.common.MetricsLoader
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 Summary
Modifier and TypeMethodDescriptionaddChart(org.bstats.charts.CustomChart chart) Adds a custom chart to the metrics dashboard.addDrillDownPie(String id, String title, Object value) Adds a drilldown pie chart to the metrics based on a single object.addDrillDownPie(String id, String title, Collection<?> list) Adds a drilldown pie chart to the metrics based on a collection of objects.addSimplePie(String id, Object value) Adds a simple pie chart to the metrics.addSingleLine(String id, int value) Adds a single-line chart to the metrics.static MetricsLoaderinitialize(org.bukkit.plugin.java.JavaPlugin plugin, int id) Initializes theMetricsLoaderfor a given plugin.
-
Method Details
-
addChart
Adds a custom chart to the metrics dashboard.- Parameters:
chart- the custom chart to add (must not benull)- Returns:
- the current
MetricsLoaderinstance for method chaining
-
addSimplePie
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 chartvalue- the value to be tracked in the pie chart (must not benull)- Returns:
- the current
MetricsLoaderinstance for method chaining
-
addSingleLine
Adds a single-line chart to the metrics.- Parameters:
id- the identifier for the chartvalue- the integer value to be tracked on the chart- Returns:
- the current
MetricsLoaderinstance for method chaining
-
addDrillDownPie
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 charttitle- the title of the drilldown categorylist- the collection of objects to track; if empty, no chart is added.- Returns:
- the current
MetricsLoaderinstance for method chaining
-
addDrillDownPie
Adds a drilldown pie chart to the metrics based on a single object.- Parameters:
id- the identifier for the drilldown pie charttitle- the title of the drilldown categoryvalue- the value to track; must not benull- Returns:
- the current
MetricsLoaderinstance for method chaining
-
initialize
Initializes theMetricsLoaderfor a given plugin.- Parameters:
plugin- theJavaPlugininstance integrating bStats metricsid- the bStats plugin ID (use a variable for version control)- Returns:
- a new
MetricsLoaderinstance
-