Skip to content

Commit 9579b7c

Browse files
committed
Add error tracker to hytale example plugin
1 parent a8c4bba commit 9579b7c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22

33
import com.hypixel.hytale.server.core.plugin.JavaPlugin;
44
import com.hypixel.hytale.server.core.plugin.JavaPluginInit;
5+
import dev.faststats.core.ErrorTracker;
56
import dev.faststats.core.Metrics;
67
import dev.faststats.core.chart.Chart;
78
import dev.faststats.hytale.HytaleMetrics;
89

910
import java.net.URI;
1011

1112
public class ExamplePlugin extends JavaPlugin {
13+
// context-aware error tracker, automatically tracks errors in the same class loader
14+
public static final ErrorTracker ERROR_TRACKER = ErrorTracker.contextAware();
15+
16+
// context-unaware error tracker, does not automatically track errors
17+
public static final ErrorTracker CONTEXT_UNAWARE_ERROR_TRACKER = ErrorTracker.contextUnaware();
18+
1219
private final Metrics metrics = HytaleMetrics.factory()
1320
.url(URI.create("https://metrics.example.com/v1/collect")) // For self-hosted metrics servers only
1421

@@ -21,6 +28,10 @@ public class ExamplePlugin extends JavaPlugin {
2128
.addChart(Chart.numberArray("example_number_array", () -> new Number[]{1, 2, 3}))
2229
.addChart(Chart.booleanArray("example_boolean_array", () -> new Boolean[]{true, false}))
2330

31+
// Attach an error tracker
32+
// This must be enabled in the project settings
33+
.errorTracker(ERROR_TRACKER)
34+
2435
.debug(true) // Enable debug mode for development and testing
2536

2637
.token("YOUR_TOKEN_HERE") // required -> token can be found in the settings of your project
@@ -34,4 +45,13 @@ public ExamplePlugin(JavaPluginInit init) {
3445
protected void shutdown() {
3546
metrics.shutdown();
3647
}
48+
49+
public void doSomethingWrong() {
50+
try {
51+
// Do something that might throw an error
52+
throw new RuntimeException("Something went wrong!");
53+
} catch (Exception e) {
54+
CONTEXT_UNAWARE_ERROR_TRACKER.trackError(e);
55+
}
56+
}
3757
}

0 commit comments

Comments
 (0)