From e430bfce06f890478054d4454fb1f59af89d7310 Mon Sep 17 00:00:00 2001 From: Myles Date: Sun, 13 Nov 2016 13:34:22 +0000 Subject: [PATCH] Fix uninjection when different handler order --- .../bukkit/platform/BukkitViaInjector.java | 20 ++++++++++++++++++- .../sponge/platform/SpongeViaInjector.java | 20 ++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaInjector.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaInjector.java index c52b4452e..3025e18c1 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaInjector.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaInjector.java @@ -115,7 +115,25 @@ public class BukkitViaInjector implements ViaInjector { public void uninject() { // TODO: Uninject from players currently online to prevent protocol lib issues. for (ChannelFuture future : injectedFutures) { - ChannelHandler bootstrapAcceptor = future.channel().pipeline().first(); + List names = future.channel().pipeline().names(); + ChannelHandler bootstrapAcceptor = null; + // Pick best + for (String name : names) { + ChannelHandler handler = future.channel().pipeline().get(name); + try { + ChannelInitializer oldInit = ReflectionUtil.get(handler, "childHandler", ChannelInitializer.class); + if (oldInit instanceof BukkitChannelInitializer) { + bootstrapAcceptor = handler; + } + } catch (Exception e) { + // Not this one + } + } + // Default to first + if (bootstrapAcceptor == null) { + bootstrapAcceptor = future.channel().pipeline().first(); + } + try { ChannelInitializer oldInit = ReflectionUtil.get(bootstrapAcceptor, "childHandler", ChannelInitializer.class); if (oldInit instanceof BukkitChannelInitializer) { diff --git a/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaInjector.java b/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaInjector.java index 04b5a329e..a6ee44359 100644 --- a/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaInjector.java +++ b/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaInjector.java @@ -107,7 +107,25 @@ public class SpongeViaInjector implements ViaInjector { public void uninject() { // TODO: Uninject from players currently online for (ChannelFuture future : injectedFutures) { - ChannelHandler bootstrapAcceptor = future.channel().pipeline().first(); + List names = future.channel().pipeline().names(); + ChannelHandler bootstrapAcceptor = null; + // Pick best + for (String name : names) { + ChannelHandler handler = future.channel().pipeline().get(name); + try { + ChannelInitializer oldInit = ReflectionUtil.get(handler, "childHandler", ChannelInitializer.class); + if (oldInit instanceof SpongeChannelInitializer) { + bootstrapAcceptor = handler; + } + } catch (Exception e) { + // Not this one + } + } + // Default to first + if (bootstrapAcceptor == null) { + bootstrapAcceptor = future.channel().pipeline().first(); + } + try { ChannelInitializer oldInit = ReflectionUtil.get(bootstrapAcceptor, "childHandler", ChannelInitializer.class); if (oldInit instanceof SpongeChannelInitializer) {