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

Fixed compatibility with the latest Velocity dev builds

Co-authored-by: Camotoy <20743703+camotoy@users.noreply.github.com>
This commit is contained in:
Tim203
2021-11-10 00:23:58 +01:00
parent ad41dbedc4
commit f20a13bba4
3 changed files with 39 additions and 4 deletions

View File

@@ -59,6 +59,15 @@ public final class ReflectionUtils {
return getClass(prefix + "." + className); return getClass(prefix + "." + className);
} }
@Nullable
public static Class<?> getPrefixedClassSilently(String className) {
try {
return Class.forName(prefix + "." + className);
} catch (ClassNotFoundException ignored) {
return null;
}
}
/** /**
* Get the class from a class name. Calling this method is equal to calling {@link * Get the class from a class name. Calling this method is equal to calling {@link
* Class#forName(String)} where String is the class name.<br> This method will return null when * Class#forName(String)} where String is the class name.<br> This method will return null when
@@ -485,7 +494,9 @@ public final class ReflectionUtils {
* @return the accessibleObject * @return the accessibleObject
*/ */
public static <T extends AccessibleObject> T makeAccessible(T accessibleObject) { public static <T extends AccessibleObject> T makeAccessible(T accessibleObject) {
if (!accessibleObject.isAccessible()) {
accessibleObject.setAccessible(true); accessibleObject.setAccessible(true);
}
return accessibleObject; return accessibleObject;
} }
} }

View File

@@ -95,7 +95,7 @@ public final class VelocityProxyDataHandler extends CommonDataHandler {
logger.info("Floodgate player who is logged in as {} {} joined", logger.info("Floodgate player who is logged in as {} {} joined",
player.getCorrectUsername(), player.getCorrectUniqueId()); player.getCorrectUsername(), player.getCorrectUniqueId());
} }
return true; return super.shouldRemoveHandler(result);
} }
@Override @Override

View File

@@ -26,8 +26,10 @@
package org.geysermc.floodgate.listener; package org.geysermc.floodgate.listener;
import static org.geysermc.floodgate.util.ReflectionUtils.getCastedValue; import static org.geysermc.floodgate.util.ReflectionUtils.getCastedValue;
import static org.geysermc.floodgate.util.ReflectionUtils.getField;
import static org.geysermc.floodgate.util.ReflectionUtils.getFieldOfType; import static org.geysermc.floodgate.util.ReflectionUtils.getFieldOfType;
import static org.geysermc.floodgate.util.ReflectionUtils.getPrefixedClass; import static org.geysermc.floodgate.util.ReflectionUtils.getPrefixedClass;
import static org.geysermc.floodgate.util.ReflectionUtils.getPrefixedClassSilently;
import static org.geysermc.floodgate.util.ReflectionUtils.getValue; import static org.geysermc.floodgate.util.ReflectionUtils.getValue;
import com.google.common.cache.Cache; import com.google.common.cache.Cache;
@@ -46,6 +48,7 @@ import io.netty.channel.Channel;
import io.netty.util.AttributeKey; import io.netty.util.AttributeKey;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Objects;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.geysermc.floodgate.api.ProxyFloodgateApi; import org.geysermc.floodgate.api.ProxyFloodgateApi;
@@ -56,13 +59,27 @@ import org.geysermc.floodgate.util.VelocityCommandUtil;
public final class VelocityListener { public final class VelocityListener {
private static final Field INITIAL_MINECRAFT_CONNECTION; private static final Field INITIAL_MINECRAFT_CONNECTION;
private static final Field INITIAL_CONNECTION_DELEGATE;
private static final Field CHANNEL; private static final Field CHANNEL;
static { static {
Class<?> initialConnection = getPrefixedClass("connection.client.InitialInboundConnection"); Class<?> initialConnection = getPrefixedClass("connection.client.InitialInboundConnection");
Class<?> minecraftConnection = getPrefixedClass("connection.MinecraftConnection"); Class<?> minecraftConnection = getPrefixedClass("connection.MinecraftConnection");
INITIAL_MINECRAFT_CONNECTION = getFieldOfType(initialConnection, minecraftConnection); INITIAL_MINECRAFT_CONNECTION = getFieldOfType(initialConnection, minecraftConnection);
// Since Velocity 3.1.0
Class<?> loginInboundConnection =
getPrefixedClassSilently("connection.client.LoginInboundConnection");
if (loginInboundConnection != null) {
INITIAL_CONNECTION_DELEGATE = getField(loginInboundConnection, "delegate");
Objects.requireNonNull(
INITIAL_CONNECTION_DELEGATE,
"initial inbound connection delegate cannot be null"
);
} else {
INITIAL_CONNECTION_DELEGATE = null;
}
CHANNEL = getFieldOfType(minecraftConnection, Channel.class); CHANNEL = getFieldOfType(minecraftConnection, Channel.class);
} }
@@ -89,7 +106,14 @@ public final class VelocityListener {
FloodgatePlayer player = null; FloodgatePlayer player = null;
String kickMessage; String kickMessage;
try { try {
Object mcConnection = getValue(event.getConnection(), INITIAL_MINECRAFT_CONNECTION); InboundConnection connection = event.getConnection();
if (INITIAL_CONNECTION_DELEGATE != null) {
// Velocity 3.1.0 added LoginInboundConnection which is used in the login state,
// but that class doesn't have a Channel field. However, it does have
// InitialInboundConnection as a field
connection = getCastedValue(connection, INITIAL_CONNECTION_DELEGATE);
}
Object mcConnection = getValue(connection, INITIAL_MINECRAFT_CONNECTION);
Channel channel = getCastedValue(mcConnection, CHANNEL); Channel channel = getCastedValue(mcConnection, CHANNEL);
player = channel.attr(playerAttribute).get(); player = channel.attr(playerAttribute).get();