mirror of
https://github.com/GeyserMC/Floodgate.git
synced 2025-12-21 07:49:18 +00:00
Added platform fork to metrics. Improved MC version detector in Bungee
This commit is contained in:
@@ -59,7 +59,7 @@ public final class BungeeInjector extends CommonPlatformInjector {
|
|||||||
// (Instead of just replacing the ChannelInitializer which is only called for
|
// (Instead of just replacing the ChannelInitializer which is only called for
|
||||||
// player <-> proxy)
|
// player <-> proxy)
|
||||||
BungeeCustomPrepender customPrepender = new BungeeCustomPrepender(
|
BungeeCustomPrepender customPrepender = new BungeeCustomPrepender(
|
||||||
this, ReflectionUtils.getCastedValue(null, framePrepender)
|
this, ReflectionUtils.castedStaticValue(framePrepender)
|
||||||
);
|
);
|
||||||
|
|
||||||
BungeeReflectionUtils.setFieldValue(null, framePrepender, customPrepender);
|
BungeeReflectionUtils.setFieldValue(null, framePrepender, customPrepender);
|
||||||
|
|||||||
@@ -25,14 +25,40 @@
|
|||||||
|
|
||||||
package org.geysermc.floodgate.util;
|
package org.geysermc.floodgate.util;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||||
import org.geysermc.floodgate.platform.util.PlatformUtils;
|
import org.geysermc.floodgate.platform.util.PlatformUtils;
|
||||||
|
|
||||||
|
@SuppressWarnings("ConstantConditions")
|
||||||
public final class BungeePlatformUtils extends PlatformUtils {
|
public final class BungeePlatformUtils extends PlatformUtils {
|
||||||
|
private static final String LATEST_SUPPORTED_VERSION;
|
||||||
private final ProxyServer proxyServer = ProxyServer.getInstance();
|
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<String> versions = ProtocolConstants.SUPPORTED_VERSIONS;
|
||||||
|
versionName = versions.get(versions.size() - 1);
|
||||||
|
}
|
||||||
|
LATEST_SUPPORTED_VERSION = versionName;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AuthType authType() {
|
public AuthType authType() {
|
||||||
return proxyServer.getConfig().isOnlineMode() ? AuthType.ONLINE : AuthType.OFFLINE;
|
return proxyServer.getConfig().isOnlineMode() ? AuthType.ONLINE : AuthType.OFFLINE;
|
||||||
@@ -40,7 +66,11 @@ public final class BungeePlatformUtils extends PlatformUtils {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String minecraftVersion() {
|
public String minecraftVersion() {
|
||||||
List<String> versions = ProtocolConstants.SUPPORTED_VERSIONS;
|
return LATEST_SUPPORTED_VERSION;
|
||||||
return versions.get(versions.size() - 1);
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String serverImplementationName() {
|
||||||
|
return proxyServer.getName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ public abstract class PlatformUtils {
|
|||||||
*/
|
*/
|
||||||
public abstract String minecraftVersion();
|
public abstract String minecraftVersion();
|
||||||
|
|
||||||
|
public abstract String serverImplementationName();
|
||||||
|
|
||||||
public enum AuthType {
|
public enum AuthType {
|
||||||
ONLINE,
|
ONLINE,
|
||||||
PROXIED,
|
PROXIED,
|
||||||
|
|||||||
@@ -96,7 +96,11 @@ public final class Metrics {
|
|||||||
new SimplePie("floodgate_version", () -> Constants.VERSION)
|
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(
|
metricsBase.addCustomChart(
|
||||||
new DrilldownPie("minecraft_version", () -> {
|
new DrilldownPie("minecraft_version", () -> {
|
||||||
|
|||||||
@@ -269,6 +269,11 @@ public final class ReflectionUtils {
|
|||||||
return (T) getValue(instance, getField(instance.getClass(), fieldName));
|
return (T) getValue(instance, getField(instance.getClass(), fieldName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static <T> 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.<br>
|
* Set the value of a field. This method make the field accessible and then sets the value.<br>
|
||||||
* This method doesn't throw an exception when failed, but it'll log the error to the console.
|
* This method doesn't throw an exception when failed, but it'll log the error to the console.
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public final class ProxyUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isBungeeData() {
|
private static boolean isBungeeData() {
|
||||||
return ReflectionUtils.getCastedValue(null, ClassNames.BUNGEE);
|
return ReflectionUtils.castedStaticValue(ClassNames.BUNGEE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isVelocitySupport() {
|
private static boolean isVelocitySupport() {
|
||||||
@@ -41,6 +41,6 @@ public final class ProxyUtils {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ReflectionUtils.getCastedValue(null, ClassNames.PAPER_VELOCITY_SUPPORT);
|
return ReflectionUtils.castedStaticValue(ClassNames.PAPER_VELOCITY_SUPPORT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -41,4 +41,9 @@ public class SpigotPlatformUtils extends PlatformUtils {
|
|||||||
public String minecraftVersion() {
|
public String minecraftVersion() {
|
||||||
return Bukkit.getServer().getVersion().split("\\(MC: ")[1].split("\\)")[0];
|
return Bukkit.getServer().getVersion().split("\\(MC: ")[1].split("\\)")[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String serverImplementationName() {
|
||||||
|
return Bukkit.getServer().getName();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,4 +43,9 @@ public final class VelocityPlatformUtils extends PlatformUtils {
|
|||||||
public String minecraftVersion() {
|
public String minecraftVersion() {
|
||||||
return ProtocolVersion.MAXIMUM_VERSION.getMostRecentSupportedVersion();
|
return ProtocolVersion.MAXIMUM_VERSION.getMostRecentSupportedVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String serverImplementationName() {
|
||||||
|
return server.getVersion().getName();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user