From 2c5b3a2a5b38a72e58433c4463444567fedd5154 Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Mon, 15 Jun 2015 13:54:34 -0400 Subject: [PATCH] Fix odd ArrayStoreException with MultiBlockChangeInfo Also adapt test to test with arrays --- .../protocol/wrappers/MultiBlockChangeInfo.java | 7 ++++--- .../protocol/wrappers/MultiBlockChangeTest.java | 15 +++++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/MultiBlockChangeInfo.java b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/MultiBlockChangeInfo.java index f8724318..b46814f6 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/MultiBlockChangeInfo.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/MultiBlockChangeInfo.java @@ -35,6 +35,7 @@ import com.comphenix.protocol.utility.MinecraftReflection; public class MultiBlockChangeInfo { private static Constructor constructor; + private static Class nmsClass = MinecraftReflection.getMultiBlockChangeInfoClass(); private short location; private WrappedBlockData data; @@ -181,7 +182,7 @@ public class MultiBlockChangeInfo { public Object getGeneric(Class genericType, MultiBlockChangeInfo specific) { try { if (constructor == null) { - constructor = MinecraftReflection.getMultiBlockChangeInfoClass().getConstructor( + constructor = nmsClass.getConstructor( PacketType.Play.Server.MULTI_BLOCK_CHANGE.getPacketClass(), short.class, MinecraftReflection.getIBlockDataClass() @@ -224,11 +225,11 @@ public class MultiBlockChangeInfo { @Override public Object getGeneric(Class genericType, MultiBlockChangeInfo[] specific) { - Object[] result = (Object[]) Array.newInstance(genericType, specific.length); + Object[] result = (Object[]) Array.newInstance(nmsClass, specific.length); // Wrap every item for (int i = 0; i < result.length; i++) { - result[i] = converter.getGeneric(genericType, specific[i]); + result[i] = converter.getGeneric(nmsClass, specific[i]); } return result; diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/MultiBlockChangeTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/MultiBlockChangeTest.java index 3b259f3e..89b07e1a 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/MultiBlockChangeTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/MultiBlockChangeTest.java @@ -48,12 +48,15 @@ public class MultiBlockChangeTest { WrappedBlockData blockData = WrappedBlockData.createData(Material.STONE); MultiBlockChangeInfo info = new MultiBlockChangeInfo(location, blockData, chunk); - Object generic = MultiBlockChangeInfo.getConverter(chunk).getGeneric(MinecraftReflection.getMultiBlockChangeInfoClass(), info); - MultiBlockChangeInfo back = MultiBlockChangeInfo.getConverter(chunk).getSpecific(generic); + MultiBlockChangeInfo[] array = { info, info }; - assertEquals(info.getX(), back.getX()); - assertEquals(info.getY(), back.getY()); - assertEquals(info.getZ(), back.getZ()); - assertEquals(info.getData(), back.getData()); + Object generic = MultiBlockChangeInfo.getArrayConverter(chunk).getGeneric(MinecraftReflection.getMultiBlockChangeInfoArrayClass(), + array); + MultiBlockChangeInfo[] back = MultiBlockChangeInfo.getArrayConverter(chunk).getSpecific(generic); + + assertEquals(info.getX(), back[0].getX()); + assertEquals(info.getY(), back[0].getY()); + assertEquals(info.getZ(), back[0].getZ()); + assertEquals(info.getData(), back[0].getData()); } } \ No newline at end of file