Skip to Content

Nukkit

Integrate FastStats with Nukkit plugins

Use dev.faststats.nukkit.FastStatsNukkit for Nukkit plugins. Requires Java 17+.

Artifact: dev.faststats.metrics:nukkit

If you absolutely cannot use Java 17, a Java 8 fallback is available as dev.faststats.metrics.j8:nukkit with the same version number. Prefer the standard artifact above for new projects.

import cn.nukkit.plugin.PluginBase;
import dev.faststats.ErrorTracker;
import dev.faststats.FastStatsContext;
import dev.faststats.Metrics;
import dev.faststats.nukkit.FastStatsNukkit;

public final class ExamplePlugin extends PluginBase {
    public static final ErrorTracker ERROR_TRACKER = ErrorTracker.contextAware();

    private FastStatsContext context;

    @Override
    public void onLoad() {
        context = FastStatsNukkit.builder(this)
                .token("YOUR_TOKEN")
                .errorTrackerService(ERROR_TRACKER)
                .metrics(Metrics.Factory::create)
                .build();
    }

    @Override
    public void onEnable() {
        context.ready();
    }

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

Call context.ready() once, in or after onEnable(). Calling it earlier, for example from onLoad(), logs an error and leaves the context not ready.

See Error Tracking for configuring error reporting.

Replace YOUR_TOKEN with your project token. To keep it out of your git repository, inject it at build time instead of hardcoding it.

View full example on GitHub