diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java index b5677e46..98559480 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java @@ -28,6 +28,9 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; +import java.util.List; +import java.util.Set; + public class CosmeticCommand implements CommandExecutor { // cosmetics apply cosmetics playerName @@ -148,19 +151,11 @@ public class CosmeticCommand implements CommandExecutor { return true; } - CosmeticSlot cosmeticSlot; - if (sender instanceof Player) player = ((Player) sender).getPlayer(); if (sender.hasPermission("hmccosmetics.cmd.unapply.other")) { if (args.length >= 3) player = Bukkit.getPlayer(args[2]); } - if (!EnumUtils.isValidEnum(CosmeticSlot.class, args[1].toUpperCase())) { - if (!silent) MessagesUtil.sendMessage(sender, "invalid-slot"); - return true; - } - cosmeticSlot = CosmeticSlot.valueOf(args[1].toUpperCase()); - if (player == null) { if (!silent) MessagesUtil.sendMessage(sender, "invalid-player"); return true; @@ -168,20 +163,34 @@ public class CosmeticCommand implements CommandExecutor { CosmeticUser user = CosmeticUsers.getUser(player); - if (user.getCosmetic(cosmeticSlot) == null) { - if (!silent) MessagesUtil.sendMessage(sender, "no-cosmetic-slot"); - return true; + Set cosmeticSlots; + + if (args[1].equalsIgnoreCase("all")) { + cosmeticSlots = user.getSlotsWithCosmetics(); + } else { + if (!EnumUtils.isValidEnum(CosmeticSlot.class, args[1].toUpperCase())) { + if (!silent) MessagesUtil.sendMessage(sender, "invalid-slot"); + return true; + } + cosmeticSlots = Set.of(CosmeticSlot.valueOf(args[1].toUpperCase())); } - TagResolver placeholders = - TagResolver.resolver(Placeholder.parsed("cosmetic", user.getCosmetic(cosmeticSlot).getId()), - TagResolver.resolver(Placeholder.parsed("player", player.getName())), - TagResolver.resolver(Placeholder.parsed("cosmeticslot", cosmeticSlot.name()))); + for (CosmeticSlot cosmeticSlot : cosmeticSlots) { + if (user.getCosmetic(cosmeticSlot) == null) { + if (!silent) MessagesUtil.sendMessage(sender, "no-cosmetic-slot"); + continue; + } - if (!silent) MessagesUtil.sendMessage(player, "unequip-cosmetic", placeholders); + TagResolver placeholders = + TagResolver.resolver(Placeholder.parsed("cosmetic", user.getCosmetic(cosmeticSlot).getId()), + TagResolver.resolver(Placeholder.parsed("player", player.getName())), + TagResolver.resolver(Placeholder.parsed("cosmeticslot", cosmeticSlot.name()))); - user.removeCosmeticSlot(cosmeticSlot); - user.updateCosmetic(cosmeticSlot); + if (!silent) MessagesUtil.sendMessage(player, "unequip-cosmetic", placeholders); + + user.removeCosmeticSlot(cosmeticSlot); + user.updateCosmetic(cosmeticSlot); + } return true; } case ("wardrobe") -> { diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommandTabComplete.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommandTabComplete.java index 31605ded..873f3f99 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommandTabComplete.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommandTabComplete.java @@ -59,6 +59,7 @@ public class CosmeticCommandTabComplete implements TabCompleter { for (Cosmetic cosmetic : user.getCosmetic()) { completions.add(cosmetic.getSlot().toString().toUpperCase()); } + completions.add("ALL"); } case "menu" -> { for (Menu menu : Menus.getMenu()) { diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java index b91e1c1e..f250a946 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java @@ -151,6 +151,10 @@ public class CosmeticUser { return playerCosmetics.containsKey(slot); } + public Set getSlotsWithCosmetics() { + return Set.copyOf(playerCosmetics.keySet()); + } + public void updateCosmetic(CosmeticSlot slot) { if (getCosmetic(slot) == null) { return;