From 1aaf272878c9aadd5c6868fb44ce7d0ccbba014f Mon Sep 17 00:00:00 2001 From: "Kristian S. Stangeland" Date: Sun, 8 Dec 2013 19:50:59 +0100 Subject: [PATCH] Don't attempt to inject closed channels. Fixes issue #23 --- .../protocol/injector/netty/ChannelInjector.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelInjector.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelInjector.java index ba7f609d..8479227d 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelInjector.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelInjector.java @@ -182,13 +182,18 @@ class ChannelInjector extends ByteToMessageDecoder { /** * Inject the current channel. + *

+ * Note that only active channels can be injected. + * @return TRUE if we injected the channel, false if we could not inject or it was already injected. */ @SuppressWarnings("unchecked") public boolean inject() { synchronized (networkManager) { if (originalChannel instanceof Factory) return false; - + if (!originalChannel.isActive()) + return false; + // Don't inject the same channel twice if (findChannelHandler(originalChannel, ChannelInjector.class) != null) { // Invalidate cache @@ -202,9 +207,9 @@ class ChannelInjector extends ByteToMessageDecoder { vanillaEncoder = (MessageToByteEncoder) originalChannel.pipeline().get("encoder"); if (vanillaDecoder == null) - throw new IllegalArgumentException("Unable to find vanilla decoder.in " + originalChannel.pipeline() + ". " + getChannelState()); + throw new IllegalArgumentException("Unable to find vanilla decoder.in " + originalChannel.pipeline() ); if (vanillaEncoder == null) - throw new IllegalArgumentException("Unable to find vanilla encoder in " + originalChannel.pipeline() + ". " + getChannelState()); + throw new IllegalArgumentException("Unable to find vanilla encoder in " + originalChannel.pipeline() ); patchEncoder(vanillaEncoder); if (DECODE_BUFFER == null) @@ -245,10 +250,6 @@ class ChannelInjector extends ByteToMessageDecoder { } } - private String getChannelState() { - return "Registered channel: " + originalChannel.isRegistered() + ", Active channel: " + originalChannel.isActive() + ", Open channel: " + originalChannel.isOpen(); - } - /** * Process a given message on the packet listeners. * @param message - the message/packet.