diff --git a/protocolize-bungeecord/src/main/java/dev/simplix/protocolize/bungee/netty/NettyPipelineInjector.java b/protocolize-bungeecord/src/main/java/dev/simplix/protocolize/bungee/netty/NettyPipelineInjector.java index 5c6e6d1..3f613ef 100644 --- a/protocolize-bungeecord/src/main/java/dev/simplix/protocolize/bungee/netty/NettyPipelineInjector.java +++ b/protocolize-bungeecord/src/main/java/dev/simplix/protocolize/bungee/netty/NettyPipelineInjector.java @@ -18,8 +18,13 @@ public void injectBefore(Connection connection, String baseName, String name, Ch Preconditions.checkNotNull(channelHandler, "The channelHandler cannot be null!"); try { final Object channelWrapper = ReflectionUtil.getChannelWrapper(connection); - if (channelWrapper != null) - ((Channel) ReflectionUtil.channelWrapperChannelField.get(channelWrapper)).pipeline().addBefore(baseName, name, channelHandler); + if (channelWrapper != null) { + ChannelPipeline pipeline = ((Channel) ReflectionUtil.channelWrapperChannelField.get(channelWrapper)).pipeline(); + if (pipeline.get(name) != null) { + pipeline.remove(name); + } + pipeline.addBefore(baseName, name, channelHandler); + } } catch (final Exception e) { ProxyServer.getInstance().getLogger().log(Level.SEVERE, "Exception occurred while injecting into netty pipeline", e); } @@ -32,8 +37,13 @@ public void injectAfter(Connection connection, String baseName, String name, Cha Preconditions.checkNotNull(channelHandler, "The channelHandler cannot be null!"); try { final Object channelWrapper = ReflectionUtil.getChannelWrapper(connection); - if (channelWrapper != null) - ((Channel) ReflectionUtil.channelWrapperChannelField.get(channelWrapper)).pipeline().addAfter(baseName, name, channelHandler); + if (channelWrapper != null) { + ChannelPipeline pipeline = ((Channel) ReflectionUtil.channelWrapperChannelField.get(channelWrapper)).pipeline(); + if (pipeline.get(name) != null) { + pipeline.remove(name); + } + pipeline.addAfter(baseName, name, channelHandler); + } } catch (final Exception e) { ProxyServer.getInstance().getLogger().log(Level.SEVERE, "Exception occurred while injecting into netty pipeline", e); }