Archiviert
13
0

Create a typed ItemStack array when writing it to a field. FIXES 24.

After the package versioning commit, ProtocolLib switched to performing
everything exclusively with reflection. Unfortunately, this may have
introduced a couple of new bugs.

This problem is caused by the fact that ProtocolLib converts a Bukkit
ItemStack array to an Object array instead of an array of NMS 
ItemStacks. This object array can't be assigned to a ItemStack array,
so the write operation fails.

The fix is to create a typed array with reflection.
Dieser Commit ist enthalten in:
Kristian S. Stangeland 2012-12-21 18:33:09 +01:00
Ursprung 35083f87fe
Commit 555b5d0795
2 geänderte Dateien mit 7 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -25,6 +25,7 @@ import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collection;
@ -241,12 +242,12 @@ public class PacketContainer implements Serializable {
BukkitConverters.getIgnoreNull(new EquivalentConverter<ItemStack[]>() {
public Object getGeneric(Class<?>genericType, ItemStack[] specific) {
Object[] result = new Object[specific.length];
Class<?> nmsStack = MinecraftReflection.getItemStackClass();
Object[] result = (Object[]) Array.newInstance(nmsStack, specific.length);
// Unwrap every item
for (int i = 0; i < result.length; i++) {
result[i] = stackConverter.getGeneric(
MinecraftReflection.getItemStackClass(), specific[i]);
result[i] = stackConverter.getGeneric(nmsStack, specific[i]);
}
return result;
}

Datei anzeigen

@ -314,12 +314,12 @@ public class MinecraftReflection {
* @return The NetHandler class.
*/
public static Class<?> getNetHandlerClass() {
return getMinecraftClass("NetHandler");
return getMinecraftClass("NetHandler", "Connection");
}
/**
* Retrieve the NetLoginHandler class.
* @return The NetLoginHandler class.
* Retrieve the NMS ItemStack class.
* @return The ItemStack class.
*/
@SuppressWarnings("rawtypes")
public static Class getItemStackClass() {