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 LOGIN_PROFILE;
|
||||||
public static final Field PACKET_LISTENER;
|
public static final Field PACKET_LISTENER;
|
||||||
|
|
||||||
@Nullable
|
@Nullable public static final Field PAPER_DISABLE_USERNAME_VALIDATION;
|
||||||
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 GET_PROFILE_METHOD;
|
||||||
public static final Method LOGIN_DISCONNECT;
|
public static final Method LOGIN_DISCONNECT;
|
||||||
@@ -68,9 +68,7 @@ public class ClassNames {
|
|||||||
public static final Method INIT_UUID;
|
public static final Method INIT_UUID;
|
||||||
public static final Method FIRE_LOGIN_EVENTS;
|
public static final Method FIRE_LOGIN_EVENTS;
|
||||||
|
|
||||||
public static final Class<?> SPIGOT_CONFIG;
|
|
||||||
public static final Field BUNGEE;
|
public static final Field BUNGEE;
|
||||||
public static final Method GET_VERSION;
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||||
@@ -80,7 +78,7 @@ public class ClassNames {
|
|||||||
// SpigotSkinApplier
|
// SpigotSkinApplier
|
||||||
Class<?> craftPlayerClass = ReflectionUtils.getClass(
|
Class<?> craftPlayerClass = ReflectionUtils.getClass(
|
||||||
"org.bukkit.craftbukkit." + version + ".entity.CraftPlayer");
|
"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");
|
checkNotNull(GET_PROFILE_METHOD, "Get profile method");
|
||||||
|
|
||||||
String nmsPackage = SPIGOT_MAPPING_PREFIX + '.';
|
String nmsPackage = SPIGOT_MAPPING_PREFIX + '.';
|
||||||
@@ -176,15 +174,18 @@ public class ClassNames {
|
|||||||
(PAPER_DISABLE_USERNAME_VALIDATION != null));
|
(PAPER_DISABLE_USERNAME_VALIDATION != null));
|
||||||
}
|
}
|
||||||
|
|
||||||
// SpigotPlatformUtils
|
// ProxyUtils
|
||||||
SPIGOT_CONFIG = ReflectionUtils.getClass("org.spigotmc.SpigotConfig");
|
Class<?> spigotConfig = ReflectionUtils.getClass("org.spigotmc.SpigotConfig");
|
||||||
checkNotNull(SPIGOT_CONFIG, "Spigot config");
|
checkNotNull(spigotConfig, "Spigot config");
|
||||||
|
|
||||||
BUNGEE = ReflectionUtils.getField(SPIGOT_CONFIG, "bungee");
|
BUNGEE = getField(spigotConfig, "bungee");
|
||||||
checkNotNull(BUNGEE, "Bungee field");
|
checkNotNull(BUNGEE, "Bungee field");
|
||||||
|
|
||||||
GET_VERSION = ReflectionUtils.getMethod(MINECRAFT_SERVER, "getVersion");
|
Class<?> paperConfig = ReflectionUtils.getClassSilently(
|
||||||
checkNotNull(GET_VERSION, "Minecraft server version");
|
"com.destroystokyo.paper.PaperConfig");
|
||||||
|
|
||||||
|
PAPER_VELOCITY_SUPPORT =
|
||||||
|
paperConfig == null ? null : getField(paperConfig, "velocitySupport");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Class<?> getClassOrFallBack(String className, String fallbackName) {
|
private static Class<?> getClassOrFallBack(String className, String fallbackName) {
|
||||||
|
|||||||
@@ -25,45 +25,22 @@
|
|||||||
|
|
||||||
package org.geysermc.floodgate.util;
|
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")
|
@SuppressWarnings("ConstantConditions")
|
||||||
public final class ProxyUtils {
|
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() {
|
public static boolean isProxyData() {
|
||||||
return isBungeeData() || isVelocitySupport();
|
return isBungeeData() || isVelocitySupport();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isBungeeData() {
|
private static boolean isBungeeData() {
|
||||||
return ReflectionUtils.getCastedValue(null, IS_BUNGEE_DATA);
|
return ReflectionUtils.getCastedValue(null, ClassNames.BUNGEE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isVelocitySupport() {
|
private static boolean isVelocitySupport() {
|
||||||
if (IS_MODERN_FORWARDING == null) {
|
if (ClassNames.PAPER_VELOCITY_SUPPORT == null) {
|
||||||
return false;
|
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 {
|
public class SpigotPlatformUtils extends PlatformUtils {
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("ConstantConditions")
|
|
||||||
public AuthType authType() {
|
public AuthType authType() {
|
||||||
if (Bukkit.getOnlineMode()) {
|
if (Bukkit.getOnlineMode()) {
|
||||||
return AuthType.ONLINE;
|
return AuthType.ONLINE;
|
||||||
}
|
}
|
||||||
|
return ProxyUtils.isProxyData() ? AuthType.PROXIED : AuthType.OFFLINE;
|
||||||
boolean bungeeEnabled = ReflectionUtils.getCastedValue(null, ClassNames.BUNGEE);
|
|
||||||
return bungeeEnabled ? AuthType.PROXIED : AuthType.OFFLINE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String minecraftVersion() {
|
public String minecraftVersion() {
|
||||||
Object instance = ReflectionUtils.invokeStatic(ClassNames.MINECRAFT_SERVER, "getServer");
|
return Bukkit.getServer().getVersion().split("\\(MC: ")[1].split("\\)")[0];
|
||||||
return ReflectionUtils.castedInvoke(instance, ClassNames.GET_VERSION);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user