From 5ab7173c9ddd0334335a39195d7f4604f9e1f770 Mon Sep 17 00:00:00 2001 From: QuickGlare Date: Wed, 22 Sep 2021 16:22:29 +0200 Subject: [PATCH] Fixed error with GeyserMC support, Fixed build.gradle not compiling on Windows --- build.gradle | 6 +++--- .../tcpshield/velocity/handler/VelocityPlayer.java | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index 1a161cc..4b902da 100644 --- a/build.gradle +++ b/build.gradle @@ -146,8 +146,8 @@ void updateYamls() { def yaml = new Yaml(options) - def bukkitYamlFile = new File('src/main/resources/plugin.yml') - def bungeeYamlFile = new File('src/main/resources/bungee.yml') + def bukkitYamlFile = new File(projectDir, 'src/main/resources/plugin.yml') + def bungeeYamlFile = new File(projectDir, 'src/main/resources/bungee.yml') def files = [bukkitYamlFile, bungeeYamlFile] files.each { file -> @@ -163,7 +163,7 @@ void updateYamls() { } void updateJsons() { - def velocityJson = new File('src/main/resources/velocity-plugin.json') + def velocityJson = new File(projectDir, 'src/main/resources/velocity-plugin.json') def files = [velocityJson] files.each { file -> diff --git a/src/main/java/net/tcpshield/tcpshield/velocity/handler/VelocityPlayer.java b/src/main/java/net/tcpshield/tcpshield/velocity/handler/VelocityPlayer.java index fda9395..a0097d3 100644 --- a/src/main/java/net/tcpshield/tcpshield/velocity/handler/VelocityPlayer.java +++ b/src/main/java/net/tcpshield/tcpshield/velocity/handler/VelocityPlayer.java @@ -22,6 +22,7 @@ public class VelocityPlayer implements PlayerProvider { */ private static final Class INITIAL_INBOUND_CONNECTION_CLASS; private static final Field MINECRAFT_CONNECTION_FIELD; + private static final Class LEGACY_INBOUND_CONNECTION_CLASS; private static final Field LEGACY_MINECRAFT_CONNECTION_FIELD; private static final Field REMOTE_ADDRESS_FIELD; private static final Method CLOSE_CHANNEL_METHOD; @@ -30,7 +31,8 @@ public class VelocityPlayer implements PlayerProvider { try { INITIAL_INBOUND_CONNECTION_CLASS = Class.forName("com.velocitypowered.proxy.connection.client.InitialInboundConnection"); MINECRAFT_CONNECTION_FIELD = ReflectionUtil.getPrivateField(INITIAL_INBOUND_CONNECTION_CLASS, "connection"); - LEGACY_MINECRAFT_CONNECTION_FIELD = ReflectionUtil.getPrivateField(Class.forName("com.velocitypowered.proxy.connection.client.HandshakeSessionHandler$LegacyInboundConnection"), "connection"); + LEGACY_INBOUND_CONNECTION_CLASS = Class.forName("com.velocitypowered.proxy.connection.client.HandshakeSessionHandler$LegacyInboundConnection"); + LEGACY_MINECRAFT_CONNECTION_FIELD = ReflectionUtil.getPrivateField(LEGACY_INBOUND_CONNECTION_CLASS, "connection"); Class minecraftConnection = Class.forName("com.velocitypowered.proxy.connection.MinecraftConnection"); REMOTE_ADDRESS_FIELD = ReflectionUtil.getPrivateField(minecraftConnection, "remoteAddress"); @@ -94,6 +96,9 @@ public void setIP(InetSocketAddress ip) throws PlayerManipulationException { @Override public void disconnect() { try { + if (!INITIAL_INBOUND_CONNECTION_CLASS.isAssignableFrom(inboundConnection.getClass()) && !LEGACY_INBOUND_CONNECTION_CLASS.isAssignableFrom(inboundConnection.getClass())) + return; + Object minecraftConnection = legacy ? LEGACY_MINECRAFT_CONNECTION_FIELD.get(inboundConnection) : MINECRAFT_CONNECTION_FIELD.get(inboundConnection); CLOSE_CHANNEL_METHOD.invoke(minecraftConnection);