From e77b080d833accd713ac0dff048994eadc3b8ae3 Mon Sep 17 00:00:00 2001 From: Limb Date: Mon, 24 Jan 2011 07:42:59 +0800 Subject: [PATCH] Implemented Inventory.contains with a minimum amount of item required. As per feature request #187 --- .../craftbukkit/inventory/CraftInventory.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java index 3387235df8..3079ae2fac 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java @@ -83,7 +83,29 @@ public class CraftInventory implements org.bukkit.inventory.Inventory { } return false; } + + public boolean contains(int materialId, int amount) { + for (ItemStack item: getContents()) { + if (item.getTypeId() == materialId && item.getAmount() >= amount) { + return true; + } + } + return false; + } + public boolean contains(Material material, int amount) { + return contains(material.getId(), amount); + } + + public boolean contains(ItemStack item, int amount) { + for (ItemStack i: getContents()) { + if (item.equals(i) && item.getAmount() >= amount) { + return true; + } + } + return false; + } + public HashMap all(int materialId) { HashMap slots = new HashMap();