diff options
author | EvilSeph <evilseph@gmail.com> | 2012-10-30 02:52:53 -0400 |
---|---|---|
committer | EvilSeph <evilseph@gmail.com> | 2012-10-30 04:55:02 -0400 |
commit | 6bf705dd0815885d0689d723be76bac5bdaf6a7e (patch) | |
tree | 71e8f0d8d16e3d4f24fd9e1993ab0861ed4952ad /src | |
parent | 856fdc2ab60d2813c815132b5e7fedfa890204f5 (diff) | |
download | craftbukkit-6bf705dd0815885d0689d723be76bac5bdaf6a7e.tar craftbukkit-6bf705dd0815885d0689d723be76bac5bdaf6a7e.tar.gz craftbukkit-6bf705dd0815885d0689d723be76bac5bdaf6a7e.tar.lz craftbukkit-6bf705dd0815885d0689d723be76bac5bdaf6a7e.tar.xz craftbukkit-6bf705dd0815885d0689d723be76bac5bdaf6a7e.zip |
Expose API for clearing a player's inventory with a successful count
return. Adds BUKKIT-2745
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java index 8ff94dff..70ea942b 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(); |