Ensure that non-CraftBukkit item stacks are correctly converted.

This commit is contained in:
Kristian S. Stangeland 2012-10-09 16:48:55 +02:00
parent 5e36547aa2
commit 2b90acf53e
1 changed files with 16 additions and 2 deletions

View File

@ -145,7 +145,7 @@ public class PacketContainer implements Serializable {
// Convert from and to the Bukkit wrapper
return structureModifier.<ItemStack>withType(net.minecraft.server.ItemStack.class, new EquivalentConverter<ItemStack>() {
public Object getGeneric(ItemStack specific) {
return ((CraftItemStack) specific).getHandle();
return toStackNMS(specific);
}
@Override
@ -175,7 +175,7 @@ public class PacketContainer implements Serializable {
// Unwrap every item
for (int i = 0; i < result.length; i++) {
result[i] = ((CraftItemStack) specific[i]).getHandle();
result[i] = toStackNMS(specific[i]);
}
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.
* <p>