1
0
mirror of https://github.com/GeyserMC/Floodgate.git synced 2025-12-19 14:59:20 +00:00

Added platform fork to metrics. Improved MC version detector in Bungee

This commit is contained in:
Tim203
2022-04-02 16:27:04 +02:00
parent 8d52ffd28d
commit c10561d010
8 changed files with 57 additions and 6 deletions

View File

@@ -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);

View File

@@ -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<String> 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<String> versions = ProtocolConstants.SUPPORTED_VERSIONS;
return versions.get(versions.size() - 1);
return LATEST_SUPPORTED_VERSION;
}
@Override
public String serverImplementationName() {
return proxyServer.getName();
}
}

View File

@@ -40,6 +40,8 @@ public abstract class PlatformUtils {
*/
public abstract String minecraftVersion();
public abstract String serverImplementationName();
public enum AuthType {
ONLINE,
PROXIED,

View File

@@ -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", () -> {

View File

@@ -269,6 +269,11 @@ public final class ReflectionUtils {
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>
* This method doesn't throw an exception when failed, but it'll log the error to the console.

View File

@@ -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);
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}