From e1ea295600cdd66ab83522d9a784287081aa9cf3 Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Sat, 8 Jul 2017 02:10:24 -0400 Subject: [PATCH] Fix one of many issues with reloading I'm only fixing this because it was relatively simple and I got a lot of reports for it. Seriously people, Stop. Reloading. Fixes #373, fixes #368, fixes #360, fixes #359 --- .../protocol/injector/netty/ChannelInjector.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/modules/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelInjector.java b/modules/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelInjector.java index d5551c7b..eb284120 100644 --- a/modules/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelInjector.java +++ b/modules/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelInjector.java @@ -27,6 +27,7 @@ import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.atomic.AtomicInteger; import net.sf.cglib.proxy.Factory; @@ -92,7 +93,18 @@ public class ChannelInjector extends ByteToMessageDecoder implements Injector { // Versioning private static Class PACKET_SET_PROTOCOL = null; - private static AttributeKey PROTOCOL_KEY = AttributeKey.valueOf("PROTOCOL"); + + private static AtomicInteger keyId = new AtomicInteger(); + private static AttributeKey PROTOCOL_KEY; + + static { + // Shout-outs to reloading + try { + PROTOCOL_KEY = AttributeKey.valueOf("PROTOCOL"); + } catch (IllegalArgumentException ex) { + PROTOCOL_KEY = AttributeKey.valueOf("PROTOCOL-" + keyId.getAndIncrement()); + } + } // Saved accessors private static MethodAccessor DECODE_BUFFER; @@ -593,7 +605,7 @@ public class ChannelInjector extends ByteToMessageDecoder implements Injector { // Save the channel injector factory.cacheInjector(profile.getName(), this); } - + if (PACKET_SET_PROTOCOL == null) { try { PACKET_SET_PROTOCOL = PacketType.Handshake.Client.SET_PROTOCOL.getPacketClass();