Closed Lorenzo0111 closed 2 years ago
How do you initiate the Sponge Metrics class?
The Sponge Metrics class has to be injected like so:
import com.google.inject.Inject;
import org.bstats.sponge.Metrics;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.game.state.GameStartedServerEvent;
import org.spongepowered.api.plugin.Plugin;
@Plugin(id = "exampleplugin", name = "ExamplePlugin", version = "1.0")
public class ExamplePlugin {
private final Metrics metrics;
// The metricsFactory parameter gets injected using @Inject :)
// Check out https://docs.spongepowered.org/master/en/plugin/injection.html if you don't know what @Inject does
@Inject
public ExamplePlugin(Metrics.Factory metricsFactory) {
// You can find the plugin ids of your plugins on the page https://bstats.org/what-is-my-plugin-id
int pluginId = 1234; // <-- Replace with the id of your plugin!
metrics = metricsFactory.make(pluginId);
}
// Optional: Add custom charts
@Listener
public void onServerStart(GameStartedServerEvent event) {
metrics.addCustomChart(new Metrics.SimplePie("chart_id", () -> "My value"));
}
}
You must not call the constructor manually.
This works now, thanks
Description The bstats-sponge 1.7 works very well with sponge but when updating it does not work.
Error When I try to load my plugin on sponge with the latest dependency it gives me this error:
Source Code