}
@CommandDescription (aliases = "clear", usage = "[player] [item] [data]", desc = "Clears the target's inventory")
@Permissible ("vanilla.command.clear")
public void clear(CommandSource source, CommandArguments args) throws CommandException {
Player player = args.popPlayerOrMe("player", source);
Material filter = VanillaArgumentTypes.popMaterial("filter", args);
Integer data = args.popInteger("data");
args.assertCompletelyParsed();
PlayerInventory inv = player.get(PlayerInventory.class);
if (inv == null) {
throw new CommandException(player.getName() + " doesn't have a inventory!");
} else {
// Count the items and clear the inventory
Inventory[] inventories = new Inventory[] {inv.getMain(), inv.getQuickbar(), inv.getArmor()};
int cleared = 0;
for (int k = 0; k < inventories.length; k++) {
for (int i = 0; i < inventories[k].size(); i++) {
if (inventories[k].get(i) != null && (filter == null || inventories[k].get(i).isMaterial(filter)) && (data == null || inventories[k].get(i).getData() == data)) {
cleared += inventories[k].get(i).getAmount();
inventories[k].set(i, null);
}
}
}
if (cleared == 0) {
throw new CommandException("Inventory is already empty");
}
source.sendMessage(plugin.getPrefix() + ChatStyle.GREEN + "Cleared the inventory of " + player.getName() + ", removing " + cleared + " items.");
}
}