diff options
author | Wesley Wolfe <weswolf@aol.com> | 2012-12-29 20:53:27 -0600 |
---|---|---|
committer | Wesley Wolfe <weswolf@aol.com> | 2012-12-29 20:53:27 -0600 |
commit | bb83795815377f0224c9c13422c8631d2427d4d8 (patch) | |
tree | 6b0704104efd0afef4badd1360822b590040b6e9 /src | |
parent | 8954cb291caa65bfa26377082c8563be0cf0855e (diff) | |
download | craftbukkit-bb83795815377f0224c9c13422c8631d2427d4d8.tar craftbukkit-bb83795815377f0224c9c13422c8631d2427d4d8.tar.gz craftbukkit-bb83795815377f0224c9c13422c8631d2427d4d8.tar.lz craftbukkit-bb83795815377f0224c9c13422c8631d2427d4d8.tar.xz craftbukkit-bb83795815377f0224c9c13422c8631d2427d4d8.zip |
Return the level, not ID. Fixes BUKKIT-3326
CraftItemStack was erroneously using the enchantment ID instead of level
for the return value of remove enchantment.
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java index 5110b6ca..85835ca7 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java @@ -220,12 +220,16 @@ public final class CraftItemStack extends ItemStack { if (list == null) { return 0; } - int index = Integer.MIN_VALUE, size = list.size(), level; + int index = Integer.MIN_VALUE; + int level = Integer.MIN_VALUE; + int size = list.size(); for (int i = 0; i < size; i++) { - short id = ((NBTTagCompound) list.get(i)).getShort(ENCHANTMENTS_ID.NBT); + NBTTagCompound enchantment = (NBTTagCompound) list.get(i); + int id = 0xffff & enchantment.getShort(ENCHANTMENTS_ID.NBT); if (id == ench.getId()) { index = i; + level = 0xffff & enchantment.getShort(ENCHANTMENTS_LVL.NBT); break; } } @@ -233,24 +237,23 @@ public final class CraftItemStack extends ItemStack { if (index == Integer.MIN_VALUE) { return 0; } - if (index == 0 && size == 1) { + if (size == 1) { handle.tag.o(ENCHANTMENTS.NBT); if (handle.tag.d()) { handle.tag = null; } - return ((NBTTagCompound) list.get(0)).getShort(ENCHANTMENTS_ID.NBT); + return level; } + // This is workaround for not having an index removal listCopy = new NBTTagList(ENCHANTMENTS.NBT); - level = Integer.MAX_VALUE; for (int i = 0; i < size; i++) { - if (i == index) { - level = ((NBTTagCompound) list.get(i)).getShort(ENCHANTMENTS_ID.NBT); - continue; + if (i != index) { + listCopy.add(list.get(i)); } - listCopy.add(list.get(i)); } handle.tag.set(ENCHANTMENTS.NBT, listCopy); + return level; } |