Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-11-16 13:00:06 +01:00
Expose API for clearing a player's inventory with a successful count
return. Adds BUKKIT-2745
Dieser Commit ist enthalten in:
Ursprung
856fdc2ab6
Commit
6bf705dd08
@ -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();
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren