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:
Ursprung
35083f87fe
Commit
555b5d0795
@ -25,6 +25,7 @@ import java.io.IOException;
|
|||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.lang.reflect.Array;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -241,12 +242,12 @@ public class PacketContainer implements Serializable {
|
|||||||
BukkitConverters.getIgnoreNull(new EquivalentConverter<ItemStack[]>() {
|
BukkitConverters.getIgnoreNull(new EquivalentConverter<ItemStack[]>() {
|
||||||
|
|
||||||
public Object getGeneric(Class<?>genericType, ItemStack[] specific) {
|
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
|
// Unwrap every item
|
||||||
for (int i = 0; i < result.length; i++) {
|
for (int i = 0; i < result.length; i++) {
|
||||||
result[i] = stackConverter.getGeneric(
|
result[i] = stackConverter.getGeneric(nmsStack, specific[i]);
|
||||||
MinecraftReflection.getItemStackClass(), specific[i]);
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -314,12 +314,12 @@ public class MinecraftReflection {
|
|||||||
* @return The NetHandler class.
|
* @return The NetHandler class.
|
||||||
*/
|
*/
|
||||||
public static Class<?> getNetHandlerClass() {
|
public static Class<?> getNetHandlerClass() {
|
||||||
return getMinecraftClass("NetHandler");
|
return getMinecraftClass("NetHandler", "Connection");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the NetLoginHandler class.
|
* Retrieve the NMS ItemStack class.
|
||||||
* @return The NetLoginHandler class.
|
* @return The ItemStack class.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public static Class getItemStackClass() {
|
public static Class getItemStackClass() {
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren