Expose API for clearing a player's inventory with a successful count

return. Adds BUKKIT-2745
This commit is contained in:
EvilSeph 2012-10-30 02:52:53 -04:00
parent 856fdc2ab6
commit 6bf705dd08

View File

@ -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();