From 1f2c669eca786debc3ee5ee8a3de5ad98bd6470a Mon Sep 17 00:00:00 2001 From: KHobbits Date: Mon, 16 Jan 2012 20:25:36 +0000 Subject: Stripping vanilla colour from /helpop and /mail Adding support for &k in EssChat Adding support for colour in /msg and /r - New perm: essentials.msg.color --- .../essentials/commands/Commandhelpop.java | 3 ++- .../earth2me/essentials/commands/Commandmail.java | 5 ++-- .../earth2me/essentials/commands/Commandme.java | 7 +++++- .../earth2me/essentials/commands/Commandmsg.java | 14 ++++++++++- .../com/earth2me/essentials/commands/Commandr.java | 29 +++++++++++++++++++--- .../chat/EssentialsChatPlayerListenerLowest.java | 2 +- 6 files changed, 51 insertions(+), 9 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java b/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java index f558a1b52..20cd5cdd3 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java @@ -2,6 +2,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; +import com.earth2me.essentials.Util; import java.util.logging.Level; import org.bukkit.Server; import org.bukkit.entity.Player; @@ -22,7 +23,7 @@ public class Commandhelpop extends EssentialsCommand throw new NotEnoughArgumentsException(); } - final String message = _("helpOp", user.getDisplayName(), getFinalArg(args, 0)); + final String message = _("helpOp", user.getDisplayName(), Util.stripColor(getFinalArg(args, 0))); logger.log(Level.INFO, message); for (Player onlinePlayer : server.getOnlinePlayers()) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java index 6a66186e7..4a9928b85 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java @@ -2,6 +2,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; +import com.earth2me.essentials.Util; import java.util.List; import org.bukkit.ChatColor; import org.bukkit.Server; @@ -58,7 +59,7 @@ public class Commandmail extends EssentialsCommand } if (!u.isIgnoredPlayer(user.getName())) { - u.addMail(user.getName() + ": " + getFinalArg(args, 2)); + u.addMail(user.getName() + ": " + Util.stripColor(getFinalArg(args, 2))); } user.sendMessage(_("mailSent")); return; @@ -69,7 +70,7 @@ public class Commandmail extends EssentialsCommand { throw new Exception(_("noPerm","essentials.mail.sendall")); } - ess.scheduleAsyncDelayedTask(new SendAll(user.getName() + ": " + getFinalArg(args, 1))); + ess.scheduleAsyncDelayedTask(new SendAll(user.getName() + ": " + Util.stripColor(getFinalArg(args, 1)))); user.sendMessage(_("mailSent")); return; } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandme.java b/Essentials/src/com/earth2me/essentials/commands/Commandme.java index 7ae87251d..3cdddf99c 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandme.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandme.java @@ -2,6 +2,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; +import com.earth2me.essentials.Util; import org.bukkit.Server; @@ -28,8 +29,12 @@ public class Commandme extends EssentialsCommand String message = getFinalArg(args, 0); if (user.isAuthorized("essentials.chat.color")) { - message = message.replaceAll("&([0-9a-f])", "§$1"); + message = message.replaceAll("&([0-9a-fk])", "§$1"); } + else { + message = Util.stripColor(message); + } + ess.broadcastMessage(user, _("action", user.getDisplayName(), message)); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java b/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java index 63bce435a..de4b921e6 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java @@ -26,6 +26,7 @@ public class Commandmsg extends EssentialsCommand throw new NotEnoughArgumentsException(); } + String message = getFinalArg(args, 1); if (sender instanceof Player) { User user = ess.getUser(sender); @@ -33,9 +34,20 @@ public class Commandmsg extends EssentialsCommand { throw new Exception(_("voiceSilenced")); } + if (user.isAuthorized("essentials.msg.color")) + { + message = message.replaceAll("&([0-9a-fk])", "§$1"); + } + else + { + message = Util.stripColor(message); + } + } + else + { + message = message.replaceAll("&([0-9a-fk])", "§$1"); } - final String message = Util.stripColor(getFinalArg(args, 1)); final String translatedMe = _("me"); final IReplyTo replyTo = sender instanceof Player ? ess.getUser((Player)sender) : Console.getConsoleReplyTo(); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandr.java b/Essentials/src/com/earth2me/essentials/commands/Commandr.java index 1da198444..9e30225ac 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandr.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandr.java @@ -4,6 +4,7 @@ import com.earth2me.essentials.Console; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.IReplyTo; import com.earth2me.essentials.User; +import com.earth2me.essentials.Util; import org.bukkit.Server; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -24,9 +25,31 @@ public class Commandr extends EssentialsCommand throw new NotEnoughArgumentsException(); } - final String message = getFinalArg(args, 0); - final IReplyTo replyTo = sender instanceof Player ? ess.getUser((Player)sender) : Console.getConsoleReplyTo(); - final String senderName = sender instanceof Player ? ((Player)sender).getDisplayName() : Console.NAME; + String message = getFinalArg(args, 0); + IReplyTo replyTo; + String senderName; + + if (sender instanceof Player) + { + User user = ess.getUser(sender); + if (user.isAuthorized("essentials.msg.color")) + { + message = message.replaceAll("&([0-9a-fk])", "§$1"); + } + else + { + message = Util.stripColor(message); + } + replyTo = user; + senderName = user.getDisplayName(); + } + else + { + message = message.replaceAll("&([0-9a-fk])", "§$1"); + replyTo = Console.getConsoleReplyTo(); + senderName = Console.NAME; + } + final CommandSender target = replyTo.getReplyTo(); final String targetName = target instanceof Player ? ((Player)target).getDisplayName() : Console.NAME; diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java index 82241a1f5..5c674d05d 100644 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java +++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java @@ -32,7 +32,7 @@ public class EssentialsChatPlayerListenerLowest extends EssentialsChatPlayer final User user = ess.getUser(event.getPlayer()); if (user.isAuthorized("essentials.chat.color")) { - event.setMessage(event.getMessage().replaceAll("&([0-9a-f])", "\u00a7$1")); + event.setMessage(event.getMessage().replaceAll("&([0-9a-fk])", "\u00a7$1")); } else { event.setMessage(Util.stripColor(event.getMessage())); } -- cgit v1.2.3