Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions bungeecord/example-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
repositories {
maven("https://repo.papermc.io/repository/maven-public/")
}

dependencies {
compileOnly("net.md-5:bungeecord-api:1.21-R0.5-SNAPSHOT")
implementation(project(":bungeecord"))
}

tasks.shadowJar {
// optionally relocate faststats
relocate("dev.faststats", "com.example.utils.faststats")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.example;

import dev.faststats.bungee.BungeeMetrics;
import dev.faststats.core.ErrorTracker;
import dev.faststats.core.Metrics;
import dev.faststats.core.chart.Chart;
import net.md_5.bungee.api.plugin.Plugin;

import java.net.URI;

public class ExamplePlugin extends Plugin {
// 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 = BungeeMetrics.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(this);

@Override
public void onDisable() {
metrics.shutdown();
}

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);
}
}
}
3 changes: 3 additions & 0 deletions bungeecord/example-plugin/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: ExamplePlugin
version: 1.0.0
main: com.example.ExamplePlugin
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ rootProject.name = "dev-kits"
include("bukkit")
include("bukkit:example-plugin")
include("bungeecord")
include("bungeecord:example-plugin")
include("core")
include("fabric")
include("fabric:example-mod")
Expand Down
Loading