From 6bf705dd0815885d0689d723be76bac5bdaf6a7e Mon Sep 17 00:00:00 2001 From: EvilSeph Date: Tue, 30 Oct 2012 02:52:53 -0400 Subject: [PATCH] Expose API for clearing a player's inventory with a successful count return. Adds BUKKIT-2745 --- .../inventory/CraftInventoryPlayer.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java index 8ff94dffec..70ea942b18 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java @@ -89,6 +89,33 @@ public class CraftInventoryPlayer extends CraftInventory implements org.bukkit.i } } + public int clear(int id, int data) { + int count = 0; + ItemStack[] items = getContents(); + ItemStack[] armor = getArmorContents(); + int armorSlot = getSize(); + + for (int i = 0; i < items.length; i++) { + ItemStack item = items[i]; + if (item == null) continue; + if (id > -1 && item.getTypeId() != id) continue; + if (data > -1 && item.getData().getData() != data) continue; + + count += item.getAmount(); + setItem(i, null); + } + + for (ItemStack item : armor) { + if (item == null) continue; + if (id > -1 && item.getTypeId() != id) continue; + if (data > -1 && item.getData().getData() != data) continue; + + count += item.getAmount(); + setItem(armorSlot++, null); + } + return count; + } + @Override public HumanEntity getHolder() { return (HumanEntity) inventory.getOwner();