From c8e8f39f9d6d9b42bfe7cb57edd746afb78d4e04 Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Sat, 12 Jan 2019 12:44:35 -0200 Subject: [PATCH] Fix new velocity version --- .../velocity/handlers/VelocityServerHandler.java | 15 ++++++++++----- .../velocity/storage/VelocityStorage.java | 7 +++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/velocity/src/main/java/us/myles/ViaVersion/velocity/handlers/VelocityServerHandler.java b/velocity/src/main/java/us/myles/ViaVersion/velocity/handlers/VelocityServerHandler.java index ec35636a4..3d07d23f1 100644 --- a/velocity/src/main/java/us/myles/ViaVersion/velocity/handlers/VelocityServerHandler.java +++ b/velocity/src/main/java/us/myles/ViaVersion/velocity/handlers/VelocityServerHandler.java @@ -14,7 +14,6 @@ import us.myles.ViaVersion.api.protocol.ProtocolPipeline; import us.myles.ViaVersion.api.protocol.ProtocolRegistry; import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker; -import us.myles.ViaVersion.util.ReflectionUtil; import us.myles.ViaVersion.velocity.service.ProtocolDetectorService; import us.myles.ViaVersion.velocity.storage.VelocityStorage; @@ -26,6 +25,8 @@ import java.util.concurrent.Semaphore; public class VelocityServerHandler { private static Method setProtocolVersion; private static Method setNextProtocolVersion; + private static Method getMinecraftConnection; + private static Method getNextProtocolVersion; static { try { @@ -33,6 +34,10 @@ public class VelocityServerHandler { .getDeclaredMethod("setProtocolVersion", ProtocolVersion.class); setNextProtocolVersion = Class.forName("com.velocitypowered.proxy.connection.MinecraftConnection") .getDeclaredMethod("setNextProtocolVersion", ProtocolVersion.class); + getMinecraftConnection = Class.forName("com.velocitypowered.proxy.connection.client.ConnectedPlayer") + .getDeclaredMethod("getMinecraftConnection"); + getNextProtocolVersion = Class.forName("com.velocitypowered.proxy.connection.MinecraftConnection") + .getDeclaredMethod("getNextProtocolVersion"); } catch (NoSuchMethodException | ClassNotFoundException e) { e.printStackTrace(); } @@ -51,12 +56,12 @@ public class VelocityServerHandler { List> protocols = ProtocolRegistry.getProtocolPath(user.get(ProtocolInfo.class).getProtocolVersion(), protocolId); // Check if ViaVersion can support that version - Object connection = ReflectionUtil.invoke(e.getPlayer(), "getConnection"); + Object connection = getMinecraftConnection.invoke(e.getPlayer()); setNextProtocolVersion.invoke(connection, ProtocolVersion.getProtocolVersion(protocols == null ? user.get(ProtocolInfo.class).getProtocolVersion() : protocolId)); - } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e1) { + } catch (IllegalAccessException | InvocationTargetException e1) { e1.printStackTrace(); } } @@ -132,8 +137,8 @@ public class VelocityServerHandler { protocol.init(user); } - Object connection = ReflectionUtil.invoke(e.getPlayer(), "getConnection"); - ProtocolVersion version = (ProtocolVersion) ReflectionUtil.invoke(connection, "getNextProtocolVersion"); + Object connection = getMinecraftConnection.invoke(e.getPlayer()); + ProtocolVersion version = (ProtocolVersion) getNextProtocolVersion.invoke(connection); setProtocolVersion.invoke(connection, version); } } diff --git a/velocity/src/main/java/us/myles/ViaVersion/velocity/storage/VelocityStorage.java b/velocity/src/main/java/us/myles/ViaVersion/velocity/storage/VelocityStorage.java index 353430070..bddd50852 100644 --- a/velocity/src/main/java/us/myles/ViaVersion/velocity/storage/VelocityStorage.java +++ b/velocity/src/main/java/us/myles/ViaVersion/velocity/storage/VelocityStorage.java @@ -5,9 +5,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; import us.myles.ViaVersion.api.data.StoredObject; import us.myles.ViaVersion.api.data.UserConnection; -import us.myles.ViaVersion.util.ReflectionUtil; -import java.lang.reflect.InvocationTargetException; import java.util.Set; import java.util.UUID; @@ -24,15 +22,16 @@ public class VelocityStorage extends StoredObject { this.currentServer = ""; // Get bossbar list if it's supported + /* TODO make this work - do we need this? try { Object connection = ReflectionUtil.invoke(player, "getConnection"); Object sessionHandler = ReflectionUtil.invoke(connection, "getSessionHandler"); if (sessionHandler.getClass().getSimpleName().contains("Play")) { - bossbar = (Set) ReflectionUtil.invoke(sessionHandler, "getServerBossBars"); - // TODO make this work + bossbar = (Set) ReflectionUtil.invoke(sessionHandler, "getServerBossBars"); } } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { e.printStackTrace(); } + */ } }