From 58fd0bdc9eaa7bdf3e618271041d75cb10662574 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Tue, 25 Oct 2022 10:36:09 +0200 Subject: [PATCH] Remove 1.8 PS compat hack --- .../bukkit/classgenerator/ClassGenerator.java | 83 +------------------ .../bukkit/handlers/BukkitEncodeHandler.java | 2 +- 2 files changed, 5 insertions(+), 80 deletions(-) diff --git a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/classgenerator/ClassGenerator.java b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/classgenerator/ClassGenerator.java index 9555c4d8d..921c4a31e 100644 --- a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/classgenerator/ClassGenerator.java +++ b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/classgenerator/ClassGenerator.java @@ -48,7 +48,6 @@ import java.lang.reflect.Method; public final class ClassGenerator { private static final boolean useModules = hasModuleMethod(); private static HandlerSupplier constructor = new HandlerSupplier.DefaultHandlerSupplier(); - private static String psPackage; private static Class psConnectListener; public static HandlerSupplier handlerSupplier() { @@ -72,19 +71,10 @@ public final class ClassGenerator { addSpigotCompatibility(pool, BukkitEncodeHandler.class, encodeSuper); } else { // ProtocolSupport compatibility - Class encodeSuper; - Class decodeSuper; if (isMultiplatformPS()) { psConnectListener = makePSConnectListener(pool); return; - } else { - String psPackage = getOldPSPackage(); - decodeSuper = Class.forName(psPackage.equals("unknown") ? "protocolsupport.protocol.pipeline.common.PacketDecoder" : psPackage + ".wrapped.WrappedDecoder"); - encodeSuper = Class.forName(psPackage.equals("unknown") ? "protocolsupport.protocol.pipeline.common.PacketEncoder" : psPackage + ".wrapped.WrappedEncoder"); } - // Generate the classes - addPSCompatibility(pool, BukkitDecodeHandler.class, decodeSuper); - addPSCompatibility(pool, BukkitEncodeHandler.class, encodeSuper); } @@ -99,11 +89,11 @@ public final class ClassGenerator { pool.importPackage("com.viaversion.viaversion.api.connection"); pool.importPackage("io.netty.handler.codec"); // Implement Methods - generated.addMethod(CtMethod.make("public MessageToByteEncoder newEncodeHandler(UserConnection info, MessageToByteEncoder minecraftEncoder) {\n" + - " return new BukkitEncodeHandler(info, minecraftEncoder);\n" + + generated.addMethod(CtMethod.make("public MessageToMessageEncoder newEncodeHandler(UserConnection connection) {\n" + + " return new BukkitEncodeHandler(connection);\n" + " }", generated)); - generated.addMethod(CtMethod.make("public ByteToMessageDecoder newDecodeHandler(UserConnection info, ByteToMessageDecoder minecraftDecoder) {\n" + - " return new BukkitDecodeHandler(info, minecraftDecoder);\n" + + generated.addMethod(CtMethod.make("public MessageToMessageDecoder newDecodeHandler(UserConnection connection) {\n" + + " return new BukkitDecodeHandler(connection);\n" + " }", generated)); constructor = (HandlerSupplier) toClass(generated).getConstructor().newInstance(); @@ -147,54 +137,6 @@ public final class ClassGenerator { } } - private static void addPSCompatibility(ClassPool pool, Class input, Class superclass) { - boolean newPS = getOldPSPackage().equals("unknown"); - String newName = "com.viaversion.viaversion.classgenerator.generated." + input.getSimpleName(); - - try { - CtClass generated = pool.getAndRename(input.getName(), newName); - if (superclass != null) { - CtClass toExtend = pool.get(superclass.getName()); - generated.setSuperclass(toExtend); - - if (!newPS) { - // Override setRealEncoder / setRealDecoder - pool.importPackage(getOldPSPackage()); - pool.importPackage(getOldPSPackage() + ".wrapped"); - if (superclass.getName().endsWith("Decoder")) { - // Decoder - generated.addMethod(CtMethod.make("public void setRealDecoder(IPacketDecoder dec) {\n" + - " ((WrappedDecoder) this.minecraftDecoder).setRealDecoder(dec);\n" + - " }", generated)); - } else { - // Encoder - pool.importPackage("protocolsupport.api"); - pool.importPackage("java.lang.reflect"); - generated.addMethod(CtMethod.make("public void setRealEncoder(IPacketEncoder enc) {\n" + - " try {\n" + - // Tell ProtocolSupport to decode MINECRAFT_FUTURE packets using the default decoder (for 1.9.4) - " Field field = enc.getClass().getDeclaredField(\"version\");\n" + - " field.setAccessible(true);\n" + - " ProtocolVersion version = (ProtocolVersion) field.get(enc);\n" + - - " if (version == ProtocolVersion.MINECRAFT_FUTURE) enc = enc.getClass().getConstructor(\n" + - " new Class[]{ProtocolVersion.class}).newInstance(new Object[] {ProtocolVersion.getLatest()});\n" + - " } catch (Exception e) {\n" + - // I guess we're not on 1.9.4 - " }\n" + - " ((WrappedEncoder) this.minecraftEncoder).setRealEncoder(enc);\n" + - " }", generated)); - } - } - } - toClass(generated); - } catch (NotFoundException e) { - e.printStackTrace(); - } catch (CannotCompileException e) { - e.printStackTrace(); - } - } - private static Class makePSConnectListener(ClassPool pool) { HandshakeProtocolType type = handshakeVersionMethod(); try { @@ -275,23 +217,6 @@ public final class ClassGenerator { return psConnectListener; } - public static String getOldPSPackage() { - if (psPackage == null) { - try { - Class.forName("protocolsupport.protocol.core.IPacketDecoder"); - psPackage = "protocolsupport.protocol.core"; - } catch (ClassNotFoundException e) { - try { - Class.forName("protocolsupport.protocol.pipeline.IPacketDecoder"); - psPackage = "protocolsupport.protocol.pipeline"; - } catch (ClassNotFoundException e1) { - psPackage = "unknown"; - } - } - } - return psPackage; - } - public static boolean isMultiplatformPS() { try { Class.forName("protocolsupport.zplatform.impl.spigot.network.pipeline.SpigotPacketEncoder"); diff --git a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/handlers/BukkitEncodeHandler.java b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/handlers/BukkitEncodeHandler.java index 710d75ac3..163f7d433 100644 --- a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/handlers/BukkitEncodeHandler.java +++ b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/handlers/BukkitEncodeHandler.java @@ -90,7 +90,7 @@ public final class BukkitEncodeHandler extends MessageToMessageEncoder pipeline.addAfter(BukkitChannelInitializer.MINECRAFT_DECOMPRESSOR, BukkitChannelInitializer.VIA_DECODER, pipeline.remove(BukkitChannelInitializer.VIA_DECODER)); return true; } - return true; + return false; } private void recompress(final ChannelHandlerContext ctx, final ByteBuf buf) throws Exception {