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 60133311..1968d05f 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java @@ -13,10 +13,12 @@ import com.hibiscusmc.hmccosmetics.gui.special.DyeMenu; import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.user.CosmeticUsers; import com.hibiscusmc.hmccosmetics.util.MessagesUtil; +import com.hibiscusmc.hmccosmetics.util.ServerUtils; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; import org.apache.commons.lang3.EnumUtils; import org.bukkit.Bukkit; +import org.bukkit.Color; import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -197,7 +199,7 @@ public class CosmeticCommand implements CommandExecutor { return true; } - else if (args[0].equalsIgnoreCase("dye") && args.length == 2) { + else if (args[0].equalsIgnoreCase("dye") && args.length >= 2) { Player player = sender instanceof Player ? (Player) sender : null; if (player == null) return true; CosmeticUser user = CosmeticUsers.getUser(player); @@ -206,7 +208,24 @@ public class CosmeticCommand implements CommandExecutor { MessagesUtil.sendMessage(sender, "no-permission"); return true; } - DyeMenu.openMenu(user, user.getCosmetic(CosmeticSlot.valueOf(args[1]))); + + CosmeticSlot slot = CosmeticSlot.valueOf(args[1]); + Cosmetic cosmetic = user.getCosmetic(slot); + + if (args.length >= 3) { + if (!args[2].contains("#") || args[2].isEmpty()) { + MessagesUtil.sendMessage(player, "invalid-color"); + return true; + } + Color color = ServerUtils.hex2Rgb(args[2]); + if (color == null) { + MessagesUtil.sendMessage(player, "invalid-color"); + return true; + } + user.addPlayerCosmetic(cosmetic, color); // #FFFFFF + } else { + DyeMenu.openMenu(user, cosmetic); + } } else if (args[0].equalsIgnoreCase("setlocation")) { 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 9d176726..9dde37a4 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommandTabComplete.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommandTabComplete.java @@ -42,7 +42,7 @@ public class CosmeticCommandTabComplete implements TabCompleter { if (!(sender instanceof Player)) return completions; CosmeticUser user = CosmeticUsers.getUser(((Player) sender).getUniqueId()); - if (args.length >= 2) { + if (args.length == 2) { String subcommand = args[0].toLowerCase(); switch (subcommand) { case "apply" -> { @@ -74,6 +74,15 @@ public class CosmeticCommandTabComplete implements TabCompleter { } StringUtil.copyPartialMatches(args[1], completions, finalCompletitons); } + if (args.length == 3) { + String subcommand = args[0].toLowerCase(); + switch (subcommand) { + case "dye" -> { + completions.add("#FFFFFF"); + } + } + StringUtil.copyPartialMatches(args[2], completions, finalCompletitons); + } Collections.sort(finalCompletitons); return finalCompletitons; diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/util/MessagesUtil.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/util/MessagesUtil.java index e230433c..fc5dd94c 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/util/MessagesUtil.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/util/MessagesUtil.java @@ -11,6 +11,7 @@ import net.kyori.adventure.audience.Audience; import net.kyori.adventure.platform.bukkit.BukkitAudiences; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.kyori.adventure.title.Title; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -59,6 +60,13 @@ public class MessagesUtil { target.sendMessage(finalMessage); } + public static void sendMessageNoKey(Player player, String message) { + Component finalMessage = processStringNoKey(player, message); + Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player); + + target.sendMessage(finalMessage); + } + public static void sendActionBar(Player player, String key) { Component finalMessage = processString(player, key); Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player); @@ -112,7 +120,11 @@ public class MessagesUtil { return Adventure.MINI_MESSAGE.deserialize(message); } - + public static String processStringNoKeyString(Player player, String message) { + message = message.replaceAll("%prefix%", prefix); + if (PAPIHook.isPAPIEnabled() && player != null) message = PlaceholderAPI.setPlaceholders(player, message); + return message; + } public static void sendDebugMessages(String message) { sendDebugMessages(message, Level.INFO); diff --git a/common/src/main/resources/messages.yml b/common/src/main/resources/messages.yml index 1c2ec38b..1f764472 100644 --- a/common/src/main/resources/messages.yml +++ b/common/src/main/resources/messages.yml @@ -18,4 +18,5 @@ unequip-cosmetic: "%prefix% You have unequipped Invalid cosmetic slot!" invalid-player: "%prefix% Invalid Player!" invalid-menu: "%prefix% Invalid Menu!" -invalid-cosmetic: "%prefix% Invalid Cosmetic!" \ No newline at end of file +invalid-cosmetic: "%prefix% Invalid Cosmetic!" +invalid-color: "%prefix% Invalid Color!" \ No newline at end of file