mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-02 04:56:50 +01:00
Expose API for clearing a player's inventory with a successful count
return. Adds BUKKIT-2745
This commit is contained in:
parent
856fdc2ab6
commit
6bf705dd08
1 changed files with 27 additions and 0 deletions
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue