-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExampleMod.java
More file actions
51 lines (40 loc) · 2.15 KB
/
ExampleMod.java
File metadata and controls
51 lines (40 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.example;
import dev.faststats.core.ErrorTracker;
import dev.faststats.core.Metrics;
import dev.faststats.core.chart.Chart;
import dev.faststats.fabric.FabricMetrics;
import net.fabricmc.api.ModInitializer;
import java.net.URI;
public class ExampleMod implements ModInitializer {
// context-aware error tracker, automatically tracks errors in the same class loader
public static final ErrorTracker ERROR_TRACKER = ErrorTracker.contextAware();
// context-unaware error tracker, does not automatically track errors
public static final ErrorTracker CONTEXT_UNAWARE_ERROR_TRACKER = ErrorTracker.contextUnaware();
private final Metrics metrics = FabricMetrics.factory()
.url(URI.create("https://metrics.example.com/v1/collect")) // For self-hosted metrics servers only
// Custom example charts
// For this to work you have to create a corresponding data source in your project settings first
.addChart(Chart.number("example_chart", () -> 42))
.addChart(Chart.string("example_string", () -> "Hello, World!"))
.addChart(Chart.bool("example_boolean", () -> true))
.addChart(Chart.stringArray("example_string_array", () -> new String[]{"Option 1", "Option 2"}))
.addChart(Chart.numberArray("example_number_array", () -> new Number[]{1, 2, 3}))
.addChart(Chart.booleanArray("example_boolean_array", () -> new Boolean[]{true, false}))
// Attach an error tracker
// This must be enabled in the project settings
.errorTracker(ERROR_TRACKER)
.debug(true) // Enable debug mode for development and testing
.token("YOUR_TOKEN_HERE") // required -> token can be found in the settings of your project
.create("example-mod"); // your mod id as defined in fabric.mod.json
public void doSomethingWrong() {
try {
// Do something that might throw an error
throw new RuntimeException("Something went wrong!");
} catch (Exception e) {
CONTEXT_UNAWARE_ERROR_TRACKER.trackError(e);
}
}
@Override
public void onInitialize() {
}
}