From 15a5d512480d7ee94e2e836769a14ac1de39e187 Mon Sep 17 00:00:00 2001 From: KennyTV Date: Sat, 22 May 2021 19:41:07 +0200 Subject: [PATCH] Don't cast ChannelInitializer type to SocketChannel --- .../bukkit/handlers/BukkitChannelInitializer.java | 15 +++++++-------- .../bukkit/platform/BukkitViaInjector.java | 8 ++++---- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/handlers/BukkitChannelInitializer.java b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/handlers/BukkitChannelInitializer.java index d76f78554..3e04bb6b2 100644 --- a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/handlers/BukkitChannelInitializer.java +++ b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/handlers/BukkitChannelInitializer.java @@ -24,18 +24,17 @@ import com.viaversion.viaversion.connection.UserConnectionImpl; import com.viaversion.viaversion.protocol.ProtocolPipelineImpl; import io.netty.channel.Channel; import io.netty.channel.ChannelInitializer; -import io.netty.channel.socket.SocketChannel; import io.netty.handler.codec.ByteToMessageDecoder; import io.netty.handler.codec.MessageToByteEncoder; import java.lang.reflect.Method; -public class BukkitChannelInitializer extends ChannelInitializer { +public class BukkitChannelInitializer extends ChannelInitializer { - private final ChannelInitializer original; + private final ChannelInitializer original; private Method method; - public BukkitChannelInitializer(ChannelInitializer oldInit) { + public BukkitChannelInitializer(ChannelInitializer oldInit) { this.original = oldInit; try { this.method = ChannelInitializer.class.getDeclaredMethod("initChannel", Channel.class); @@ -45,15 +44,15 @@ public class BukkitChannelInitializer extends ChannelInitializer } } - public ChannelInitializer getOriginal() { + public ChannelInitializer getOriginal() { return original; } @Override - protected void initChannel(SocketChannel socketChannel) throws Exception { + protected void initChannel(Channel channel) throws Exception { // Add originals - this.method.invoke(this.original, socketChannel); - afterChannelInitialize(socketChannel); + this.method.invoke(this.original, channel); + afterChannelInitialize(channel); } public static void afterChannelInitialize(Channel channel) { diff --git a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaInjector.java b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaInjector.java index ae2307f08..467007a95 100644 --- a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaInjector.java +++ b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaInjector.java @@ -27,10 +27,10 @@ import com.viaversion.viaversion.util.ConcurrentList; import com.viaversion.viaversion.util.ListWrapper; import com.viaversion.viaversion.util.Pair; import com.viaversion.viaversion.util.ReflectionUtil; +import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelInitializer; -import io.netty.channel.socket.SocketChannel; import org.bukkit.Bukkit; import org.bukkit.plugin.PluginDescriptionFile; @@ -116,7 +116,7 @@ public class BukkitViaInjector implements ViaInjector { bootstrapAcceptor = future.channel().pipeline().first(); } try { - ChannelInitializer oldInit = ReflectionUtil.get(bootstrapAcceptor, "childHandler", ChannelInitializer.class); + ChannelInitializer oldInit = ReflectionUtil.get(bootstrapAcceptor, "childHandler", ChannelInitializer.class); ChannelInitializer newInit = new BukkitChannelInitializer(oldInit); ReflectionUtil.set(bootstrapAcceptor, "childHandler", newInit); @@ -153,7 +153,7 @@ public class BukkitViaInjector implements ViaInjector { for (String name : names) { ChannelHandler handler = future.channel().pipeline().get(name); try { - ChannelInitializer oldInit = ReflectionUtil.get(handler, "childHandler", ChannelInitializer.class); + ChannelInitializer oldInit = ReflectionUtil.get(handler, "childHandler", ChannelInitializer.class); if (oldInit instanceof BukkitChannelInitializer) { bootstrapAcceptor = handler; } @@ -167,7 +167,7 @@ public class BukkitViaInjector implements ViaInjector { } try { - ChannelInitializer oldInit = ReflectionUtil.get(bootstrapAcceptor, "childHandler", ChannelInitializer.class); + ChannelInitializer oldInit = ReflectionUtil.get(bootstrapAcceptor, "childHandler", ChannelInitializer.class); if (oldInit instanceof BukkitChannelInitializer) { ReflectionUtil.set(bootstrapAcceptor, "childHandler", ((BukkitChannelInitializer) oldInit).getOriginal()); }