Don't cast ChannelInitializer type to SocketChannel

This commit is contained in:
KennyTV 2021-05-22 19:41:07 +02:00
parent 8bcd8fd995
commit 15a5d51248
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
2 changed files with 11 additions and 12 deletions

View File

@ -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<SocketChannel> {
public class BukkitChannelInitializer extends ChannelInitializer<Channel> {
private final ChannelInitializer<SocketChannel> original;
private final ChannelInitializer<Channel> original;
private Method method;
public BukkitChannelInitializer(ChannelInitializer<SocketChannel> oldInit) {
public BukkitChannelInitializer(ChannelInitializer<Channel> oldInit) {
this.original = oldInit;
try {
this.method = ChannelInitializer.class.getDeclaredMethod("initChannel", Channel.class);
@ -45,15 +44,15 @@ public class BukkitChannelInitializer extends ChannelInitializer<SocketChannel>
}
}
public ChannelInitializer<SocketChannel> getOriginal() {
public ChannelInitializer<Channel> 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) {

View File

@ -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<SocketChannel> oldInit = ReflectionUtil.get(bootstrapAcceptor, "childHandler", ChannelInitializer.class);
ChannelInitializer<Channel> 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<SocketChannel> oldInit = ReflectionUtil.get(handler, "childHandler", ChannelInitializer.class);
ChannelInitializer<Channel> oldInit = ReflectionUtil.get(handler, "childHandler", ChannelInitializer.class);
if (oldInit instanceof BukkitChannelInitializer) {
bootstrapAcceptor = handler;
}
@ -167,7 +167,7 @@ public class BukkitViaInjector implements ViaInjector {
}
try {
ChannelInitializer<SocketChannel> oldInit = ReflectionUtil.get(bootstrapAcceptor, "childHandler", ChannelInitializer.class);
ChannelInitializer<Channel> oldInit = ReflectionUtil.get(bootstrapAcceptor, "childHandler", ChannelInitializer.class);
if (oldInit instanceof BukkitChannelInitializer) {
ReflectionUtil.set(bootstrapAcceptor, "childHandler", ((BukkitChannelInitializer) oldInit).getOriginal());
}