mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-11 11:49:12 +00:00
Allow multiple item names in /clearinventory
Allow a comma-separated list of item names in /clearinventory.
This commit is contained in:
parent
60c90408e7
commit
79bc34047b
1 changed files with 29 additions and 39 deletions
|
@ -14,11 +14,7 @@ import org.bukkit.Server;
|
|||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class Commandclearinventory extends EssentialsCommand {
|
||||
|
@ -89,7 +85,7 @@ public class Commandclearinventory extends EssentialsCommand {
|
|||
short data = -1;
|
||||
int type = -1;
|
||||
int amount = -1;
|
||||
Material mat = null;
|
||||
final Set<Material> mats = new HashSet<>();
|
||||
|
||||
if (args.length > (offset + 1) && NumberUtil.isInt(args[(offset + 1)])) {
|
||||
amount = Integer.parseInt(args[(offset + 1)]);
|
||||
|
@ -98,16 +94,15 @@ public class Commandclearinventory extends EssentialsCommand {
|
|||
if (args[offset].equalsIgnoreCase("**")) {
|
||||
type = -2;
|
||||
} else if (!args[offset].equalsIgnoreCase("*")) {
|
||||
final String[] split = args[offset].split(":");
|
||||
final ItemStack item = ess.getItemDb().get(split[0]);
|
||||
type = ess.getItemDb().getLegacyId(item.getType());
|
||||
mat = item.getType();
|
||||
final String[] split = args[offset].split(",");
|
||||
|
||||
if (split.length > 1 && NumberUtil.isInt(split[1])) {
|
||||
data = Short.parseShort(split[1]);
|
||||
} else {
|
||||
data = item.getDurability();
|
||||
for (String name : split) {
|
||||
try {
|
||||
mats.add(ess.getItemDb().get(name).getType());
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
type = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -127,14 +122,8 @@ public class Commandclearinventory extends EssentialsCommand {
|
|||
InventoryWorkaround.setItemInOffHand(player, null);
|
||||
player.getInventory().setArmorContents(null);
|
||||
} else {
|
||||
if (data == -1) // data -1 means that all subtypes will be cleared
|
||||
{
|
||||
ItemStack stack = new ItemStack(mat);
|
||||
if (showExtended) {
|
||||
sender.sendMessage(tl("inventoryClearingAllStack", stack.getType().toString().toLowerCase(Locale.ENGLISH), player.getDisplayName()));
|
||||
}
|
||||
player.getInventory().remove(mat);
|
||||
} else if (amount == -1) // amount -1 means all items will be cleared
|
||||
for (Material mat : mats) {
|
||||
if (amount == -1) // amount -1 means all items will be cleared
|
||||
{
|
||||
ItemStack stack = new ItemStack(mat, BASE_AMOUNT, data);
|
||||
ItemStack removedStack = player.getInventory().removeItem(stack).get(0);
|
||||
|
@ -146,7 +135,7 @@ public class Commandclearinventory extends EssentialsCommand {
|
|||
if (amount < 0) {
|
||||
amount = 1;
|
||||
}
|
||||
ItemStack stack = new ItemStack(mat, amount, data);
|
||||
ItemStack stack = new ItemStack(mat, amount);
|
||||
if (player.getInventory().containsAtLeast(stack, amount)) {
|
||||
sender.sendMessage(tl("inventoryClearingStack", amount, stack.getType().toString().toLowerCase(Locale.ENGLISH), player.getDisplayName()));
|
||||
player.getInventory().removeItem(stack);
|
||||
|
@ -158,6 +147,7 @@ public class Commandclearinventory extends EssentialsCommand {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
|
||||
|
|
Loading…
Reference in a new issue