mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-11-19 00:55:32 +01:00
Fix some rare cases, where adding an item to inventory could result in an infinite loop.
This commit is contained in:
parent
20bc8840d6
commit
6371a59819
@ -43,6 +43,11 @@ public final class InventoryWorkaround
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int firstPartial(final Inventory cinventory, final ItemStack item, final boolean forceDurability)
|
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)
|
if (item == null)
|
||||||
{
|
{
|
||||||
@ -56,7 +61,7 @@ public final class InventoryWorkaround
|
|||||||
{
|
{
|
||||||
continue;
|
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;
|
return i;
|
||||||
}
|
}
|
||||||
@ -129,7 +134,8 @@ public final class InventoryWorkaround
|
|||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
// Do we already have a stack of it?
|
// 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
|
// Drat! no partial stack
|
||||||
if (firstPartial == -1)
|
if (firstPartial == -1)
|
||||||
@ -145,7 +151,6 @@ public final class InventoryWorkaround
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
final int maxAmount = oversizedStacks > 0 ? oversizedStacks : item.getType().getMaxStackSize();
|
|
||||||
// More than a single stack!
|
// More than a single stack!
|
||||||
if (item.getAmount() > maxAmount)
|
if (item.getAmount() > maxAmount)
|
||||||
{
|
{
|
||||||
@ -169,8 +174,7 @@ public final class InventoryWorkaround
|
|||||||
|
|
||||||
final int amount = item.getAmount();
|
final int amount = item.getAmount();
|
||||||
final int partialAmount = partialItem.getAmount();
|
final int partialAmount = partialItem.getAmount();
|
||||||
final int maxAmount = oversizedStacks > 0 ? oversizedStacks : partialItem.getType().getMaxStackSize();
|
|
||||||
|
|
||||||
// Check if it fully fits
|
// Check if it fully fits
|
||||||
if (amount + partialAmount <= maxAmount)
|
if (amount + partialAmount <= maxAmount)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user