mirror of
https://github.com/essentials/Essentials.git
synced 2025-08-20 13:31:25 +02:00
@@ -26,7 +26,7 @@ public class Commandhat extends EssentialsCommand
|
|||||||
{
|
{
|
||||||
final ItemStack air = new ItemStack(Material.AIR);
|
final ItemStack air = new ItemStack(Material.AIR);
|
||||||
inv.setHelmet(air);
|
inv.setHelmet(air);
|
||||||
InventoryWorkaround.addItem(user.getPlayer().getInventory(), true, head);
|
InventoryWorkaround.addItems(user.getPlayer().getInventory(), head);
|
||||||
user.sendMessage(_("hatRemoved"));
|
user.sendMessage(_("hatRemoved"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -41,7 +41,7 @@ public class Commandhat extends EssentialsCommand
|
|||||||
final PlayerInventory inv = player.getInventory();
|
final PlayerInventory inv = player.getInventory();
|
||||||
final ItemStack head = inv.getHelmet();
|
final ItemStack head = inv.getHelmet();
|
||||||
hand.setAmount(1);
|
hand.setAmount(1);
|
||||||
InventoryWorkaround.removeItem(inv, true, true, hand);
|
inv.remove(hand);
|
||||||
inv.setHelmet(hand);
|
inv.setHelmet(hand);
|
||||||
inv.setItemInHand(head);
|
inv.setItemInHand(head);
|
||||||
user.sendMessage(_("hatPlaced"));
|
user.sendMessage(_("hatPlaced"));
|
||||||
|
@@ -7,7 +7,6 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import net.ess3.api.IUser;
|
import net.ess3.api.IUser;
|
||||||
import net.ess3.craftbukkit.InventoryWorkaround;
|
|
||||||
import net.ess3.economy.Trade;
|
import net.ess3.economy.Trade;
|
||||||
import net.ess3.utils.FormatUtil;
|
import net.ess3.utils.FormatUtil;
|
||||||
|
|
||||||
@@ -143,7 +142,7 @@ public class Commandsell extends EssentialsCommand
|
|||||||
//TODO: Prices for Enchantments
|
//TODO: Prices for Enchantments
|
||||||
final ItemStack ris = is.clone();
|
final ItemStack ris = is.clone();
|
||||||
ris.setAmount(amount);
|
ris.setAmount(amount);
|
||||||
InventoryWorkaround.removeItem(player.getInventory(), true, true, ris);
|
player.getInventory().removeItem(ris);
|
||||||
player.updateInventory();
|
player.updateInventory();
|
||||||
Trade.log("Command", "Sell", "Item", user.getName(), new Trade(ris, ess), user.getName(), new Trade(worth * amount, ess), player.getLocation(), ess);
|
Trade.log("Command", "Sell", "Item", user.getName(), new Trade(ris, ess), user.getName(), new Trade(worth * amount, ess), player.getLocation(), ess);
|
||||||
user.giveMoney(worth * amount);
|
user.giveMoney(worth * amount);
|
||||||
|
@@ -1,249 +0,0 @@
|
|||||||
package net.ess3.craftbukkit;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.ListIterator;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
|
||||||
import org.bukkit.event.inventory.InventoryType;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
import org.bukkit.inventory.InventoryHolder;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
|
|
||||||
public class FakeInventory implements Inventory
|
|
||||||
{
|
|
||||||
ItemStack[] items;
|
|
||||||
|
|
||||||
public FakeInventory(ItemStack[] items)
|
|
||||||
{
|
|
||||||
this.items = new ItemStack[items.length];
|
|
||||||
for (int i = 0; i < items.length; i++)
|
|
||||||
{
|
|
||||||
if (items[i] == null)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
this.items[i] = items[i].clone();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSize()
|
|
||||||
{
|
|
||||||
return items.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName()
|
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack getItem(int i)
|
|
||||||
{
|
|
||||||
return items[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setItem(int i, ItemStack is)
|
|
||||||
{
|
|
||||||
items[i] = is;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public HashMap<Integer, ItemStack> addItem(ItemStack... iss)
|
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public HashMap<Integer, ItemStack> removeItem(ItemStack... iss)
|
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack[] getContents()
|
|
||||||
{
|
|
||||||
return items;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setContents(ItemStack[] iss)
|
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean contains(int i)
|
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean contains(Material mtrl)
|
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean contains(ItemStack is)
|
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean contains(int i, int i1)
|
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean contains(Material mtrl, int i)
|
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean contains(ItemStack is, int i)
|
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public HashMap<Integer, ? extends ItemStack> all(int i)
|
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public HashMap<Integer, ? extends ItemStack> all(Material mtrl)
|
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public HashMap<Integer, ? extends ItemStack> all(ItemStack is)
|
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int first(int i)
|
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int first(Material mtrl)
|
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int first(ItemStack is)
|
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int firstEmpty()
|
|
||||||
{
|
|
||||||
for (int i = 0; i < items.length; i++)
|
|
||||||
{
|
|
||||||
if (items[i] == null || items[i].getTypeId() == 0)
|
|
||||||
{
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void remove(int i)
|
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void remove(Material mtrl)
|
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void remove(ItemStack is)
|
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clear(int i)
|
|
||||||
{
|
|
||||||
items[i] = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clear()
|
|
||||||
{
|
|
||||||
for (int i = 0; i < items.length; i++)
|
|
||||||
{
|
|
||||||
items[i] = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<HumanEntity> getViewers()
|
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getTitle()
|
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public InventoryType getType()
|
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public InventoryHolder getHolder()
|
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ListIterator<ItemStack> iterator()
|
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMaxStackSize()
|
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setMaxStackSize(int size)
|
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ListIterator<ItemStack> iterator(int index)
|
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean containsAtLeast(ItemStack arg0, int arg1)
|
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
|
||||||
}
|
|
||||||
}
|
|
@@ -2,6 +2,7 @@ package net.ess3.craftbukkit;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
@@ -16,51 +17,17 @@ public final class InventoryWorkaround
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int first(final Inventory inventory, final ItemStack item, final boolean enforceDurability, final boolean enforceAmount, final boolean enforceEnchantments)
|
public static int firstPartial(final Inventory inventory, final ItemStack item, final int maxAmount)
|
||||||
{
|
|
||||||
return next(inventory, item, 0, enforceDurability, enforceAmount, enforceEnchantments);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int next(final Inventory cinventory, final ItemStack item, final int start, final boolean enforceDurability, final boolean enforceAmount, final boolean enforceEnchantments)
|
|
||||||
{
|
|
||||||
final ItemStack[] inventory = cinventory.getContents();
|
|
||||||
for (int i = start; i < inventory.length; i++)
|
|
||||||
{
|
|
||||||
final ItemStack cItem = inventory[i];
|
|
||||||
if (cItem == null)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (item.getTypeId() == cItem.getTypeId() && (!enforceAmount || item.getAmount() == cItem.getAmount()) && (!enforceDurability || cItem.getDurability() == item.getDurability()) && (!enforceEnchantments || cItem.getEnchantments().equals(
|
|
||||||
item.getEnchantments())))
|
|
||||||
{
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int firstPartial(final Inventory cinventory, final ItemStack item, final boolean enforceDurability)
|
|
||||||
{
|
|
||||||
return firstPartial(cinventory, item, enforceDurability, item.getType().getMaxStackSize());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int firstPartial(final Inventory cinventory, final ItemStack item, final boolean enforceDurability, final int maxAmount)
|
|
||||||
{
|
{
|
||||||
if (item == null)
|
if (item == null)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
final ItemStack[] inventory = cinventory.getContents();
|
final ItemStack[] stacks = inventory.getContents();
|
||||||
for (int i = 0; i < inventory.length; i++)
|
for (int i = 0; i < stacks.length; i++)
|
||||||
{
|
{
|
||||||
final ItemStack cItem = inventory[i];
|
final ItemStack cItem = stacks[i];
|
||||||
if (cItem == null)
|
if(cItem != null && cItem.getAmount() < maxAmount && cItem.isSimilar(item))
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (item.getTypeId() == cItem.getTypeId() && cItem.getAmount() < maxAmount && (!enforceDurability || cItem.getDurability() == item.getDurability()) && cItem.getEnchantments().equals(
|
|
||||||
item.getEnchantments()))
|
|
||||||
{
|
{
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
@@ -68,26 +35,24 @@ public final class InventoryWorkaround
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean addAllItems(final Inventory cinventory, final boolean enforceDurability, final ItemStack... items)
|
public static boolean addAllItems(final Inventory inventory, final ItemStack... items)
|
||||||
{
|
{
|
||||||
final Inventory fake = new FakeInventory(cinventory.getContents());
|
final Inventory fakeInventory = Bukkit.getServer().createInventory(null, inventory.getType());
|
||||||
if (addItem(fake, enforceDurability, items).isEmpty())
|
fakeInventory.setContents(inventory.getContents());
|
||||||
|
if (fakeInventory.addItem(items).isEmpty())
|
||||||
{
|
{
|
||||||
addItem(cinventory, enforceDurability, items);
|
inventory.addItem(items);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
return false;
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<Integer, ItemStack> addItem(final Inventory cinventory, final boolean forceDurability, final ItemStack... items)
|
public static Map<Integer, ItemStack> addItems(final Inventory inventory, final ItemStack... items)
|
||||||
{
|
{
|
||||||
return addItem(cinventory, forceDurability, 0, items);
|
return addOversizedItems(inventory, 0, items);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<Integer, ItemStack> addItem(final Inventory cinventory, final boolean enforceDurability, final int oversizedStacks, final ItemStack... items)
|
public static Map<Integer, ItemStack> addOversizedItems(final Inventory inventory, final int oversizedStacks, final ItemStack... items)
|
||||||
{
|
{
|
||||||
final Map<Integer, ItemStack> leftover = new HashMap<Integer, ItemStack>();
|
final Map<Integer, ItemStack> leftover = new HashMap<Integer, ItemStack>();
|
||||||
|
|
||||||
@@ -112,8 +77,7 @@ public final class InventoryWorkaround
|
|||||||
combined[j] = items[i].clone();
|
combined[j] = items[i].clone();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (combined[j].getTypeId() == items[i].getTypeId() && (!enforceDurability || combined[j].getDurability() == items[i].getDurability()) && combined[j].getEnchantments().equals(
|
if (combined[j].isSimilar(items[i]))
|
||||||
items[i].getEnchantments()))
|
|
||||||
{
|
{
|
||||||
combined[j].setAmount(combined[j].getAmount() + items[i].getAmount());
|
combined[j].setAmount(combined[j].getAmount() + items[i].getAmount());
|
||||||
break;
|
break;
|
||||||
@@ -134,13 +98,13 @@ public final class InventoryWorkaround
|
|||||||
{
|
{
|
||||||
// Do we already have a stack of it?
|
// Do we already have a stack of it?
|
||||||
final int maxAmount = oversizedStacks > item.getType().getMaxStackSize() ? oversizedStacks : item.getType().getMaxStackSize();
|
final int maxAmount = oversizedStacks > item.getType().getMaxStackSize() ? oversizedStacks : item.getType().getMaxStackSize();
|
||||||
final int firstPartial = firstPartial(cinventory, item, enforceDurability, maxAmount);
|
final int firstPartial = firstPartial(inventory, item, maxAmount);
|
||||||
|
|
||||||
// Drat! no partial stack
|
// Drat! no partial stack
|
||||||
if (firstPartial == -1)
|
if (firstPartial == -1)
|
||||||
{
|
{
|
||||||
// Find a free spot!
|
// Find a free spot!
|
||||||
final int firstFree = cinventory.firstEmpty();
|
final int firstFree = inventory.firstEmpty();
|
||||||
|
|
||||||
if (firstFree == -1)
|
if (firstFree == -1)
|
||||||
{
|
{
|
||||||
@@ -155,13 +119,13 @@ public final class InventoryWorkaround
|
|||||||
{
|
{
|
||||||
final ItemStack stack = item.clone();
|
final ItemStack stack = item.clone();
|
||||||
stack.setAmount(maxAmount);
|
stack.setAmount(maxAmount);
|
||||||
cinventory.setItem(firstFree, stack);
|
inventory.setItem(firstFree, stack);
|
||||||
item.setAmount(item.getAmount() - maxAmount);
|
item.setAmount(item.getAmount() - maxAmount);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Just store it
|
// Just store it
|
||||||
cinventory.setItem(firstFree, item);
|
inventory.setItem(firstFree, item);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -169,7 +133,7 @@ public final class InventoryWorkaround
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// So, apparently it might only partially fit, well lets do just that
|
// So, apparently it might only partially fit, well lets do just that
|
||||||
final ItemStack partialItem = cinventory.getItem(firstPartial);
|
final ItemStack partialItem = inventory.getItem(firstPartial);
|
||||||
|
|
||||||
final int amount = item.getAmount();
|
final int amount = item.getAmount();
|
||||||
final int partialAmount = partialItem.getAmount();
|
final int partialAmount = partialItem.getAmount();
|
||||||
@@ -189,139 +153,4 @@ public final class InventoryWorkaround
|
|||||||
}
|
}
|
||||||
return leftover;
|
return leftover;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<Integer, ItemStack> removeItem(final Inventory cinventory, final boolean enforceDurability, final boolean enforceEnchantments, final ItemStack... items)
|
|
||||||
{
|
|
||||||
final Map<Integer, ItemStack> leftover = new HashMap<Integer, ItemStack>();
|
|
||||||
|
|
||||||
// TODO: optimization
|
|
||||||
|
|
||||||
for (int i = 0; i < items.length; i++)
|
|
||||||
{
|
|
||||||
final ItemStack item = items[i];
|
|
||||||
if (item == null)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
int toDelete = item.getAmount();
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
|
|
||||||
// Bail when done
|
|
||||||
if (toDelete <= 0)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// get first Item, ignore the amount
|
|
||||||
final int first = first(cinventory, item, enforceDurability, false, enforceEnchantments);
|
|
||||||
|
|
||||||
// Drat! we don't have this type in the inventory
|
|
||||||
if (first == -1)
|
|
||||||
{
|
|
||||||
item.setAmount(toDelete);
|
|
||||||
leftover.put(i, item);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
final ItemStack itemStack = cinventory.getItem(first);
|
|
||||||
final int amount = itemStack.getAmount();
|
|
||||||
|
|
||||||
if (amount <= toDelete)
|
|
||||||
{
|
|
||||||
toDelete -= amount;
|
|
||||||
// clear the slot, all used up
|
|
||||||
cinventory.clear(first);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// split the stack and store
|
|
||||||
itemStack.setAmount(amount - toDelete);
|
|
||||||
cinventory.setItem(first, itemStack);
|
|
||||||
toDelete = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return leftover;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean containsItem(final Inventory cinventory, final boolean enforceDurability, final boolean enforceEnchantments, final ItemStack... items)
|
|
||||||
{
|
|
||||||
final Map<Integer, ItemStack> leftover = new HashMap<Integer, ItemStack>();
|
|
||||||
|
|
||||||
// TODO: optimization
|
|
||||||
|
|
||||||
// combine items
|
|
||||||
|
|
||||||
ItemStack[] combined = new ItemStack[items.length];
|
|
||||||
for (int i = 0; i < items.length; i++)
|
|
||||||
{
|
|
||||||
if (items[i] == null)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
for (int j = 0; j < combined.length; j++)
|
|
||||||
{
|
|
||||||
if (combined[j] == null)
|
|
||||||
{
|
|
||||||
combined[j] = items[i].clone();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (combined[j].getTypeId() == items[i].getTypeId() && (!enforceDurability || combined[j].getDurability() == items[i].getDurability()) && (!enforceEnchantments || combined[j].getEnchantments().equals(
|
|
||||||
items[i].getEnchantments())))
|
|
||||||
{
|
|
||||||
combined[j].setAmount(combined[j].getAmount() + items[i].getAmount());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < combined.length; i++)
|
|
||||||
{
|
|
||||||
final ItemStack item = combined[i];
|
|
||||||
if (item == null)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
int mustHave = item.getAmount();
|
|
||||||
int position = 0;
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
// Bail when done
|
|
||||||
if (mustHave <= 0)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
final int slot = next(cinventory, item, position, enforceDurability, false, enforceEnchantments);
|
|
||||||
|
|
||||||
// Drat! we don't have this type in the inventory
|
|
||||||
if (slot == -1)
|
|
||||||
{
|
|
||||||
leftover.put(i, item);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
final ItemStack itemStack = cinventory.getItem(slot);
|
|
||||||
final int amount = itemStack.getAmount();
|
|
||||||
|
|
||||||
if (amount <= mustHave)
|
|
||||||
{
|
|
||||||
mustHave -= amount;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mustHave = 0;
|
|
||||||
}
|
|
||||||
position = slot + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return leftover.isEmpty();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -71,7 +71,7 @@ public class Trade
|
|||||||
throw new ChargeException(_("notEnoughMoney"));
|
throw new ChargeException(_("notEnoughMoney"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getItemStack() != null && InventoryWorkaround.containsItem(user.getPlayer().getInventory(), true, true, itemStack))
|
if (getItemStack() != null && !user.getPlayer().getInventory().containsAtLeast(itemStack, itemStack.getAmount()))
|
||||||
{
|
{
|
||||||
throw new ChargeException(
|
throw new ChargeException(
|
||||||
_("missingItems", getItemStack().getAmount(), getItemStack().getType().toString().toLowerCase(Locale.ENGLISH).replace("_", " ")));
|
_("missingItems", getItemStack().getAmount(), getItemStack().getType().toString().toLowerCase(Locale.ENGLISH).replace("_", " ")));
|
||||||
@@ -105,7 +105,7 @@ public class Trade
|
|||||||
{
|
{
|
||||||
if (dropItems)
|
if (dropItems)
|
||||||
{
|
{
|
||||||
final Map<Integer, ItemStack> leftOver = InventoryWorkaround.addItem(user.getPlayer().getInventory(), true, getItemStack());
|
final Map<Integer, ItemStack> leftOver = InventoryWorkaround.addItems(user.getPlayer().getInventory(), getItemStack());
|
||||||
final Location loc = user.getPlayer().getLocation();
|
final Location loc = user.getPlayer().getLocation();
|
||||||
for (ItemStack dropStack : leftOver.values())
|
for (ItemStack dropStack : leftOver.values())
|
||||||
{
|
{
|
||||||
@@ -129,7 +129,7 @@ public class Trade
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
success = InventoryWorkaround.addAllItems(user.getPlayer().getInventory(), true, getItemStack());
|
success = InventoryWorkaround.addAllItems(user.getPlayer().getInventory(), getItemStack());
|
||||||
}
|
}
|
||||||
user.getPlayer().updateInventory();
|
user.getPlayer().updateInventory();
|
||||||
}
|
}
|
||||||
@@ -152,12 +152,12 @@ public class Trade
|
|||||||
}
|
}
|
||||||
if (getItemStack() != null)
|
if (getItemStack() != null)
|
||||||
{
|
{
|
||||||
if (!InventoryWorkaround.containsItem(user.getPlayer().getInventory(), true, true, itemStack))
|
if (!user.getPlayer().getInventory().containsAtLeast(itemStack, itemStack.getAmount()))
|
||||||
{
|
{
|
||||||
throw new ChargeException(
|
throw new ChargeException(
|
||||||
_("missingItems", getItemStack().getAmount(), getItemStack().getType().toString().toLowerCase(Locale.ENGLISH).replace("_", " ")));
|
_("missingItems", getItemStack().getAmount(), getItemStack().getType().toString().toLowerCase(Locale.ENGLISH).replace("_", " ")));
|
||||||
}
|
}
|
||||||
InventoryWorkaround.removeItem(user.getPlayer().getInventory(), true, true, getItemStack());
|
user.getPlayer().getInventory().removeItem(getItemStack());
|
||||||
user.getPlayer().updateInventory();
|
user.getPlayer().updateInventory();
|
||||||
}
|
}
|
||||||
if (command != null && !command.isEmpty() && !Permissions.NOCOMMANDCOST.isAuthorized(user, command))
|
if (command != null && !command.isEmpty() && !Permissions.NOCOMMANDCOST.isAuthorized(user, command))
|
||||||
|
Reference in New Issue
Block a user