-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathExamplePlugin.java
More file actions
43 lines (36 loc) · 1.62 KB
/
Copy pathExamplePlugin.java
File metadata and controls
43 lines (36 loc) · 1.62 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
package com.example;
import com.google.inject.Inject;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
import com.velocitypowered.api.plugin.Plugin;
import dev.faststats.core.ErrorTracker;
import dev.faststats.core.Metrics;
import dev.faststats.core.Settings;
import dev.faststats.core.data.Metric;
import dev.faststats.velocity.VelocityMetrics;
import org.jspecify.annotations.Nullable;
@Plugin(id = "example", name = "Example Plugin", version = "1.0.0",
url = "https://example.com", authors = {"Your Name"})
public class ExamplePlugin {
private final VelocityMetrics.Factory metricsFactory;
private @Nullable Metrics metrics = null;
@Inject
public ExamplePlugin(final VelocityMetrics.Factory factory) {
this.metricsFactory = factory;
}
@Subscribe
public void onProxyInitialize(final ProxyInitializeEvent event) {
this.metrics = metricsFactory
// Custom metrics require a corresponding data source in your project settings
.addMetric(Metric.number("example_metric", () -> 42))
// Error tracking must be enabled in the project settings
.errorTracker(ErrorTracker.contextAware())
.settings(Settings.withToken("YOUR_TOKEN_HERE")) // token can be found in the settings of your project
.create(this);
}
@Subscribe
public void onProxyStop(final ProxyShutdownEvent event) {
if (metrics != null) metrics.shutdown(); // safely shut down metrics submission
}
}