From 7e48b381667471894339e9fe7cf781a8a73ede7c Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Sat, 15 Jan 2011 21:55:53 +0100 Subject: [PATCH] Implemented clear/remove for inventories By: Erik Broes --- .../bukkit/craftbukkit/CraftInventory.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftInventory.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftInventory.java index f8a95ee90d..66a77fd8ec 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftInventory.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftInventory.java @@ -205,4 +205,35 @@ public class CraftInventory implements org.bukkit.Inventory { return getInventory().c(); } + public void remove(int materialId) { + ItemStack[] items = getContents(); + for (int i = 0; i < items.length; i++) { + if (items[i].getTypeId() == materialId) { + clear(i); + } + } + } + + public void remove(Material material) { + remove(material.getId()); + } + + public void remove(ItemStack item) { + ItemStack[] items = getContents(); + for (int i = 0; i < items.length; i++) { + if (items[i].equals(item)) { + clear(i); + } + } + } + + public void clear(int index) { + setItem(index, null); + } + + public void clear() { + for (int i = 0; i < getSize(); i++) { + clear(i); + } + } }