From cd7894f9f1b659cb8df4e5bdb82b74afbcb823d3 Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Fri, 23 Oct 2015 20:28:49 -0400 Subject: [PATCH] Ignore improperly registered custom packets Fixes #123 --- .../protocol/compat/netty/Netty.java | 4 +++ .../injector/netty/NettyProtocolRegistry.java | 26 +++++++++++-------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/compat/netty/Netty.java b/ProtocolLib/src/main/java/com/comphenix/protocol/compat/netty/Netty.java index f79c5678..8d09ef18 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/compat/netty/Netty.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/compat/netty/Netty.java @@ -53,6 +53,10 @@ public class Netty { return compat; } + public static boolean isIndependent() { + return compat instanceof IndependentNetty; + } + public static WrappedByteBuf createPacketBuffer() { return getCompat().createPacketBuffer(); } diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/NettyProtocolRegistry.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/NettyProtocolRegistry.java index 044a40e4..8b2fea93 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/NettyProtocolRegistry.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/NettyProtocolRegistry.java @@ -9,10 +9,10 @@ import java.util.Set; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.PacketType.Protocol; import com.comphenix.protocol.PacketType.Sender; +import com.comphenix.protocol.compat.netty.Netty; import com.comphenix.protocol.injector.packet.MapContainer; import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.utility.MinecraftReflection; -import com.comphenix.protocol.utility.MinecraftVersion; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.google.common.collect.Iterables; @@ -109,14 +109,13 @@ public class NettyProtocolRegistry { * Load the packet lookup tables in each protocol. */ private synchronized void initialize() { - Object[] protocols = enumProtocol.getEnumConstants(); - - // TODO: Find a better less than 1.7 check - if (MinecraftVersion.getCurrentVersion().compareTo(MinecraftVersion.BOUNTIFUL_UPDATE) < 0) { + if (!Netty.isIndependent()) { // Check for 1.7 initialize17(); return; } + Object[] protocols = enumProtocol.getEnumConstants(); + // ID to Packet class maps Map>> serverMaps = Maps.newLinkedHashMap(); Map>> clientMaps = Maps.newLinkedHashMap(); @@ -218,12 +217,17 @@ public class NettyProtocolRegistry { private void associatePackets(Register register, Map> lookup, Protocol protocol, Sender sender) { for (Entry> entry : lookup.entrySet()) { PacketType type = PacketType.fromCurrent(protocol, sender, entry.getKey(), PacketType.UNKNOWN_PACKET); - register.typeToClass.put(type, entry.getValue()); - - if (sender == Sender.SERVER) - register.serverPackets.add(type); - if (sender == Sender.CLIENT) - register.clientPackets.add(type); + + try { + register.typeToClass.put(type, entry.getValue()); + + if (sender == Sender.SERVER) + register.serverPackets.add(type); + if (sender == Sender.CLIENT) + register.clientPackets.add(type); + } catch (IllegalArgumentException ex) { + // Sometimes this happens with fake packets, just ignore it + } } }