Fix odd ArrayStoreException with MultiBlockChangeInfo

Also adapt test to test with arrays
This commit is contained in:
Dan Mulloy 2015-06-15 13:54:34 -04:00
parent 24d5b1739a
commit 2c5b3a2a5b
2 changed files with 13 additions and 9 deletions

View File

@ -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;

View File

@ -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());
}
}