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 { public class MultiBlockChangeInfo {
private static Constructor<?> constructor; private static Constructor<?> constructor;
private static Class<?> nmsClass = MinecraftReflection.getMultiBlockChangeInfoClass();
private short location; private short location;
private WrappedBlockData data; private WrappedBlockData data;
@ -181,7 +182,7 @@ public class MultiBlockChangeInfo {
public Object getGeneric(Class<?> genericType, MultiBlockChangeInfo specific) { public Object getGeneric(Class<?> genericType, MultiBlockChangeInfo specific) {
try { try {
if (constructor == null) { if (constructor == null) {
constructor = MinecraftReflection.getMultiBlockChangeInfoClass().getConstructor( constructor = nmsClass.getConstructor(
PacketType.Play.Server.MULTI_BLOCK_CHANGE.getPacketClass(), PacketType.Play.Server.MULTI_BLOCK_CHANGE.getPacketClass(),
short.class, short.class,
MinecraftReflection.getIBlockDataClass() MinecraftReflection.getIBlockDataClass()
@ -224,11 +225,11 @@ public class MultiBlockChangeInfo {
@Override @Override
public Object getGeneric(Class<?> genericType, MultiBlockChangeInfo[] specific) { 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 // Wrap every item
for (int i = 0; i < result.length; i++) { for (int i = 0; i < result.length; i++) {
result[i] = converter.getGeneric(genericType, specific[i]); result[i] = converter.getGeneric(nmsClass, specific[i]);
} }
return result; return result;

Datei anzeigen

@ -48,12 +48,15 @@ public class MultiBlockChangeTest {
WrappedBlockData blockData = WrappedBlockData.createData(Material.STONE); WrappedBlockData blockData = WrappedBlockData.createData(Material.STONE);
MultiBlockChangeInfo info = new MultiBlockChangeInfo(location, blockData, chunk); MultiBlockChangeInfo info = new MultiBlockChangeInfo(location, blockData, chunk);
Object generic = MultiBlockChangeInfo.getConverter(chunk).getGeneric(MinecraftReflection.getMultiBlockChangeInfoClass(), info); MultiBlockChangeInfo[] array = { info, info };
MultiBlockChangeInfo back = MultiBlockChangeInfo.getConverter(chunk).getSpecific(generic);
assertEquals(info.getX(), back.getX()); Object generic = MultiBlockChangeInfo.getArrayConverter(chunk).getGeneric(MinecraftReflection.getMultiBlockChangeInfoArrayClass(),
assertEquals(info.getY(), back.getY()); array);
assertEquals(info.getZ(), back.getZ()); MultiBlockChangeInfo[] back = MultiBlockChangeInfo.getArrayConverter(chunk).getSpecific(generic);
assertEquals(info.getData(), back.getData());
assertEquals(info.getX(), back[0].getX());
assertEquals(info.getY(), back[0].getY());
assertEquals(info.getZ(), back[0].getZ());
assertEquals(info.getData(), back[0].getData());
} }
} }