From f372b247f9baa9a3dbc98a3ff6893f7a01e51c22 Mon Sep 17 00:00:00 2001 From: "Kristian S. Stangeland" Date: Thu, 13 Sep 2012 11:34:47 +0200 Subject: [PATCH] Add support for 1.3.2 --- .../src/com/comphenix/protocol/ProtocolManager.java | 4 ++++ .../comphenix/protocol/injector/PlayerInjector.java | 10 ++++++---- .../comphenix/protocol/injector/StructureCache.java | 4 +++- .../protocol/reflect/StructureModifier.java | 13 +++++++++---- .../protocol/reflect/StructureModifierTest.java | 3 ++- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/ProtocolLib/src/com/comphenix/protocol/ProtocolManager.java b/ProtocolLib/src/com/comphenix/protocol/ProtocolManager.java index c109d32d..cd0272b5 100644 --- a/ProtocolLib/src/com/comphenix/protocol/ProtocolManager.java +++ b/ProtocolLib/src/com/comphenix/protocol/ProtocolManager.java @@ -9,6 +9,10 @@ import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketListener; import com.google.common.collect.ImmutableSet; +/** + * Represents an API for accessing the Minecraft protocol. + * @author Kristian + */ public interface ProtocolManager { /** diff --git a/ProtocolLib/src/com/comphenix/protocol/injector/PlayerInjector.java b/ProtocolLib/src/com/comphenix/protocol/injector/PlayerInjector.java index 49def95c..720bd7be 100644 --- a/ProtocolLib/src/com/comphenix/protocol/injector/PlayerInjector.java +++ b/ProtocolLib/src/com/comphenix/protocol/injector/PlayerInjector.java @@ -94,12 +94,14 @@ class PlayerInjector { Object serverHandler = FieldUtils.readField(serverHandlerField, notchEntity); // Next, get the network manager - if (networkManagerField == null) { + if (networkManagerField == null) networkManagerField = FuzzyReflection.fromObject(serverHandler).getFieldByType(".*NetworkManager"); - networkModifier = new StructureModifier(networkManagerField.getType(), null); - } networkManager = FieldUtils.readField(networkManagerField, serverHandler); + // Create the network manager modifier from the actual object type + if (networkManager != null && networkModifier == null) + networkModifier = new StructureModifier(networkManager.getClass(), null, false); + // And the queue method if (queueMethod == null) queueMethod = FuzzyReflection.fromClass(networkManagerField.getType()). @@ -207,7 +209,7 @@ class PlayerInjector { @SuppressWarnings("rawtypes") StructureModifier list = networkModifier.withType(List.class); - + // Subclass both send queues for (Field field : list.getFields()) { VolatileField overwriter = new VolatileField(field, networkManager, true); diff --git a/ProtocolLib/src/com/comphenix/protocol/injector/StructureCache.java b/ProtocolLib/src/com/comphenix/protocol/injector/StructureCache.java index e19e2555..7ca13c93 100644 --- a/ProtocolLib/src/com/comphenix/protocol/injector/StructureCache.java +++ b/ProtocolLib/src/com/comphenix/protocol/injector/StructureCache.java @@ -37,7 +37,9 @@ public class StructureCache { // Use the vanilla class definition if (result == null) { - result = new StructureModifier(MinecraftRegistry.getPacketClassFromID(id, true), Packet.class); + result = new StructureModifier( + MinecraftRegistry.getPacketClassFromID(id, true), Packet.class, true); + structureModifiers.put(id, result); } diff --git a/ProtocolLib/src/com/comphenix/protocol/reflect/StructureModifier.java b/ProtocolLib/src/com/comphenix/protocol/reflect/StructureModifier.java index 6dc22ec8..a5d7f2f8 100644 --- a/ProtocolLib/src/com/comphenix/protocol/reflect/StructureModifier.java +++ b/ProtocolLib/src/com/comphenix/protocol/reflect/StructureModifier.java @@ -35,12 +35,17 @@ public class StructureModifier { // Cache of previous types private Map subtypeCache; - public StructureModifier(Class targetType, Class superclassExclude) { + /** + * Creates a structure modifier. + * @param targetType - the structure to modify. + * @param superclassExclude - a superclass to exclude. + * @param requireDefault - whether or not we will be using writeDefaults(). + */ + public StructureModifier(Class targetType, Class superclassExclude, boolean requireDefault) { List fields = getFields(targetType, superclassExclude); + Set defaults = requireDefault ? generateDefaultFields(fields) : new HashSet(); - initialize(targetType, Object.class, - fields, generateDefaultFields(fields), null, - new HashMap()); + initialize(targetType, Object.class, fields, defaults, null, new HashMap()); } private StructureModifier(StructureModifier other, Object target) { diff --git a/ProtocolLib/test/com/comphenix/protocol/reflect/StructureModifierTest.java b/ProtocolLib/test/com/comphenix/protocol/reflect/StructureModifierTest.java index 3d1c8de0..82996a3b 100644 --- a/ProtocolLib/test/com/comphenix/protocol/reflect/StructureModifierTest.java +++ b/ProtocolLib/test/com/comphenix/protocol/reflect/StructureModifierTest.java @@ -15,7 +15,8 @@ public class StructureModifierTest { public void test() throws IllegalAccessException { Packet103SetSlot move = new Packet103SetSlot(); - StructureModifier modifier = new StructureModifier(Packet103SetSlot.class, Packet.class); + StructureModifier modifier = new StructureModifier( + Packet103SetSlot.class, Packet.class, true); move.a = 1; int value = (Integer) modifier.withTarget(move).withType(int.class).read(0);