diff options
author | snowleo <schneeleo@gmail.com> | 2011-12-04 22:45:47 +0100 |
---|---|---|
committer | snowleo <schneeleo@gmail.com> | 2011-12-04 22:45:47 +0100 |
commit | 6371a59819d608d1add155e4fc59eeba93e14acc (patch) | |
tree | de446449d01bfedd3a41fa213866b9a87ad49103 | |
parent | 20bc8840d6c625a63bf862c617a5f17d78e34c3b (diff) | |
download | Essentials-6371a59819d608d1add155e4fc59eeba93e14acc.tar Essentials-6371a59819d608d1add155e4fc59eeba93e14acc.tar.gz Essentials-6371a59819d608d1add155e4fc59eeba93e14acc.tar.lz Essentials-6371a59819d608d1add155e4fc59eeba93e14acc.tar.xz Essentials-6371a59819d608d1add155e4fc59eeba93e14acc.zip |
Fix some rare cases, where adding an item to inventory could result in an infinite loop.
-rw-r--r-- | Essentials/src/com/earth2me/essentials/InventoryWorkaround.java | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/Essentials/src/com/earth2me/essentials/InventoryWorkaround.java b/Essentials/src/com/earth2me/essentials/InventoryWorkaround.java index 3ffda0ab3..5d020f08b 100644 --- a/Essentials/src/com/earth2me/essentials/InventoryWorkaround.java +++ b/Essentials/src/com/earth2me/essentials/InventoryWorkaround.java @@ -44,6 +44,11 @@ public final class InventoryWorkaround public static int firstPartial(final Inventory cinventory, final ItemStack item, final boolean forceDurability) { + return firstPartial(cinventory, item, forceDurability, item.getType().getMaxStackSize()); + } + + public static int firstPartial(final Inventory cinventory, final ItemStack item, final boolean forceDurability, final int maxAmount) + { if (item == null) { return -1; @@ -56,7 +61,7 @@ public final class InventoryWorkaround { continue; } - if (item.getTypeId() == cItem.getTypeId() && cItem.getAmount() < cItem.getType().getMaxStackSize() && (!forceDurability || cItem.getDurability() == item.getDurability()) && cItem.getEnchantments().equals(item.getEnchantments())) + if (item.getTypeId() == cItem.getTypeId() && cItem.getAmount() < maxAmount && (!forceDurability || cItem.getDurability() == item.getDurability()) && cItem.getEnchantments().equals(item.getEnchantments())) { return i; } @@ -129,7 +134,8 @@ public final class InventoryWorkaround while (true) { // Do we already have a stack of it? - final int firstPartial = firstPartial(cinventory, item, forceDurability); + final int maxAmount = oversizedStacks > item.getType().getMaxStackSize() ? oversizedStacks : item.getType().getMaxStackSize(); + final int firstPartial = firstPartial(cinventory, item, forceDurability, maxAmount); // Drat! no partial stack if (firstPartial == -1) @@ -145,7 +151,6 @@ public final class InventoryWorkaround } else { - final int maxAmount = oversizedStacks > 0 ? oversizedStacks : item.getType().getMaxStackSize(); // More than a single stack! if (item.getAmount() > maxAmount) { @@ -169,8 +174,7 @@ public final class InventoryWorkaround final int amount = item.getAmount(); final int partialAmount = partialItem.getAmount(); - final int maxAmount = oversizedStacks > 0 ? oversizedStacks : partialItem.getType().getMaxStackSize(); - + // Check if it fully fits if (amount + partialAmount <= maxAmount) { |