diff options
author | Wesley Wolfe <weswolf@aol.com> | 2012-12-17 15:53:25 -0600 |
---|---|---|
committer | Wesley Wolfe <weswolf@aol.com> | 2012-12-17 16:43:16 -0600 |
commit | 6cec8ba5cb2d69366df92e602c48e963eb9e3076 (patch) | |
tree | 149ce8ba24d71039c28607b3b46829b6ee44472d | |
parent | d66d3674ea12bef35f1e41391f5132f0b03b8a6e (diff) | |
download | craftbukkit-6cec8ba5cb2d69366df92e602c48e963eb9e3076.tar craftbukkit-6cec8ba5cb2d69366df92e602c48e963eb9e3076.tar.gz craftbukkit-6cec8ba5cb2d69366df92e602c48e963eb9e3076.tar.lz craftbukkit-6cec8ba5cb2d69366df92e602c48e963eb9e3076.tar.xz craftbukkit-6cec8ba5cb2d69366df92e602c48e963eb9e3076.zip |
Change enchantment comparisons to isSimilar. Fixes BUKKIT-3183
The purpose of the isSimilar method was designed to consider all NBT
data, not solely enchantments, without the need to have exact stack
size matches. The respective methods in CraftInventory were still
comparing enchantments instead of the ItemMeta.
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java | 14 |
1 files changed, 3 insertions, 11 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java index 7342179d..280a2a5f 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java @@ -147,7 +147,7 @@ public class CraftInventory implements Inventory { return true; } for (ItemStack i : getContents()) { - if (i != null && item.getTypeId() == i.getTypeId() && item.getDurability() == i.getDurability() && item.getEnchantments().equals(i.getEnchantments()) && (amount -= i.getAmount()) <= 0) { + if (item.isSimilar(i) && (amount -= i.getAmount()) <= 0) { return true; } } @@ -213,15 +213,7 @@ public class CraftInventory implements Inventory { for (int i = 0; i < inventory.length; i++) { if (inventory[i] == null) continue; - boolean equals = false; - - if (withAmount) { - equals = item.equals(inventory[i]); - } else { - equals = item.getTypeId() == inventory[i].getTypeId() && item.getDurability() == inventory[i].getDurability() && item.getEnchantments().equals(inventory[i].getEnchantments()); - } - - if (equals) { + if (withAmount ? item.equals(inventory[i]) : item.isSimilar(inventory[i])) { return i; } } @@ -262,7 +254,7 @@ public class CraftInventory implements Inventory { } for (int i = 0; i < inventory.length; i++) { ItemStack cItem = inventory[i]; - if (cItem != null && cItem.getTypeId() == filteredItem.getTypeId() && cItem.getAmount() < cItem.getMaxStackSize() && cItem.getDurability() == filteredItem.getDurability() && cItem.getEnchantments().equals(filteredItem.getEnchantments())) { + if (cItem != null && cItem.getAmount() < cItem.getMaxStackSize() && cItem.isSimilar(filteredItem)) { return i; } } |