mirror of
https://github.com/GeyserMC/Floodgate.git
synced 2025-12-19 14:59:20 +00:00
Velocity is also a proxy
This commit is contained in:
@@ -59,8 +59,8 @@ public class ClassNames {
|
||||
public static final Field LOGIN_PROFILE;
|
||||
public static final Field PACKET_LISTENER;
|
||||
|
||||
@Nullable
|
||||
public static final Field PAPER_DISABLE_USERNAME_VALIDATION;
|
||||
@Nullable public static final Field PAPER_DISABLE_USERNAME_VALIDATION;
|
||||
@Nullable public static final Field PAPER_VELOCITY_SUPPORT;
|
||||
|
||||
public static final Method GET_PROFILE_METHOD;
|
||||
public static final Method LOGIN_DISCONNECT;
|
||||
@@ -68,9 +68,7 @@ public class ClassNames {
|
||||
public static final Method INIT_UUID;
|
||||
public static final Method FIRE_LOGIN_EVENTS;
|
||||
|
||||
public static final Class<?> SPIGOT_CONFIG;
|
||||
public static final Field BUNGEE;
|
||||
public static final Method GET_VERSION;
|
||||
|
||||
static {
|
||||
String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||
@@ -80,7 +78,7 @@ public class ClassNames {
|
||||
// SpigotSkinApplier
|
||||
Class<?> craftPlayerClass = ReflectionUtils.getClass(
|
||||
"org.bukkit.craftbukkit." + version + ".entity.CraftPlayer");
|
||||
GET_PROFILE_METHOD = ReflectionUtils.getMethod(craftPlayerClass, "getProfile");
|
||||
GET_PROFILE_METHOD = getMethod(craftPlayerClass, "getProfile");
|
||||
checkNotNull(GET_PROFILE_METHOD, "Get profile method");
|
||||
|
||||
String nmsPackage = SPIGOT_MAPPING_PREFIX + '.';
|
||||
@@ -176,15 +174,18 @@ public class ClassNames {
|
||||
(PAPER_DISABLE_USERNAME_VALIDATION != null));
|
||||
}
|
||||
|
||||
// SpigotPlatformUtils
|
||||
SPIGOT_CONFIG = ReflectionUtils.getClass("org.spigotmc.SpigotConfig");
|
||||
checkNotNull(SPIGOT_CONFIG, "Spigot config");
|
||||
// ProxyUtils
|
||||
Class<?> spigotConfig = ReflectionUtils.getClass("org.spigotmc.SpigotConfig");
|
||||
checkNotNull(spigotConfig, "Spigot config");
|
||||
|
||||
BUNGEE = ReflectionUtils.getField(SPIGOT_CONFIG, "bungee");
|
||||
BUNGEE = getField(spigotConfig, "bungee");
|
||||
checkNotNull(BUNGEE, "Bungee field");
|
||||
|
||||
GET_VERSION = ReflectionUtils.getMethod(MINECRAFT_SERVER, "getVersion");
|
||||
checkNotNull(GET_VERSION, "Minecraft server version");
|
||||
Class<?> paperConfig = ReflectionUtils.getClassSilently(
|
||||
"com.destroystokyo.paper.PaperConfig");
|
||||
|
||||
PAPER_VELOCITY_SUPPORT =
|
||||
paperConfig == null ? null : getField(paperConfig, "velocitySupport");
|
||||
}
|
||||
|
||||
private static Class<?> getClassOrFallBack(String className, String fallbackName) {
|
||||
|
||||
@@ -25,45 +25,22 @@
|
||||
|
||||
package org.geysermc.floodgate.util;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.geysermc.floodgate.util.ReflectionUtils.getField;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public final class ProxyUtils {
|
||||
private static final Field IS_BUNGEE_DATA;
|
||||
private static final Field IS_MODERN_FORWARDING;
|
||||
|
||||
static {
|
||||
Class<?> spigotConfig = ReflectionUtils.getClass("org.spigotmc.SpigotConfig");
|
||||
IS_BUNGEE_DATA = getField(spigotConfig, "bungee");
|
||||
checkNotNull(IS_BUNGEE_DATA, "bungee field cannot be null. Are you using CraftBukkit?");
|
||||
|
||||
Field velocitySupport;
|
||||
try {
|
||||
Class<?> paperConfig = Class.forName("com.destroystokyo.paper.PaperConfig");
|
||||
velocitySupport = getField(paperConfig, "velocitySupport");
|
||||
} catch (ClassNotFoundException e) {
|
||||
// We're not on a platform that has modern forwarding
|
||||
velocitySupport = null; // NOPMD - there's really not a better way around this unless you want to use an optional
|
||||
}
|
||||
IS_MODERN_FORWARDING = velocitySupport;
|
||||
}
|
||||
|
||||
public static boolean isProxyData() {
|
||||
return isBungeeData() || isVelocitySupport();
|
||||
}
|
||||
|
||||
private static boolean isBungeeData() {
|
||||
return ReflectionUtils.getCastedValue(null, IS_BUNGEE_DATA);
|
||||
return ReflectionUtils.getCastedValue(null, ClassNames.BUNGEE);
|
||||
}
|
||||
|
||||
private static boolean isVelocitySupport() {
|
||||
if (IS_MODERN_FORWARDING == null) {
|
||||
if (ClassNames.PAPER_VELOCITY_SUPPORT == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ReflectionUtils.getCastedValue(null, IS_MODERN_FORWARDING);
|
||||
return ReflectionUtils.getCastedValue(null, ClassNames.PAPER_VELOCITY_SUPPORT);
|
||||
}
|
||||
}
|
||||
@@ -30,19 +30,15 @@ import org.geysermc.floodgate.platform.util.PlatformUtils;
|
||||
|
||||
public class SpigotPlatformUtils extends PlatformUtils {
|
||||
@Override
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public AuthType authType() {
|
||||
if (Bukkit.getOnlineMode()) {
|
||||
return AuthType.ONLINE;
|
||||
}
|
||||
|
||||
boolean bungeeEnabled = ReflectionUtils.getCastedValue(null, ClassNames.BUNGEE);
|
||||
return bungeeEnabled ? AuthType.PROXIED : AuthType.OFFLINE;
|
||||
return ProxyUtils.isProxyData() ? AuthType.PROXIED : AuthType.OFFLINE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String minecraftVersion() {
|
||||
Object instance = ReflectionUtils.invokeStatic(ClassNames.MINECRAFT_SERVER, "getServer");
|
||||
return ReflectionUtils.castedInvoke(instance, ClassNames.GET_VERSION);
|
||||
return Bukkit.getServer().getVersion().split("\\(MC: ")[1].split("\\)")[0];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user