package net.knarcraft.blacksmith.util; import net.citizensnpcs.api.npc.NPC; import net.knarcraft.blacksmith.BlacksmithPlugin; import net.md_5.bungee.api.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; /** * A message formatter to ensure uniform colors and format of chat messages */ public final class MessageFormatter { private final static String pluginName = BlacksmithPlugin.getInstance().getDescription().getName(); private MessageFormatter() { } /** * Sends a message from a blacksmith NPC to a player * * @param npc

The NPC sending the message

* @param player

The player to send the message to

* @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 + " " + translateColors(message)); } /** * Displays a message signifying a successful action * * @param sender

The command sender to display the message to

* @param message

The raw message to display

*/ public static void displaySuccessMessage(CommandSender sender, String message) { sender.sendMessage(ChatColor.GREEN + getFormattedMessage(message)); } /** * Displays a message signifying an unsuccessful action * * @param sender

The command sender to display the message to

* @param message

The raw message to display

*/ public static void displayErrorMessage(CommandSender sender, String message) { sender.sendMessage(ChatColor.DARK_RED + getFormattedMessage(message)); } /** * Gets the formatted version of any chat message * * @param message

The message to format

* @return

The formatted message

*/ private static String getFormattedMessage(String message) { return "[" + pluginName + "] " + ChatColor.RESET + translateColors(message); } /** * Translates & color codes to proper colors * * @param input

The input string to translate colors for

* @return

The input with color codes translated

*/ private static String translateColors(String input) { return ChatColor.translateAlternateColorCodes('&', input); } }