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 playerThe player to send the message to
* @param messageThe 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 senderThe command sender to display the message to
* @param messageThe 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 senderThe command sender to display the message to
* @param messageThe 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 messageThe message to format
* @returnThe formatted message
*/ private static String getFormattedMessage(String message) { return "[" + pluginName + "] " + ChatColor.RESET + translateColors(message); } /** * Translates & color codes to proper colors * * @param inputThe input string to translate colors for
* @returnThe input with color codes translated
*/ private static String translateColors(String input) { return ChatColor.translateAlternateColorCodes('&', input); } }