diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketContainer.java b/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketContainer.java index 46d5e7f2..144a0a97 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketContainer.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketContainer.java @@ -17,7 +17,9 @@ package com.comphenix.protocol.events; +import java.io.DataInput; import java.io.DataInputStream; +import java.io.DataOutput; import java.io.DataOutputStream; import java.io.IOException; import java.io.ObjectInputStream; @@ -49,6 +51,7 @@ import com.comphenix.protocol.reflect.cloning.CollectionCloner; import com.comphenix.protocol.reflect.cloning.FieldCloner; import com.comphenix.protocol.reflect.cloning.ImmutableDetector; import com.comphenix.protocol.reflect.cloning.AggregateCloner.BuilderParameters; +import com.comphenix.protocol.reflect.fuzzy.FuzzyMethodContract; import com.comphenix.protocol.reflect.instances.DefaultInstances; import com.comphenix.protocol.utility.MinecraftReflection; import com.comphenix.protocol.utility.StreamSerializer; @@ -456,7 +459,7 @@ public class PacketContainer implements Serializable { try { // Call the write-method - getMethodLazily(writeMethods, handle.getClass(), "write", DataOutputStream.class). + getMethodLazily(writeMethods, handle.getClass(), "write", DataOutput.class). invoke(handle, new DataOutputStream(output)); } catch (IllegalArgumentException e) { @@ -483,7 +486,7 @@ public class PacketContainer implements Serializable { // Call the read method try { - getMethodLazily(readMethods, handle.getClass(), "read", DataInputStream.class). + getMethodLazily(readMethods, handle.getClass(), "read", DataInput.class). invoke(handle, new DataInputStream(input)); } catch (IllegalArgumentException e) { @@ -513,7 +516,12 @@ public class PacketContainer implements Serializable { // Atomic operation if (method == null) { - Method initialized = FuzzyReflection.fromClass(handleClass).getMethodByParameters(methodName, parameterClass); + Method initialized = FuzzyReflection.fromClass(handleClass).getMethod( + FuzzyMethodContract.newBuilder(). + parameterCount(1). + parameterDerivedOf(parameterClass). + returnTypeVoid(). + build()); method = lookup.putIfAbsent(handleClass, initialized); // Use our version if we succeeded diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/events/PacketContainerTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/events/PacketContainerTest.java index 5d3c75f2..917b160a 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/events/PacketContainerTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/events/PacketContainerTest.java @@ -21,6 +21,7 @@ import static org.junit.Assert.*; import java.lang.reflect.Array; import java.util.List; +import org.apache.commons.lang.SerializationUtils; // Will have to be updated for every version though import org.bukkit.craftbukkit.v1_6_R2.inventory.CraftItemFactory; @@ -305,6 +306,17 @@ public class PacketContainerTest { watchableAccessor.write(0, list); assertEquals(list, watchableAccessor.read(0)); } + + @Test + public void testSerialization() { + PacketContainer chat = new PacketContainer(3); + chat.getStrings().write(0, "Test"); + + PacketContainer copy = (PacketContainer) SerializationUtils.clone(chat); + + assertEquals(3, copy.getID()); + assertEquals("Test", copy.getStrings().read(0)); + } @Test public void testDeepClone() {