diff --git a/src/main/java/dev/majek/hexnicks/command/CommandNickColor.java b/src/main/java/dev/majek/hexnicks/command/CommandNickColor.java index bb5518c..60939f6 100644 --- a/src/main/java/dev/majek/hexnicks/command/CommandNickColor.java +++ b/src/main/java/dev/majek/hexnicks/command/CommandNickColor.java @@ -54,8 +54,12 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command } if (args.length == 0) { - new NickColorGui().openGui(player); - return true; + if (HexNicks.config().NICKCOLOR_GUI) { + new NickColorGui().openGui(player); + return true; + } else { + return false; + } } String nickInput = String.join(" ", args); diff --git a/src/main/java/dev/majek/hexnicks/config/ConfigValues.java b/src/main/java/dev/majek/hexnicks/config/ConfigValues.java index b1f8d05..9a4795e 100644 --- a/src/main/java/dev/majek/hexnicks/config/ConfigValues.java +++ b/src/main/java/dev/majek/hexnicks/config/ConfigValues.java @@ -58,6 +58,7 @@ public class ConfigValues { public Boolean PREVENT_DUPLICATE_NICKS; public Boolean PREVENT_DUPLICATE_NICKS_STRICT; public List BLOCKED_NICKNAMES; + public Boolean NICKCOLOR_GUI; public Boolean DEBUG; public ConfigValues() { @@ -84,6 +85,7 @@ public void reload() { PREVENT_DUPLICATE_NICKS = HexNicks.core().getConfig().getBoolean("prevent-duplicate-nicks", true); PREVENT_DUPLICATE_NICKS_STRICT = HexNicks.core().getConfig().getBoolean("prevent-duplicate-nicks-strict", false); BLOCKED_NICKNAMES = HexNicks.core().getConfig().getStringList("blocked-nicknames"); + NICKCOLOR_GUI = HexNicks.core().getConfig().getBoolean("nickcolor-gui", true); DEBUG = HexNicks.core().getConfig().getBoolean("debug", false); } diff --git a/src/main/java/dev/majek/hexnicks/config/Messages.java b/src/main/java/dev/majek/hexnicks/config/Messages.java index 809f63e..fab426a 100644 --- a/src/main/java/dev/majek/hexnicks/config/Messages.java +++ b/src/main/java/dev/majek/hexnicks/config/Messages.java @@ -27,6 +27,7 @@ import dev.majek.hexnicks.util.MiscUtils; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextReplacementConfig; +import net.kyori.adventure.text.format.TextColor; import net.kyori.adventure.text.minimessage.MiniMessage; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -120,6 +121,27 @@ public interface Messages { .replaceText(TextReplacementConfig.builder().matchLiteral("%player%").replacement(player.getName()).build()) .replaceText(TextReplacementConfig.builder().matchLiteral("%nick%").replacement(nickname).build()); + Args0 GUI_BACK = () -> MiscUtils.configString("messages.guiBack", "Back"); + + Args0 GUI_NICK_COLOR_TITLE = () -> MiscUtils.configString("messages.guiNickColorTitle", "Nick Color"); + + Args1 GUI_NICK_COLOR_HEX_TITLE = (col) -> MiniMessage.miniMessage().deserialize(HexNicks.core().getConfig().getString( + "messages.guiNickColorHexTitle", + "Nick Color - %color%" + ).replace("%color%", col.toString())); + + Args0 GUI_NICK_COLOR_RANDOM_HEX = () -> MiscUtils.configString("messages.guiNickColorRandomHex", "Random Hexadecimal Color"); + + Args1 GUI_NICK_COLOR_HEX_RED = (c) -> MiscUtils.configString("messages.guiNickColorHexRed", "Red %step%") + .replaceText(TextReplacementConfig.builder().matchLiteral("%step%").replacement("%+d".formatted(c)).build()); + Args1 GUI_NICK_COLOR_HEX_GREEN = (c) -> MiscUtils.configString("messages.guiNickColorHexGreen", "Green %step%") + .replaceText(TextReplacementConfig.builder().matchLiteral("%step%").replacement("%+d".formatted(c)).build()); + Args1 GUI_NICK_COLOR_HEX_BLUE = (c) -> MiscUtils.configString("messages.guiNickColorHexBlue", "Blue %step%") + .replaceText(TextReplacementConfig.builder().matchLiteral("%step%").replacement("%+d".formatted(c)).build()); + + Args0 GUI_NICK_COLOR_HEX_BUTTON = () -> MiscUtils.configString("messages.guiNickColorHexButton", "Custom Hexadecimal Color"); + Args0 GUI_NICK_COLOR_HEX_SAVE = () -> MiscUtils.configString("messages.guiNickColorHexSave", "Click to save nickname"); + /** * A message that has no arguments that need to be replaced. */ diff --git a/src/main/java/dev/majek/hexnicks/gui/NickColorGui.java b/src/main/java/dev/majek/hexnicks/gui/NickColorGui.java index 324ae46..e07535e 100644 --- a/src/main/java/dev/majek/hexnicks/gui/NickColorGui.java +++ b/src/main/java/dev/majek/hexnicks/gui/NickColorGui.java @@ -2,6 +2,7 @@ import dev.majek.hexnicks.command.CommandHexNicks; import dev.majek.hexnicks.command.CommandNickColor; +import dev.majek.hexnicks.config.Messages; import dev.majek.hexnicks.util.CustomHead; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; @@ -79,18 +80,12 @@ private static ItemStack generateItem(@NotNull String name, @NotNull TextColor c RAINBOW = CustomHead.RAINBOW.asItemStack(); ItemMeta meta = RAINBOW.getItemMeta(); - // TODO: Language - meta.displayName(Component.text("Hexadecimal Color").decoration(TextDecoration.ITALIC, false)); - meta.lore(List.of( - // TODO: Language - Component.text("Create a custom hexadecimal color", NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC, false) - )); + meta.displayName(Messages.GUI_NICK_COLOR_HEX_BUTTON.build()); RAINBOW.setItemMeta(meta); } public NickColorGui() { - // TODO: Language - super(54, Component.text("Nick Color")); + super(54, Messages.GUI_NICK_COLOR_TITLE.build()); } /** diff --git a/src/main/java/dev/majek/hexnicks/gui/NickColorHexGui.java b/src/main/java/dev/majek/hexnicks/gui/NickColorHexGui.java index 053f972..ee13129 100644 --- a/src/main/java/dev/majek/hexnicks/gui/NickColorHexGui.java +++ b/src/main/java/dev/majek/hexnicks/gui/NickColorHexGui.java @@ -1,6 +1,7 @@ package dev.majek.hexnicks.gui; import dev.majek.hexnicks.HexNicks; +import dev.majek.hexnicks.config.Messages; import dev.majek.hexnicks.message.MiniMessageWrapper; import dev.majek.hexnicks.util.CustomHead; import dev.majek.hexnicks.util.MiscUtils; @@ -43,18 +44,16 @@ public class NickColorHexGui extends Gui { /** * Generate the array of items that should be used for changing the r/g/b values * - * @param name the name of the value that should be displayed (i.e. "Red") - * @param color The colour of the text to be displayed - * @param base The base {@link ItemStack} that should be used (this is cloned for each item in the array) + * @param msg The message that should be used for the name (passed the step) + * @param base The base {@link ItemStack} that should be used (this is cloned for each item in the array) * @return An array with 6 elements that maps to the values in {@code STEPS} */ - private static ItemStack[] generateItems(String name, NamedTextColor color, ItemStack base) { + private static ItemStack[] generateItems(Messages.Args1 msg, ItemStack base) { ItemStack[] out = new ItemStack[6]; - Component nameComp = Component.text(name, color).decoration(TextDecoration.ITALIC, false); ItemMeta meta = base.getItemMeta(); for (int i = 0; i < 6; i++) { int step = STEPS[i]; - meta.displayName(nameComp.append(Component.space()).append(Component.text("%+d".formatted(step)))); + meta.displayName(msg.build(step)); out[i] = base.clone(); out[i].setAmount(Math.abs(step)); out[i].setItemMeta(meta); @@ -64,33 +63,29 @@ private static ItemStack[] generateItems(String name, NamedTextColor color, Item static { // @formatter:off - // TODO: Language - RED = generateItems("Red", NamedTextColor.RED, CustomHead.RED.asItemStack()); - GREEN = generateItems("Green", NamedTextColor.GREEN, CustomHead.GREEN.asItemStack()); - BLUE = generateItems("Blue", NamedTextColor.AQUA, CustomHead.AQUA.asItemStack()); + RED = generateItems(Messages.GUI_NICK_COLOR_HEX_RED, CustomHead.RED.asItemStack()); + GREEN = generateItems(Messages.GUI_NICK_COLOR_HEX_GREEN, CustomHead.GREEN.asItemStack()); + BLUE = generateItems(Messages.GUI_NICK_COLOR_HEX_BLUE, CustomHead.AQUA.asItemStack()); // @formatter:on // Generate the rainbow button RAINBOW = CustomHead.RAINBOW.asItemStack(); ItemMeta meta = RAINBOW.getItemMeta(); - // TODO: Language - meta.displayName(MiniMessageWrapper.standard().mmParse("Random Hexadecimal Color").decoration(TextDecoration.ITALIC, false)); + meta.displayName(Messages.GUI_NICK_COLOR_RANDOM_HEX.build()); RAINBOW.setItemMeta(meta); BACK_BUTTON = new ItemStack(Material.NETHER_STAR); meta = BACK_BUTTON.getItemMeta(); - // TODO: Language - meta.displayName(Component.text("Back", NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC, false)); + meta.displayName(Messages.GUI_BACK.build()); BACK_BUTTON.setItemMeta(meta); } public NickColorHexGui() { - // TODO: Language this(0x88, 0x88, 0x88); } public NickColorHexGui(int r, int g, int b) { - super(54, Component.text("Nick Color - ").append(Component.text(TextColor.color(r, g, b).toString(), TextColor.color(r, g, b)))); + super(54, Messages.GUI_NICK_COLOR_HEX_TITLE.build(TextColor.color(r, g, b))); this.red = r; this.green = g; @@ -105,7 +100,10 @@ private void updateName(boolean newGui) { ItemStack s = new ItemStack(Material.NAME_TAG); ItemMeta meta = s.getItemMeta(); meta.displayName(Component.text(this.nickname).color(col).decoration(TextDecoration.ITALIC, false)); - meta.lore(List.of(Component.text(col.toString()).decoration(TextDecoration.ITALIC, false))); + meta.lore(List.of( + Component.text(col.toString()).decoration(TextDecoration.ITALIC, false), + Messages.GUI_NICK_COLOR_HEX_SAVE.build() + )); s.setItemMeta(meta); addActionButton(20, s, () -> { // Use the command since it already handles the logic diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index f99051a..fbfff81 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -63,6 +63,9 @@ blocked-nicknames: - "replace these lines" - "what to block" +# Whether a gui should open when running `/nickcolor` with no arguments -- `/nickcolor ` works either way. +nickcolor-gui: true + # Database settings # Only enable this if you know what you're doing and have an existing database database-enabled: false @@ -105,4 +108,13 @@ messages: latestLog: "View the latest log here." working: "Working..." notAllowed: "That nickname is not allowed!" - joinAnnouncement: "%player% has the nickname %nick%" \ No newline at end of file + joinAnnouncement: "%player% has the nickname %nick%" + guiBack: "Back" + guiNickColorTitle: "Nick Color" + guiNickColorHexTitle: "Nick Color - %color%" + guiNickColorRandomHex: "Random Hexadecimal Color" + guiNickColorHexRed: "Red %step%" + guiNickColorHexGreen: "Green %step%" + guiNickColorHexBlue: "Blue %step%" + guiNickColorHexButton: "Custom Hexadecimal Color" + guiNickColorHexSave: "Click to save nickname"