From ee441ae4b6fc89c0ad00b8eba443d2cdc722cef5 Mon Sep 17 00:00:00 2001 From: Telesphoreo Date: Tue, 18 Jul 2023 15:49:02 -0500 Subject: [PATCH] Convert more strings to MiniMessage --- .../dev/plex/itemizerx/ItemizerXCommand.java | 157 ++++++++---------- 1 file changed, 70 insertions(+), 87 deletions(-) diff --git a/src/main/java/dev/plex/itemizerx/ItemizerXCommand.java b/src/main/java/dev/plex/itemizerx/ItemizerXCommand.java index d2d666e..1af4816 100644 --- a/src/main/java/dev/plex/itemizerx/ItemizerXCommand.java +++ b/src/main/java/dev/plex/itemizerx/ItemizerXCommand.java @@ -7,6 +7,7 @@ import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; import org.apache.commons.lang3.StringUtils; import org.bukkit.ChatColor; import org.bukkit.Color; @@ -45,8 +46,7 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase if (args.length == 0) { - sender.sendMessage(mm.deserialize("ItemizerX v" + plugin.getDescription().getVersion() + - " by " + StringUtils.join(plugin.getDescription().getAuthors(), ", "))); + sender.sendMessage(mm.deserialize("ItemizerX v" + plugin.getDescription().getVersion() + " by " + StringUtils.join(plugin.getDescription().getAuthors(), ", "))); sender.sendMessage(mm.deserialize("Type /itemizer help for help")); return true; } @@ -234,7 +234,7 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase { if (!sender.hasPermission("itemizer.lore.change")) { - sender.sendMessage(colorize("&4You don't have permission to use this command!")); + sender.sendMessage(mm.deserialize("You don't have permission to use this command!")); return true; } if (args.length < 4) @@ -262,8 +262,7 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase } if (index > lores.size()) { - sender.sendMessage(mm.deserialize("")); - sender.sendMessage(colorize("&4The item's lore doesn't have line &f'" + index + "'")); + sender.sendMessage(mm.deserialize("The item's lore doesn't have line '" + index + "'")); return true; } lores.set(index - 1, lore); @@ -307,18 +306,18 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase } if (args.length == 1) { - sender.sendMessage(colorize(""" - &3===============&f[&dPotion Commands&f]&3=============== - &b/itemizer potion add <&feffect&b> <&flevel&b> <&ftime[tick]&b> &c- &6Add a potion effect - &b/itemizer potion remove <&feffect&b> &c- &6Remove a potion effect - &b/itemizer potion change <&fname&b> &c- &6Change the potion type - &b/itemizer potion color <&fhexcolor&b> &c- &6Set the potion color - &b/itemizer potion list &c- &6List all potion effects""")); + sender.sendMessage(mm.deserialize(""" + ===============[Potion Commands]=============== + /itemizer potion add <effect> <level> <time[tick]> - Add a potion effect + /itemizer potion remove <effect> - Remove a potion effect + /itemizer potion change <name> - Change the potion type + /itemizer potion color <hexcolor> - Set the potion color + /itemizer potion list - List all potion effects""")); return true; } if (!hasPotion) { - sender.sendMessage("Get a POTION in hand!"); + sender.sendMessage(mm.deserialize("You do not have a potion in your hand.")); return true; } else @@ -334,14 +333,14 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase } if (args.length < 5) { - sender.sendMessage(colorize("&3===============&f[&dPotion Commands&f]&3===============\n" - + "&b/itemizer potion add <&feffect&b> <&flevel&b> <&ftime[tick]&b> &c- &6Add a potion effect")); + sender.sendMessage(mm.deserialize("===============[Potion Commands]===============")); + sender.sendMessage(mm.deserialize("/itemizer potion add <effect> <level> <time[tick]> - Add a potion effect")); return true; } PotionEffectType potType = PotionEffectType.getByName(args[2].toUpperCase()); if (potType == null) { - sender.sendMessage(colorize("&4The potion &f\"" + args[2] + "&f\"&4 does not exist!")); + sender.sendMessage(mm.deserialize("The potion \"" + args[2] + "\" does not exist!")); return true; } Integer level = parseInt(sender, args[3]); @@ -355,12 +354,12 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase assert potionMeta != null; if (potionMeta.hasCustomEffect(pot.getType())) { - sender.sendMessage(colorize("&4This potion already has &f" + pot.getType().getName())); + sender.sendMessage(mm.deserialize("This potion already has " + pot.getType().getName())); return true; } potionMeta.addCustomEffect(pot, false); item.setItemMeta(potionMeta); - sender.sendMessage(colorize(pot.getType().getName() + " &2has been added to the potion")); + sender.sendMessage(mm.deserialize(pot.getType().getName() + " has been added to the potion")); return true; } case "remove" -> @@ -372,26 +371,26 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase } if (args.length == 2) { - sender.sendMessage(colorize("&3===============&f[&dPotion Commands&f]&3===============\n" - + "&b/itemizer potion remove <&feffect&b> &c- &6Remove a potion effect")); + sender.sendMessage(mm.deserialize("===============[Potion Commands]===============")); + sender.sendMessage(mm.deserialize("/itemizer potion remove <effect> - Remove a potion effect")); return true; } PotionEffectType potType = PotionEffectType.getByName(args[2].toUpperCase()); if (potType == null) { - sender.sendMessage("&4The potion effect &f\"" + args[2] + "&f\"&4 does not exist!"); + sender.sendMessage(mm.deserialize("The potion effect \"" + args[2] + "\" does not exist!")); return true; } final PotionMeta potionMeta = (PotionMeta)meta; assert potionMeta != null; if (!potionMeta.hasCustomEffect(potType)) { - sender.sendMessage(colorize("This potion does not have &f" + potType.getName())); + sender.sendMessage(mm.deserialize("This potion does not have " + potType.getName())); return true; } potionMeta.removeCustomEffect(potType); item.setItemMeta(potionMeta); - sender.sendMessage(colorize(potType.getName() + " &2has been removed from the potion")); + sender.sendMessage(mm.deserialize(potType.getName() + " has been removed from the potion")); return true; } case "change" -> @@ -403,21 +402,18 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase } if (args.length == 2) { - sender.sendMessage(colorize("&3===============&f[&dPotion Commands&f]&3===============\n" - + "&b/itemizer potion change <&fname&b> &c- &6Change the potion type")); + sender.sendMessage(mm.deserialize("===============[Potion Commands]===============")); + sender.sendMessage(mm.deserialize("/itemizer potion change <name> - Change the potion type")); return true; } Material material = Material.matchMaterial(args[2]); if (material == null || !POTIONS.contains(material)) { - sender.sendMessage(colorize(material != null ? - "&f'" + material.name() + "' &4is not a potion type!" - : - "&4That material doesn't exist!")); + sender.sendMessage(mm.deserialize(material != null ? "'" + material.name() + "' is not a potion type!" : "That material doesn't exist!")); return true; } item.setType(material); - sender.sendMessage(colorize("&2The potion in hand has changed to &f'" + material.name() + "'")); + sender.sendMessage(mm.deserialize("The potion in hand has changed to '" + material.name() + "'")); return true; } case "color" -> @@ -429,8 +425,8 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase } if (args.length < 3) { - sender.sendMessage(colorize("&3===============&f[&dPotion Commands&f]&3===============\n" - + "&b/itemizer potion color <&fhexcolor&b> &c- &6Set a potion color")); + sender.sendMessage(mm.deserialize("===============[Potion Commands]===============")); + sender.sendMessage(mm.deserialize("/itemizer potion color <hexcolor> - Set the potion color")); return true; } final PotionMeta potionMeta = (PotionMeta)meta; @@ -441,11 +437,11 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase Color color = Color.fromRGB(awtColor.getRed(), awtColor.getGreen(), awtColor.getBlue()); potionMeta.setColor(color); item.setItemMeta(potionMeta); - sender.sendMessage(colorize(args[2] + " &2has been set as potion color")); + sender.sendMessage(mm.deserialize(args[2] + " has been set as potion color")); } catch (NumberFormatException ignored) { - sender.sendMessage(colorize("&4The hex &f\"" + args[2] + "&f\"&4 is invalid!")); + sender.sendMessage(mm.deserialize("The hex \"" + args[2] + "\" is invalid!")); return true; } return true; @@ -463,13 +459,12 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase { sb.append(", ").append(effects[i].getName()); } - sender.sendMessage(colorize("&2Available potion effects: &e" - + sb.toString().replaceFirst(", ", ""))); + sender.sendMessage(mm.deserialize("Available potion effects: " + sb.toString().replaceFirst(", ", ""))); return true; } default -> { - sender.sendMessage(colorize("&bUnknown sub-command. Type &6/itemizer potion &bfor help.")); + sender.sendMessage(mm.deserialize("Unknown sub-command. Type /itemizer potion for help.")); return true; } } @@ -484,12 +479,12 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase } if (args.length == 1) { - sender.sendMessage(colorize(""" - &3===============&f[&dAttribute Commands&f]&3=============== - &b/itemizer attr add <&fname&b> <&fstrength&b> [&fslot&b] &c - &6Add an attribute - &b/itemizer attr remove <&fname&b> &c- &6Remove an attribute - &b/itemizer attr list &c- &6List all item's attributes - &b/itemizer attr listall &c- &6List all supported attributes""")); + sender.sendMessage(mm.deserialize(""" + ===============[Attribute Commands]=============== + /itemizer attr add <name> <strength> [slot] - Add an attribute + /itemizer attr remove <name> - Remove an attribute + /itemizer attr list - List all item's attributes + /itemizer attr listall - List all supported attributes""")); return true; } if (!hasItem) @@ -539,13 +534,12 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase sender.sendMessage(mm.deserialize("You don't have permission to use this command!")); return true; } - sender.sendMessage(colorize("&2Supported attributes: " - + "&e" + Attributes.getAttributes())); + sender.sendMessage(mm.deserialize("Supported attributes: " + Attributes.getAttributes())); return true; } default -> { - sender.sendMessage(colorize("&bUnknown sub-command. Type &6/itemizer attr &bfor help.")); + sender.sendMessage(mm.deserialize("Unknown sub-command. Type /itemizer attr for help.")); return true; } } @@ -560,12 +554,12 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase } if (args.length == 1) { - sender.sendMessage(colorize(""" - &3===============&f[&dFlag Commands&f]&3=============== - &b/itemizer flag add <&fname&b> &c- &6Add a flag - &b/itemizer flag remove <&fname&b> &c- &6Remove a flag - &b/itemizer flag list &c- &6List all item's flag - &b/itemizer flag listall &c- &6List all available flags""")); + sender.sendMessage(mm.deserialize(""" + ===============[Flag Commands]=============== + /itemizer flag add <name - Add a flag + /itemizer flag remove <name - Remove a flag + /itemizer flag list - List all item's flags + /itemizer flag listall - List all available flags""")); return true; } if (!hasItem) @@ -579,13 +573,13 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase { if (!sender.hasPermission("itemizer.flag.add")) { - sender.sendMessage(colorize("&4You don't have permission to use this command!")); + sender.sendMessage(mm.deserialize("You don't have permission to use this command!")); return true; } if (args.length == 2) { - sender.sendMessage(colorize("&3===============&f[&dFlag Commands&f]&3===============\n" - + "&b/itemizer flag add <&fname&b> &c- &6Add a flag")); + sender.sendMessage(mm.deserialize("===============[Flag Commands]===============")); + sender.sendMessage(mm.deserialize("/itemizer flag add <name - Add a flag")); return true; } ItemFlag flag = null; @@ -598,18 +592,18 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase } if (flag == null) { - sender.sendMessage(colorize("&4The flag &f\"" + args[2] + "&f\" does not exist!")); + sender.sendMessage(mm.deserialize("The flag \"" + args[2] + "\" does not exist!")); return true; } assert meta != null; if (meta.getItemFlags().contains(flag)) { - sender.sendMessage(colorize("&4The flag &f'" + args[2].toUpperCase() + "' &4already added to the item!")); + sender.sendMessage(mm.deserialize("The flag '" + args[2].toUpperCase() + "' is already added to the item!")); return true; } meta.addItemFlags(flag); item.setItemMeta(meta); - sender.sendMessage(colorize("&2The flag &f'" + args[2].toUpperCase() + "' &2has been added to your item!")); + sender.sendMessage(mm.deserialize("The flag '" + args[2].toUpperCase() + "' has been added to your item!")); return true; } case "remove" -> @@ -621,8 +615,8 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase } if (args.length == 2) { - sender.sendMessage(colorize("&3===============&f[&dFlag Commands&f]&3===============\n" - + "&b/itemizer flag remove <&fname&b> &c- &6remove a flag")); + sender.sendMessage(mm.deserialize("===============[Flag Commands]===============")); + sender.sendMessage(mm.deserialize("/itemizer flag remove <name - Remove a flag")); return true; } ItemFlag flag = null; @@ -635,18 +629,18 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase } if (flag == null) { - sender.sendMessage(colorize("&4The flag &f\"" + args[2] + "&f\" does not exist!")); + sender.sendMessage(mm.deserialize("The flag \"" + args[2] + "\" does not exist!")); return true; } assert meta != null; if (!meta.getItemFlags().contains(flag)) { - sender.sendMessage(colorize("&4The flag &f'" + args[2].toUpperCase() + "' &4has not been added the item!")); + sender.sendMessage(mm.deserialize("The flag '" + args[2].toUpperCase() + "' has not been added to the item!")); return true; } meta.removeItemFlags(flag); item.setItemMeta(meta); - sender.sendMessage(colorize("&2The flag &f'" + args[2].toUpperCase() + "' &2has been removed from your item!")); + sender.sendMessage(mm.deserialize("The flag '" + args[2].toUpperCase() + "' has been removed from your item!")); return true; } case "list" -> @@ -659,11 +653,10 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase assert meta != null; if (Objects.requireNonNull(meta.getItemFlags()).isEmpty()) { - sender.sendMessage(colorize("&4The item in your hand does not have any flags")); + sender.sendMessage(mm.deserialize("The item in your hand does not have any flags")); return true; } - sender.sendMessage(colorize("&2Item flags: &e" - + StringUtils.join(meta.getItemFlags(), ", "))); + sender.sendMessage(mm.deserialize("Item flags: " + StringUtils.join(meta.getItemFlags(), ", "))); return true; } case "listall" -> @@ -673,13 +666,12 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase sender.sendMessage(mm.deserialize("You don't have permission to use this command!")); return true; } - sender.sendMessage(colorize("&2Available item flags: &e" - + StringUtils.join(ItemFlag.values(), ", "))); + sender.sendMessage(mm.deserialize("Available item flags: " + StringUtils.join(ItemFlag.values(), ", "))); return true; } default -> { - sender.sendMessage(colorize("&bUnknown sub-command. Type &6/itemizer flag &bfor help")); + sender.sendMessage(mm.deserialize("Unknown sub-command. Type /itemizer flag for help.")); return true; } } @@ -717,8 +709,7 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase } if (args.length < 4) { - sender.sendMessage(colorize("&3===============&f[&dEnchant Commands&f]&3===============\n" - + "&b/itemizer enchant add <&fname&b> <&flevel&b> &c- &6Add an enchant")); + sender.sendMessage(colorize("&3===============&f[&dEnchant Commands&f]&3===============\n" + "&b/itemizer enchant add <&fname&b> <&flevel&b> &c- &6Add an enchant")); return true; } final Enchantment ench = EnchantmentWrapper.getByKey(NamespacedKey.minecraft(args[2].toLowerCase())); @@ -745,8 +736,7 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase } if (args.length == 2) { - sender.sendMessage(colorize("&3===============&f[&dEnchant Commands&f]&3===============\n" - + "&b/itemizer enchant remove <&fname&b> &c- &6Remove an enchant")); + sender.sendMessage(colorize("&3===============&f[&dEnchant Commands&f]&3===============\n" + "&b/itemizer enchant remove <&fname&b> &c- &6Remove an enchant")); return true; } final Enchantment ench = EnchantmentWrapper.getByKey(NamespacedKey.minecraft(args[2].toLowerCase())); @@ -783,8 +773,7 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase sender.sendMessage(colorize("&4This item doesn't hold any enchants")); return true; } - sender.sendMessage(colorize("&2Item enchants: &e" - + StringUtils.join(meta.getEnchants().keySet(), ", "))); + sender.sendMessage(colorize("&2Item enchants: &e" + StringUtils.join(meta.getEnchants().keySet(), ", "))); return true; } case "listall" -> @@ -800,8 +789,7 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase { sb.append(", ").append(enchantments[i].getKey().getKey()); } - sender.sendMessage(colorize("&2Available item enchants: &e" - + sb.toString().replaceFirst(", ", ""))); + sender.sendMessage(colorize("&2Available item enchants: &e" + sb.toString().replaceFirst(", ", ""))); return true; } default -> @@ -820,8 +808,7 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase } if (args.length == 1) { - sender.sendMessage(colorize("&3===============&f[&dTitle Command&f]&3===============\n" - + "&b/itemizer title <&fname&b> &c- &6Set the book's title")); + sender.sendMessage(colorize("&3===============&f[&dTitle Command&f]&3===============\n" + "&b/itemizer title <&fname&b> &c- &6Set the book's title")); return true; } if (!hasBook) @@ -846,8 +833,7 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase } if (args.length == 1) { - sender.sendMessage(colorize("&3===============&f[&dAuthor Command&f]&3===============\n" - + "&b/itemizer author <&fname&b> &c- &6Set the book's title")); + sender.sendMessage(colorize("&3===============&f[&dAuthor Command&f]&3===============\n" + "&b/itemizer author <&fname&b> &c- &6Set the book's title")); return true; } if (!hasBook) @@ -872,8 +858,7 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase } if (args.length == 1) { - sender.sendMessage(colorize("&3===============&f[&dHead Command&f]&3===============\n" - + "&b/itemizer head <&fname&b> &c- &6Set the player of the head")); + sender.sendMessage(colorize("&3===============&f[&dHead Command&f]&3===============\n" + "&b/itemizer head <&fname&b> &c- &6Set the player of the head")); return true; } if (item.getType() != Material.PLAYER_HEAD) @@ -902,13 +887,11 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase } if (args.length < 3) { - sender.sendMessage(colorize("&3===============&f[&dSign Command&f]&3===============\n" - + "&b/itemizer sign <&fline&b> <&ftext&b> &c- &6Change the line on the sign")); + sender.sendMessage(colorize("&3===============&f[&dSign Command&f]&3===============\n" + "&b/itemizer sign <&fline&b> <&ftext&b> &c- &6Change the line on the sign")); return true; } final Block block = player.getTargetBlockExact(20); - if (block == null || block.getType() == Material.AIR - || !block.getType().toString().contains("SIGN")) + if (block == null || block.getType() == Material.AIR || !block.getType().toString().contains("SIGN")) { sender.sendMessage(colorize("&4Please look at a sign!")); return true;