diff --git a/src/main/java/de/themoep/snap/Snap.java b/src/main/java/de/themoep/snap/Snap.java index 531523b..efb2ac9 100644 --- a/src/main/java/de/themoep/snap/Snap.java +++ b/src/main/java/de/themoep/snap/Snap.java @@ -54,6 +54,10 @@ public Snap(ProxyServer proxy, Logger logger, @DataDirectory Path dataFolder) { @Subscribe public void onProxyInitialization(ProxyInitializeEvent event) throws NoSuchMethodException, ClassNotFoundException, NoSuchFieldException, IllegalAccessException, InvocationTargetException, IOException { if (loadConfig()) { + if (!config.has("stats-id") || config.getString("stats-id").isEmpty()) { + config.set("stats-id", UUID.randomUUID().toString()); + config.save(); + } bungeeAdapter = new SnapBungeeAdapter(this); bungeeAdapter.registerEvents(); bungeeAdapter.loadPlugins(); @@ -77,6 +81,10 @@ private boolean loadConfig() { return false; } + public PluginConfig getConfig() { + return config; + } + public ProxyServer getProxy() { return proxy; } diff --git a/src/main/java/de/themoep/snap/forwarding/SnapProxyServer.java b/src/main/java/de/themoep/snap/forwarding/SnapProxyServer.java index 0bd74e7..cfdc6fe 100644 --- a/src/main/java/de/themoep/snap/forwarding/SnapProxyServer.java +++ b/src/main/java/de/themoep/snap/forwarding/SnapProxyServer.java @@ -62,6 +62,7 @@ public class SnapProxyServer extends ProxyServer { private final Snap snap; + private String statsId; private Field fIdentifierMap; private Set channels = new HashSet<>(); private final ListenerInfo listener; @@ -73,6 +74,11 @@ public SnapProxyServer(Snap snap) { this.snap = snap; com.velocitypowered.api.proxy.config.ProxyConfig config = snap.getProxy().getConfiguration(); + statsId = snap.getConfig().getString("stats-id"); + if (statsId == null) { + statsId = UUID.randomUUID().toString(); + } + listener = new ListenerInfo( snap.getProxy().getBoundAddress(), LegacyComponentSerializer.legacySection().serialize(config.getMotd()), @@ -356,7 +362,7 @@ public int getTimeout() { @Override public String getUuid() { - return UUID.randomUUID().toString(); + return statsId; } @Override diff --git a/src/main/resources/snap.conf b/src/main/resources/snap.conf index b4f0115..4207f19 100644 --- a/src/main/resources/snap.conf +++ b/src/main/resources/snap.conf @@ -1,3 +1,6 @@ # Whether to throw exceptions when accessing methods that aren't supported # Setting this to false makes them return sensible values but they might not be correct -throw-unsupported-exception = true \ No newline at end of file +throw-unsupported-exception = true + +# The stats/metrics ID of this proxy, ideally the same as in the velocity.toml +stats-id = "" \ No newline at end of file