Archiviert
13
0

Ensure that non-CraftBukkit item stacks are correctly converted.

Dieser Commit ist enthalten in:
Kristian S. Stangeland 2012-10-09 16:48:55 +02:00
Ursprung 5e36547aa2
Commit 2b90acf53e

Datei anzeigen

@ -145,7 +145,7 @@ public class PacketContainer implements Serializable {
// Convert from and to the Bukkit wrapper // Convert from and to the Bukkit wrapper
return structureModifier.<ItemStack>withType(net.minecraft.server.ItemStack.class, new EquivalentConverter<ItemStack>() { return structureModifier.<ItemStack>withType(net.minecraft.server.ItemStack.class, new EquivalentConverter<ItemStack>() {
public Object getGeneric(ItemStack specific) { public Object getGeneric(ItemStack specific) {
return ((CraftItemStack) specific).getHandle(); return toStackNMS(specific);
} }
@Override @Override
@ -175,7 +175,7 @@ public class PacketContainer implements Serializable {
// Unwrap every item // Unwrap every item
for (int i = 0; i < result.length; i++) { for (int i = 0; i < result.length; i++) {
result[i] = ((CraftItemStack) specific[i]).getHandle(); result[i] = toStackNMS(specific[i]);
} }
return result; return result;
} }
@ -199,6 +199,20 @@ public class PacketContainer implements Serializable {
}); });
} }
/**
* Convert an item stack to the NMS equivalent.
* @param stack - Bukkit stack to convert.
* @return A bukkit stack.
*/
private net.minecraft.server.ItemStack toStackNMS(ItemStack stack) {
// We must be prepared for an object that simply implements ItemStcak
if (stack instanceof CraftItemStack) {
return ((CraftItemStack) stack).getHandle();
} else {
return (new CraftItemStack(stack)).getHandle();
}
}
/** /**
* Retrieves a read/write structure for the world type enum. * Retrieves a read/write structure for the world type enum.
* <p> * <p>