summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormd_5 <md_5@bigpond.com>2012-02-15 17:18:12 +1100
committermd_5 <md_5@bigpond.com>2012-02-15 17:21:28 +1100
commitd05f2d7a32058ea0b877786fffb5dff4c00e3879 (patch)
tree8cd332c8941a37409e9e6ad79dacc16f1e40e68f
parentf0c0ee1a8dd90de1524032e92c65df5e823a7b1f (diff)
downloadEssentials-d05f2d7a32058ea0b877786fffb5dff4c00e3879.tar
Essentials-d05f2d7a32058ea0b877786fffb5dff4c00e3879.tar.gz
Essentials-d05f2d7a32058ea0b877786fffb5dff4c00e3879.tar.lz
Essentials-d05f2d7a32058ea0b877786fffb5dff4c00e3879.tar.xz
Essentials-d05f2d7a32058ea0b877786fffb5dff4c00e3879.zip
Remove dropItems from the inventory work around
-rw-r--r--Essentials/src/com/earth2me/essentials/Trade.java30
-rw-r--r--Essentials/src/com/earth2me/essentials/craftbukkit/InventoryWorkaround.java39
2 files changed, 30 insertions, 39 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Trade.java b/Essentials/src/com/earth2me/essentials/Trade.java
index 6cd9ce93a..933b54b3f 100644
--- a/Essentials/src/com/earth2me/essentials/Trade.java
+++ b/Essentials/src/com/earth2me/essentials/Trade.java
@@ -13,6 +13,7 @@ import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.Location;
+import org.bukkit.entity.Item;
import org.bukkit.inventory.ItemStack;
@@ -38,7 +39,7 @@ public class Trade
{
this(null, null, items, null, ess);
}
-
+
public Trade(final int exp, final IEssentials ess)
{
this(null, null, null, exp, ess);
@@ -79,9 +80,10 @@ public class Trade
{
throw new ChargeException(_("notEnoughMoney"));
}
-
- if (exp != null && exp > 0
- && SetExpFix.getTotalExperience(user) < exp) {
+
+ if (exp != null && exp > 0
+ && SetExpFix.getTotalExperience(user) < exp)
+ {
throw new ChargeException(_("notEnoughExperience"));
}
}
@@ -103,9 +105,25 @@ public class Trade
if (dropItems)
{
final Map<Integer, ItemStack> leftOver = InventoryWorkaround.addItem(user.getInventory(), true, getItemStack());
+ final Location loc = user.getLocation();
for (ItemStack itemStack : leftOver.values())
{
- InventoryWorkaround.dropItem(user.getLocation(), itemStack);
+ final int maxStackSize = itemStack.getType().getMaxStackSize();
+ final int stacks = itemStack.getAmount() / maxStackSize;
+ final int leftover = itemStack.getAmount() % maxStackSize;
+ final Item[] itemStacks = new Item[stacks + (leftover > 0 ? 1 : 0)];
+ for (int i = 0; i < stacks; i++)
+ {
+ final ItemStack stack = itemStack.clone();
+ stack.setAmount(maxStackSize);
+ itemStacks[i] = loc.getWorld().dropItem(loc, stack);
+ }
+ if (leftover > 0)
+ {
+ final ItemStack stack = itemStack.clone();
+ stack.setAmount(leftover);
+ itemStacks[stacks] = loc.getWorld().dropItem(loc, stack);
+ }
}
}
else
@@ -173,7 +191,7 @@ public class Trade
{
return itemStack;
}
-
+
public Integer getExperience()
{
return exp;
diff --git a/Essentials/src/com/earth2me/essentials/craftbukkit/InventoryWorkaround.java b/Essentials/src/com/earth2me/essentials/craftbukkit/InventoryWorkaround.java
index 308568452..a6d5d4fbc 100644
--- a/Essentials/src/com/earth2me/essentials/craftbukkit/InventoryWorkaround.java
+++ b/Essentials/src/com/earth2me/essentials/craftbukkit/InventoryWorkaround.java
@@ -1,17 +1,12 @@
package com.earth2me.essentials.craftbukkit;
-import com.earth2me.essentials.craftbukkit.FakeInventory;
import java.util.HashMap;
import java.util.Map;
-import org.bukkit.Location;
-import org.bukkit.entity.Item;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
/*
- * This class can be removed when
- * https://github.com/Bukkit/CraftBukkit/pull/193
- * is accepted to CraftBukkit
+ * This class can be removed when https://github.com/Bukkit/CraftBukkit/pull/193 is accepted to CraftBukkit
*/
public final class InventoryWorkaround
@@ -47,7 +42,7 @@ public final class InventoryWorkaround
{
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)
@@ -93,10 +88,9 @@ public final class InventoryWorkaround
{
final Map<Integer, ItemStack> leftover = new HashMap<Integer, ItemStack>();
- /* TODO: some optimization
- * - Create a 'firstPartial' with a 'fromIndex'
- * - Record the lastPartial per Material
- * - Cache firstEmpty result
+ /*
+ * TODO: some optimization - Create a 'firstPartial' with a 'fromIndex' - Record the lastPartial per Material -
+ * Cache firstEmpty result
*/
// combine items
@@ -175,7 +169,7 @@ public final class InventoryWorkaround
final int amount = item.getAmount();
final int partialAmount = partialItem.getAmount();
-
+
// Check if it fully fits
if (amount + partialAmount <= maxAmount)
{
@@ -325,25 +319,4 @@ public final class InventoryWorkaround
}
return leftover.isEmpty();
}
-
- public static Item[] dropItem(final Location loc, final ItemStack itm)
- {
- final int maxStackSize = itm.getType().getMaxStackSize();
- final int stacks = itm.getAmount() / maxStackSize;
- final int leftover = itm.getAmount() % maxStackSize;
- final Item[] itemStacks = new Item[stacks + (leftover > 0 ? 1 : 0)];
- for (int i = 0; i < stacks; i++)
- {
- final ItemStack stack = itm.clone();
- stack.setAmount(maxStackSize);
- itemStacks[i] = loc.getWorld().dropItem(loc, stack);
- }
- if (leftover > 0)
- {
- final ItemStack stack = itm.clone();
- stack.setAmount(leftover);
- itemStacks[stacks] = loc.getWorld().dropItem(loc, stack);
- }
- return itemStacks;
- }
}