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.
This commit is contained in:
Wesley Wolfe 2012-12-29 20:53:27 -06:00
parent 8954cb291c
commit bb83795815

View File

@ -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));
}
}
handle.tag.set(ENCHANTMENTS.NBT, listCopy);
return level;
}