Archiviert
13
0

Fix odd ArrayStoreException with MultiBlockChangeInfo

Also adapt test to test with arrays
Dieser Commit ist enthalten in:
Dan Mulloy 2015-06-15 13:54:34 -04:00
Ursprung 24d5b1739a
Commit 2c5b3a2a5b
2 geänderte Dateien mit 13 neuen und 9 gelöschten Zeilen

Datei anzeigen

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

Datei anzeigen

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