3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-20 15:00:09 +01:00

Don't cast ChannelInitializer type to SocketChannel

Dieser Commit ist enthalten in:
KennyTV 2021-05-22 19:41:07 +02:00
Ursprung 8bcd8fd995
Commit 15a5d51248
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
2 geänderte Dateien mit 11 neuen und 12 gelöschten Zeilen

Datei anzeigen

@ -24,18 +24,17 @@ import com.viaversion.viaversion.connection.UserConnectionImpl;
import com.viaversion.viaversion.protocol.ProtocolPipelineImpl; import com.viaversion.viaversion.protocol.ProtocolPipelineImpl;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.ByteToMessageDecoder; import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.MessageToByteEncoder; import io.netty.handler.codec.MessageToByteEncoder;
import java.lang.reflect.Method; 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; private Method method;
public BukkitChannelInitializer(ChannelInitializer<SocketChannel> oldInit) { public BukkitChannelInitializer(ChannelInitializer<Channel> oldInit) {
this.original = oldInit; this.original = oldInit;
try { try {
this.method = ChannelInitializer.class.getDeclaredMethod("initChannel", Channel.class); 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; return original;
} }
@Override @Override
protected void initChannel(SocketChannel socketChannel) throws Exception { protected void initChannel(Channel channel) throws Exception {
// Add originals // Add originals
this.method.invoke(this.original, socketChannel); this.method.invoke(this.original, channel);
afterChannelInitialize(socketChannel); afterChannelInitialize(channel);
} }
public static void afterChannelInitialize(Channel channel) { public static void afterChannelInitialize(Channel channel) {

Datei anzeigen

@ -27,10 +27,10 @@ import com.viaversion.viaversion.util.ConcurrentList;
import com.viaversion.viaversion.util.ListWrapper; import com.viaversion.viaversion.util.ListWrapper;
import com.viaversion.viaversion.util.Pair; import com.viaversion.viaversion.util.Pair;
import com.viaversion.viaversion.util.ReflectionUtil; import com.viaversion.viaversion.util.ReflectionUtil;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginDescriptionFile;
@ -116,7 +116,7 @@ public class BukkitViaInjector implements ViaInjector {
bootstrapAcceptor = future.channel().pipeline().first(); bootstrapAcceptor = future.channel().pipeline().first();
} }
try { try {
ChannelInitializer<SocketChannel> oldInit = ReflectionUtil.get(bootstrapAcceptor, "childHandler", ChannelInitializer.class); ChannelInitializer<Channel> oldInit = ReflectionUtil.get(bootstrapAcceptor, "childHandler", ChannelInitializer.class);
ChannelInitializer newInit = new BukkitChannelInitializer(oldInit); ChannelInitializer newInit = new BukkitChannelInitializer(oldInit);
ReflectionUtil.set(bootstrapAcceptor, "childHandler", newInit); ReflectionUtil.set(bootstrapAcceptor, "childHandler", newInit);
@ -153,7 +153,7 @@ public class BukkitViaInjector implements ViaInjector {
for (String name : names) { for (String name : names) {
ChannelHandler handler = future.channel().pipeline().get(name); ChannelHandler handler = future.channel().pipeline().get(name);
try { try {
ChannelInitializer<SocketChannel> oldInit = ReflectionUtil.get(handler, "childHandler", ChannelInitializer.class); ChannelInitializer<Channel> oldInit = ReflectionUtil.get(handler, "childHandler", ChannelInitializer.class);
if (oldInit instanceof BukkitChannelInitializer) { if (oldInit instanceof BukkitChannelInitializer) {
bootstrapAcceptor = handler; bootstrapAcceptor = handler;
} }
@ -167,7 +167,7 @@ public class BukkitViaInjector implements ViaInjector {
} }
try { try {
ChannelInitializer<SocketChannel> oldInit = ReflectionUtil.get(bootstrapAcceptor, "childHandler", ChannelInitializer.class); ChannelInitializer<Channel> oldInit = ReflectionUtil.get(bootstrapAcceptor, "childHandler", ChannelInitializer.class);
if (oldInit instanceof BukkitChannelInitializer) { if (oldInit instanceof BukkitChannelInitializer) {
ReflectionUtil.set(bootstrapAcceptor, "childHandler", ((BukkitChannelInitializer) oldInit).getOriginal()); ReflectionUtil.set(bootstrapAcceptor, "childHandler", ((BukkitChannelInitializer) oldInit).getOriginal());
} }