From 7d468115e0c5ab051d26ae1b4c7a29b5a5084fd1 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Mon, 16 Jan 2023 03:02:13 +0100 Subject: [PATCH] Makes the npc talking format configurable #19 --- .../blacksmith/formatting/BlacksmithStringFormatter.java | 8 +++++--- .../formatting/BlacksmithTranslatableMessage.java | 7 ++++++- src/main/resources/strings.yml | 1 + 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/knarcraft/blacksmith/formatting/BlacksmithStringFormatter.java b/src/main/java/net/knarcraft/blacksmith/formatting/BlacksmithStringFormatter.java index dfd0d14..fb85ea2 100644 --- a/src/main/java/net/knarcraft/blacksmith/formatting/BlacksmithStringFormatter.java +++ b/src/main/java/net/knarcraft/blacksmith/formatting/BlacksmithStringFormatter.java @@ -1,9 +1,9 @@ package net.knarcraft.blacksmith.formatting; import net.citizensnpcs.api.npc.NPC; +import net.knarcraft.blacksmith.BlacksmithPlugin; import net.knarcraft.knarlib.property.ColorConversion; import net.knarcraft.knarlib.util.ColorHelper; -import net.md_5.bungee.api.ChatColor; import org.bukkit.entity.Player; /** @@ -23,8 +23,10 @@ public final class BlacksmithStringFormatter { * @param message

The message to send

*/ public static void sendNPCMessage(NPC npc, Player player, String message) { - player.sendMessage(ChatColor.GREEN + "[" + npc.getName() + "] -> You:" + ChatColor.RESET + " " + - ColorHelper.translateColorCodes(message, ColorConversion.NORMAL)); + player.sendMessage(BlacksmithPlugin.getStringFormatter().replacePlaceholders( + BlacksmithTranslatableMessage.NPC_TALK_FORMAT, + new String[]{"{npc}", "{message}"}, + new String[]{npc.getName(), ColorHelper.translateColorCodes(message, ColorConversion.RGB)})); } } diff --git a/src/main/java/net/knarcraft/blacksmith/formatting/BlacksmithTranslatableMessage.java b/src/main/java/net/knarcraft/blacksmith/formatting/BlacksmithTranslatableMessage.java index 87b7ae6..20c6711 100644 --- a/src/main/java/net/knarcraft/blacksmith/formatting/BlacksmithTranslatableMessage.java +++ b/src/main/java/net/knarcraft/blacksmith/formatting/BlacksmithTranslatableMessage.java @@ -130,7 +130,12 @@ public enum BlacksmithTranslatableMessage implements TranslatableMessage { /** * The marker used for displaying that a given setting has been overridden for the selected NPC */ - SETTING_OVERRIDDEN_MARKER; + SETTING_OVERRIDDEN_MARKER, + + /** + * The format to use for formatting any message spoken by a blacksmith NPC + */ + NPC_TALK_FORMAT; /** * Gets the message to display when displaying the raw value of messages diff --git a/src/main/resources/strings.yml b/src/main/resources/strings.yml index 31436c3..22bc6fc 100644 --- a/src/main/resources/strings.yml +++ b/src/main/resources/strings.yml @@ -18,6 +18,7 @@ en: INVALID_PRESET_OR_FILTER: "You specified an invalid preset or an invalid filter" PRESET_MATERIALS: "Materials in preset: {materials}" DURATION_FORMAT: "in {time} {unit}" + NPC_TALK_FORMAT: "&a[{npc}] -> You:&r {message}" UNIT_NOW: "imminently" UNIT_SECOND: "second" UNIT_SECONDS: "seconds"