Skip to content

Commit c063d91

Browse files
authored
Merge pull request #74 from faststats-dev/docs/bungee
Add BungeeCord example plugin
2 parents 2472bae + 71272f3 commit c063d91

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
repositories {
2+
maven("https://repo.papermc.io/repository/maven-public/")
3+
}
4+
5+
dependencies {
6+
compileOnly("net.md-5:bungeecord-api:1.21-R0.5-SNAPSHOT")
7+
implementation(project(":bungeecord"))
8+
}
9+
10+
tasks.shadowJar {
11+
// optionally relocate faststats
12+
relocate("dev.faststats", "com.example.utils.faststats")
13+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.example;
2+
3+
import dev.faststats.bungee.BungeeMetrics;
4+
import dev.faststats.core.ErrorTracker;
5+
import dev.faststats.core.Metrics;
6+
import dev.faststats.core.chart.Chart;
7+
import net.md_5.bungee.api.plugin.Plugin;
8+
9+
import java.net.URI;
10+
11+
public class ExamplePlugin extends Plugin {
12+
// context-aware error tracker, automatically tracks errors in the same class loader
13+
public static final ErrorTracker ERROR_TRACKER = ErrorTracker.contextAware();
14+
15+
// context-unaware error tracker, does not automatically track errors
16+
public static final ErrorTracker CONTEXT_UNAWARE_ERROR_TRACKER = ErrorTracker.contextUnaware();
17+
18+
private final Metrics metrics = BungeeMetrics.factory()
19+
.url(URI.create("https://metrics.example.com/v1/collect")) // For self-hosted metrics servers only
20+
21+
// Custom example charts
22+
// For this to work you have to create a corresponding data source in your project settings first
23+
.addChart(Chart.number("example_chart", () -> 42))
24+
.addChart(Chart.string("example_string", () -> "Hello, World!"))
25+
.addChart(Chart.bool("example_boolean", () -> true))
26+
.addChart(Chart.stringArray("example_string_array", () -> new String[]{"Option 1", "Option 2"}))
27+
.addChart(Chart.numberArray("example_number_array", () -> new Number[]{1, 2, 3}))
28+
.addChart(Chart.booleanArray("example_boolean_array", () -> new Boolean[]{true, false}))
29+
30+
// Attach an error tracker
31+
// This must be enabled in the project settings
32+
.errorTracker(ERROR_TRACKER)
33+
34+
.debug(true) // Enable debug mode for development and testing
35+
36+
.token("YOUR_TOKEN_HERE") // required -> token can be found in the settings of your project
37+
.create(this);
38+
39+
@Override
40+
public void onDisable() {
41+
metrics.shutdown();
42+
}
43+
44+
public void doSomethingWrong() {
45+
try {
46+
// Do something that might throw an error
47+
throw new RuntimeException("Something went wrong!");
48+
} catch (Exception e) {
49+
CONTEXT_UNAWARE_ERROR_TRACKER.trackError(e);
50+
}
51+
}
52+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name: ExamplePlugin
2+
version: 1.0.0
3+
main: com.example.ExamplePlugin

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ rootProject.name = "dev-kits"
1111
include("bukkit")
1212
include("bukkit:example-plugin")
1313
include("bungeecord")
14+
include("bungeecord:example-plugin")
1415
include("core")
1516
include("fabric")
1617
include("fabric:example-mod")

0 commit comments

Comments
 (0)