From 1ed0f88702def219ca038645640e90c3206abbed Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 11 Jun 2025 11:42:42 +0200 Subject: [PATCH] Fix SteamwarConnectionListener --- build.gradle | 1 + .../listener/SteamwarConnectionListener.java | 39 ++----------------- 2 files changed, 5 insertions(+), 35 deletions(-) diff --git a/build.gradle b/build.gradle index 2e08343..08d1f70 100644 --- a/build.gradle +++ b/build.gradle @@ -39,4 +39,5 @@ dependencies { compileOnly 'net.md-5:bungeecord-api:1.21-R0.1-SNAPSHOT' compileOnly 'net.md-5:bungeecord-proxy:1.21-R0.1-SNAPSHOT' // compileOnly 'codecrafter47.bungeetablistplus:bungeetablistplus-api-bungee:3.5.2' + implementation 'it.unimi.dsi:fastutil-core:8.5.15' } diff --git a/src/de/steamwar/listener/SteamwarConnectionListener.java b/src/de/steamwar/listener/SteamwarConnectionListener.java index 59977df..645bd7a 100644 --- a/src/de/steamwar/listener/SteamwarConnectionListener.java +++ b/src/de/steamwar/listener/SteamwarConnectionListener.java @@ -20,9 +20,9 @@ package de.steamwar.listener; import de.steamwar.ConfigSystem; -import gnu.trove.map.TIntObjectMap; -import gnu.trove.map.TObjectIntMap; import io.netty.buffer.ByteBuf; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.objects.Object2IntMap; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.event.PostLoginEvent; @@ -64,7 +64,7 @@ public class SteamwarConnectionListener implements Listener { Protocol.DirectionData directionData = Protocol.HANDSHAKE.TO_SERVER; Field directionDataProtocols = Protocol.DirectionData.class.getDeclaredField("protocols"); directionDataProtocols.setAccessible(true); - TIntObjectMap protocols = (TIntObjectMap) directionDataProtocols.get(directionData); + Int2ObjectMap protocols = (Int2ObjectMap) directionDataProtocols.get(directionData); Class protocolDataClass = Class.forName("net.md_5.bungee.protocol.Protocol$ProtocolData"); Field protocolDataPacketMap = protocolDataClass.getDeclaredField("packetMap"); @@ -82,44 +82,13 @@ public class SteamwarConnectionListener implements Listener { for (int version : ProtocolConstants.SUPPORTED_VERSION_IDS) { Object protocolData = protocols.get(version); - TObjectIntMap> packetMap = (TObjectIntMap>) protocolDataPacketMap.get(protocolData); + Object2IntMap> packetMap = (Object2IntMap>) protocolDataPacketMap.get(protocolData); Supplier[] packetConstructors = (Supplier[]) protocolDataPacketConstructors.get(protocolData); packetMap.put(Handshake.class, packetID); packetConstructors[packetID] = SteamwarHandshake::new; } - /* - Field FIELD_TO_SERVER = Protocol.class.getDeclaredField("TO_SERVER"); - FIELD_TO_SERVER.setAccessible(true); - Protocol.DirectionData o = FIELD_TO_SERVER.get(Protocol.HANDSHAKE); - - - Class directionDataClazz = Class.forName("net.md_5.bungee.protocol.Protocol$DirectionData"); - Class protocolMappingClazz = Class.forName("net.md_5.bungee.protocol.Protocol$ProtocolMapping"); - - Field FIELD_PROTOCOLS = directionDataClazz.getDeclaredField("protocols"); - Object protocols = FIELD_PROTOCOLS.get(protocolMapping); - - Method method = Arrays.stream(directionDataClazz.getDeclaredMethods()) - .filter(m -> m.getName().equals("registerPacket")) - .filter(m -> m.getParameterCount() == 3) - .filter(m -> m.getParameterTypes()[0] == Class.class) - .filter(m -> m.getParameterTypes()[1] == Supplier.class) - .filter(m -> m.getParameterTypes()[2].isArray()) - .findFirst() - .orElseThrow(() -> new RuntimeException("Could not find registerPacket method")); - method.setAccessible(true); - Object protocolMappingArray = Array.newInstance(protocolMappingClazz, 1); - Array.set(protocolMappingArray, 0, protocolMapping); - method.invoke(o, Handshake.class, new Supplier() { - @Override - public Handshake get() { - return new SteamwarHandshake(); - } - }, protocolMappingArray); - */ - chField = InitialHandler.class.getDeclaredField("ch"); chField.setAccessible(true);