mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-28 05:35:28 +01:00
Update packet container serialization for Minecraft 1.6.2.
This commit is contained in:
parent
c590e4a825
commit
1000378b78
@ -17,7 +17,9 @@
|
|||||||
|
|
||||||
package com.comphenix.protocol.events;
|
package com.comphenix.protocol.events;
|
||||||
|
|
||||||
|
import java.io.DataInput;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
|
import java.io.DataOutput;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.ObjectInputStream;
|
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.FieldCloner;
|
||||||
import com.comphenix.protocol.reflect.cloning.ImmutableDetector;
|
import com.comphenix.protocol.reflect.cloning.ImmutableDetector;
|
||||||
import com.comphenix.protocol.reflect.cloning.AggregateCloner.BuilderParameters;
|
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.reflect.instances.DefaultInstances;
|
||||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||||
import com.comphenix.protocol.utility.StreamSerializer;
|
import com.comphenix.protocol.utility.StreamSerializer;
|
||||||
@ -456,7 +459,7 @@ public class PacketContainer implements Serializable {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Call the write-method
|
// Call the write-method
|
||||||
getMethodLazily(writeMethods, handle.getClass(), "write", DataOutputStream.class).
|
getMethodLazily(writeMethods, handle.getClass(), "write", DataOutput.class).
|
||||||
invoke(handle, new DataOutputStream(output));
|
invoke(handle, new DataOutputStream(output));
|
||||||
|
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
@ -483,7 +486,7 @@ public class PacketContainer implements Serializable {
|
|||||||
|
|
||||||
// Call the read method
|
// Call the read method
|
||||||
try {
|
try {
|
||||||
getMethodLazily(readMethods, handle.getClass(), "read", DataInputStream.class).
|
getMethodLazily(readMethods, handle.getClass(), "read", DataInput.class).
|
||||||
invoke(handle, new DataInputStream(input));
|
invoke(handle, new DataInputStream(input));
|
||||||
|
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
@ -513,7 +516,12 @@ public class PacketContainer implements Serializable {
|
|||||||
|
|
||||||
// Atomic operation
|
// Atomic operation
|
||||||
if (method == null) {
|
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);
|
method = lookup.putIfAbsent(handleClass, initialized);
|
||||||
|
|
||||||
// Use our version if we succeeded
|
// Use our version if we succeeded
|
||||||
|
@ -21,6 +21,7 @@ import static org.junit.Assert.*;
|
|||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.SerializationUtils;
|
||||||
// Will have to be updated for every version though
|
// Will have to be updated for every version though
|
||||||
import org.bukkit.craftbukkit.v1_6_R2.inventory.CraftItemFactory;
|
import org.bukkit.craftbukkit.v1_6_R2.inventory.CraftItemFactory;
|
||||||
|
|
||||||
@ -305,6 +306,17 @@ public class PacketContainerTest {
|
|||||||
watchableAccessor.write(0, list);
|
watchableAccessor.write(0, list);
|
||||||
assertEquals(list, watchableAccessor.read(0));
|
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
|
@Test
|
||||||
public void testDeepClone() {
|
public void testDeepClone() {
|
||||||
|
Loading…
Reference in New Issue
Block a user