diff --git a/bungee/src/main/java/org/geysermc/floodgate/inject/bungee/BungeeInjector.java b/bungee/src/main/java/org/geysermc/floodgate/inject/bungee/BungeeInjector.java index 4178490b..7181edd2 100644 --- a/bungee/src/main/java/org/geysermc/floodgate/inject/bungee/BungeeInjector.java +++ b/bungee/src/main/java/org/geysermc/floodgate/inject/bungee/BungeeInjector.java @@ -59,7 +59,7 @@ public final class BungeeInjector extends CommonPlatformInjector { // (Instead of just replacing the ChannelInitializer which is only called for // player <-> proxy) BungeeCustomPrepender customPrepender = new BungeeCustomPrepender( - this, ReflectionUtils.getCastedValue(null, framePrepender) + this, ReflectionUtils.castedStaticValue(framePrepender) ); BungeeReflectionUtils.setFieldValue(null, framePrepender, customPrepender); diff --git a/bungee/src/main/java/org/geysermc/floodgate/util/BungeePlatformUtils.java b/bungee/src/main/java/org/geysermc/floodgate/util/BungeePlatformUtils.java index 44540da2..fae9a83c 100644 --- a/bungee/src/main/java/org/geysermc/floodgate/util/BungeePlatformUtils.java +++ b/bungee/src/main/java/org/geysermc/floodgate/util/BungeePlatformUtils.java @@ -25,14 +25,40 @@ package org.geysermc.floodgate.util; +import java.lang.reflect.Field; import java.util.List; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.protocol.ProtocolConstants; import org.geysermc.floodgate.platform.util.PlatformUtils; +@SuppressWarnings("ConstantConditions") public final class BungeePlatformUtils extends PlatformUtils { + private static final String LATEST_SUPPORTED_VERSION; private final ProxyServer proxyServer = ProxyServer.getInstance(); + static { + int protocolNumber = -1; + String versionName = ""; + + for (Field field : ProtocolConstants.class.getFields()) { + if (!field.getName().startsWith("MINECRAFT_")) { + continue; + } + + int fieldValue = ReflectionUtils.castedStaticValue(field); + if (fieldValue > protocolNumber) { + protocolNumber = fieldValue; + versionName = field.getName().substring(10).replace('_', '.'); + } + } + + if (protocolNumber == -1) { + List versions = ProtocolConstants.SUPPORTED_VERSIONS; + versionName = versions.get(versions.size() - 1); + } + LATEST_SUPPORTED_VERSION = versionName; + } + @Override public AuthType authType() { return proxyServer.getConfig().isOnlineMode() ? AuthType.ONLINE : AuthType.OFFLINE; @@ -40,7 +66,11 @@ public final class BungeePlatformUtils extends PlatformUtils { @Override public String minecraftVersion() { - List versions = ProtocolConstants.SUPPORTED_VERSIONS; - return versions.get(versions.size() - 1); + return LATEST_SUPPORTED_VERSION; + } + + @Override + public String serverImplementationName() { + return proxyServer.getName(); } } diff --git a/core/src/main/java/org/geysermc/floodgate/platform/util/PlatformUtils.java b/core/src/main/java/org/geysermc/floodgate/platform/util/PlatformUtils.java index 81f5096c..d9901848 100644 --- a/core/src/main/java/org/geysermc/floodgate/platform/util/PlatformUtils.java +++ b/core/src/main/java/org/geysermc/floodgate/platform/util/PlatformUtils.java @@ -40,6 +40,8 @@ public abstract class PlatformUtils { */ public abstract String minecraftVersion(); + public abstract String serverImplementationName(); + public enum AuthType { ONLINE, PROXIED, diff --git a/core/src/main/java/org/geysermc/floodgate/util/Metrics.java b/core/src/main/java/org/geysermc/floodgate/util/Metrics.java index 50ea1025..be7ff315 100644 --- a/core/src/main/java/org/geysermc/floodgate/util/Metrics.java +++ b/core/src/main/java/org/geysermc/floodgate/util/Metrics.java @@ -96,7 +96,11 @@ public final class Metrics { new SimplePie("floodgate_version", () -> Constants.VERSION) ); - metricsBase.addCustomChart(new SimplePie("platform", () -> implementationName)); + metricsBase.addCustomChart( + new DrilldownPie("platform", () -> Collections.singletonMap( + implementationName, + Collections.singletonMap(platformUtils.serverImplementationName(), 1) + ))); metricsBase.addCustomChart( new DrilldownPie("minecraft_version", () -> { diff --git a/core/src/main/java/org/geysermc/floodgate/util/ReflectionUtils.java b/core/src/main/java/org/geysermc/floodgate/util/ReflectionUtils.java index 28c5abaf..63605c66 100644 --- a/core/src/main/java/org/geysermc/floodgate/util/ReflectionUtils.java +++ b/core/src/main/java/org/geysermc/floodgate/util/ReflectionUtils.java @@ -269,6 +269,11 @@ public final class ReflectionUtils { return (T) getValue(instance, getField(instance.getClass(), fieldName)); } + @Nullable + public static T castedStaticValue(Field field) { + return getCastedValue(null, field); + } + /** * Set the value of a field. This method make the field accessible and then sets the value.
* This method doesn't throw an exception when failed, but it'll log the error to the console. diff --git a/spigot/src/main/java/org/geysermc/floodgate/util/ProxyUtils.java b/spigot/src/main/java/org/geysermc/floodgate/util/ProxyUtils.java index 3080b137..9d982850 100644 --- a/spigot/src/main/java/org/geysermc/floodgate/util/ProxyUtils.java +++ b/spigot/src/main/java/org/geysermc/floodgate/util/ProxyUtils.java @@ -33,7 +33,7 @@ public final class ProxyUtils { } private static boolean isBungeeData() { - return ReflectionUtils.getCastedValue(null, ClassNames.BUNGEE); + return ReflectionUtils.castedStaticValue(ClassNames.BUNGEE); } private static boolean isVelocitySupport() { @@ -41,6 +41,6 @@ public final class ProxyUtils { return false; } - return ReflectionUtils.getCastedValue(null, ClassNames.PAPER_VELOCITY_SUPPORT); + return ReflectionUtils.castedStaticValue(ClassNames.PAPER_VELOCITY_SUPPORT); } } \ No newline at end of file diff --git a/spigot/src/main/java/org/geysermc/floodgate/util/SpigotPlatformUtils.java b/spigot/src/main/java/org/geysermc/floodgate/util/SpigotPlatformUtils.java index d431bc5b..538c8ce6 100644 --- a/spigot/src/main/java/org/geysermc/floodgate/util/SpigotPlatformUtils.java +++ b/spigot/src/main/java/org/geysermc/floodgate/util/SpigotPlatformUtils.java @@ -41,4 +41,9 @@ public class SpigotPlatformUtils extends PlatformUtils { public String minecraftVersion() { return Bukkit.getServer().getVersion().split("\\(MC: ")[1].split("\\)")[0]; } + + @Override + public String serverImplementationName() { + return Bukkit.getServer().getName(); + } } diff --git a/velocity/src/main/java/org/geysermc/floodgate/util/VelocityPlatformUtils.java b/velocity/src/main/java/org/geysermc/floodgate/util/VelocityPlatformUtils.java index 4abafe61..0340cfac 100644 --- a/velocity/src/main/java/org/geysermc/floodgate/util/VelocityPlatformUtils.java +++ b/velocity/src/main/java/org/geysermc/floodgate/util/VelocityPlatformUtils.java @@ -43,4 +43,9 @@ public final class VelocityPlatformUtils extends PlatformUtils { public String minecraftVersion() { return ProtocolVersion.MAXIMUM_VERSION.getMostRecentSupportedVersion(); } + + @Override + public String serverImplementationName() { + return server.getVersion().getName(); + } }