Skip to content

Commit ded108d

Browse files
committed
Add game count tracking to metrics example
1 parent 9b5e114 commit ded108d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

bukkit/example-plugin/src/main/java/com/example/ExamplePlugin.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.bukkit.plugin.java.JavaPlugin;
77

88
import java.net.URI;
9+
import java.util.concurrent.atomic.AtomicInteger;
910

1011
public class ExamplePlugin extends JavaPlugin {
1112
// context-aware error tracker, automatically tracks errors in the same class loader
@@ -14,12 +15,15 @@ public class ExamplePlugin extends JavaPlugin {
1415
// context-unaware error tracker, does not automatically track errors
1516
public static final ErrorTracker CONTEXT_UNAWARE_ERROR_TRACKER = ErrorTracker.contextUnaware();
1617

18+
private final AtomicInteger gameCount = new AtomicInteger();
19+
1720
private final BukkitMetrics metrics = BukkitMetrics.factory()
1821
.url(URI.create("https://metrics.example.com/v1/collect")) // For self-hosted metrics servers only
1922

2023
// Custom example charts
2124
// For this to work you have to create a corresponding data source in your project settings first
2225
.addChart(Chart.number("example_chart", () -> 42))
26+
.addChart(Chart.number("game_count", gameCount::get))
2327
.addChart(Chart.string("example_string", () -> "Hello, World!"))
2428
.addChart(Chart.bool("example_boolean", () -> true))
2529
.addChart(Chart.stringArray("example_string_array", () -> new String[]{"Option 1", "Option 2"}))
@@ -30,6 +34,8 @@ public class ExamplePlugin extends JavaPlugin {
3034
// This must be enabled in the project settings
3135
.errorTracker(ERROR_TRACKER)
3236

37+
.onFlush(() -> gameCount.set(0)) // Reset game count on flush
38+
3339
.debug(true) // Enable debug mode for development and testing
3440

3541
.token("YOUR_TOKEN_HERE") // required -> token can be found in the settings of your project
@@ -53,4 +59,8 @@ public void doSomethingWrong() {
5359
CONTEXT_UNAWARE_ERROR_TRACKER.trackError(e);
5460
}
5561
}
62+
63+
public void startGame() {
64+
gameCount.incrementAndGet();
65+
}
5666
}

0 commit comments

Comments
 (0)