diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/MinecraftRegistry.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/MinecraftRegistry.java index 34f7a341..e433604e 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/MinecraftRegistry.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/MinecraftRegistry.java @@ -24,6 +24,7 @@ import java.util.Map; import java.util.Set; import net.minecraft.server.Packet; +import net.sf.cglib.proxy.Factory; import com.comphenix.protocol.reflect.FieldAccessException; import com.comphenix.protocol.reflect.FieldUtils; @@ -166,7 +167,7 @@ class MinecraftRegistry { // Optimized lookup if (lookup.containsKey(packetID)) { - return lookup.get(packetID); + return removeEnhancer(lookup.get(packetID), forceVanilla); } // Will most likely not be used @@ -174,10 +175,27 @@ class MinecraftRegistry { if (Objects.equal(entry.getValue(), packetID)) { // Attempt to get the vanilla class here too if (!forceVanilla || entry.getKey().getName().startsWith("net.minecraft.server")) - return entry.getKey(); + return removeEnhancer(entry.getKey(), forceVanilla); } } throw new IllegalArgumentException("The packet ID " + packetID + " is not registered."); } + + /** + * Find the first superclass that is not a CBLib proxy object. + * @param clazz - the class whose hierachy we're going to search through. + * @param remove - whether or not to skip enhanced (proxy) classes. + * @return If remove is TRUE, the first superclass that is not a proxy. + */ + private static Class removeEnhancer(Class clazz, boolean remove) { + if (remove) { + // Get the underlying vanilla class + while (Factory.class.isAssignableFrom(clazz) && !clazz.equals(Object.class)) { + clazz = clazz.getSuperclass(); + } + } + + return clazz; + } } diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/InjectedArrayList.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/InjectedArrayList.java index fd5a0b80..d92d4803 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/InjectedArrayList.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/InjectedArrayList.java @@ -27,6 +27,7 @@ import com.comphenix.protocol.injector.player.NetworkFieldInjector.FakePacket; import net.minecraft.server.Packet; import net.sf.cglib.proxy.Enhancer; +import net.sf.cglib.proxy.Factory; import net.sf.cglib.proxy.MethodInterceptor; import net.sf.cglib.proxy.MethodProxy; @@ -95,7 +96,7 @@ class InjectedArrayList extends ArrayList { int packetID = invoker.getPacketID(source); Class type = invoker.getPacketClassFromID(packetID, true); - + // We want to subtract the byte amount that were added to the running // total of outstanding packets. Otherwise, cancelling too many packets // might cause a "disconnect.overflow" error.