From e6625fd37907497d4c69e71e839f58070b4b205b Mon Sep 17 00:00:00 2001 From: Pepich Date: Fri, 5 May 2017 10:23:30 +0200 Subject: [PATCH] Moved colorify method into Utils class --- src/com/redstoner/misc/Utils.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/com/redstoner/misc/Utils.java b/src/com/redstoner/misc/Utils.java index 3a51344..ee9a67d 100644 --- a/src/com/redstoner/misc/Utils.java +++ b/src/com/redstoner/misc/Utils.java @@ -16,7 +16,7 @@ import net.md_5.bungee.api.ChatColor; /** The utils class containing utility functions. Those include but are not limited to sending formatted messages, broadcasts and more. * * @author Pepich */ -@Version(major = 1, minor = 3, revision = 0, compatible = 1) +@Version(major = 1, minor = 3, revision = 1, compatible = 1) public final class Utils { /** The SimpleDateFormat used for getting the current date. */ @@ -258,4 +258,20 @@ public final class Utils else return "&9" + sender.getName(); } + + /** This method "colorifies" a message using proper permissions. + * + * @param message the message to be colored. + * @param sender the command sender whose permissions shall be applied. + * @return the colorified message. */ + public static String colorify(String message, CommandSender sender) + { + if (sender.hasPermission("essentials.chat.color")) + message = message.replaceAll("&([0-9a-fA-FrR])", "§$1"); + if (sender.hasPermission("essentials.chat.format")) + message = message.replaceAll("&(l-oL-OrR)", "§$1"); + if (sender.hasPermission("essentials.chat.magic")) + message = message.replaceAll("&([kKrR])", "§$1"); + return message.replace("&§", "&"); + } }