From fb5ebdb0c27663cef9dc59c8852a427fda411e9c Mon Sep 17 00:00:00 2001 From: Johnny Cao Date: Mon, 29 Jan 2018 10:01:20 -0800 Subject: [PATCH] Fixes #1637: Correctly handle /mail permissions (#1743) @AgentTroll Fixes #1637 /mail stripped colors from the entire message before as reported by the issue. The desired fix was to only strip the color from the sent message rather than from the entire message format (e.g. prefixes coming before the message itself). Fixed by formatting only the message before passing it to the localization. Also had a minor issue with FormatUtil in which it failed to strip ampersand (&)-formatted color codes, which was amended by stripping both VANILLA_*_PATTERN as well as REPLACE_*_PATTERN in FormatUtil#formatString(...). It's not necessary to actualy strip any vanilla (i.e. section-prefixed) color codes since that's already done by FormatUtil#stripFormat(String), but I'd like to keep the changes as non-invasive as possible at the current moment. Demo: git-Spigot-d20369f-7fc5cd8 (MC: 1.9) (Implementing API version 1.9-R0.1-SNAPSHOT) https://streamable.com/umyi8 This is my first time contributing so please be gentle :) --- .../src/com/earth2me/essentials/commands/Commandmail.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java index 526829881..f95458303 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java @@ -56,8 +56,7 @@ public class Commandmail extends EssentialsCommand { throw new Exception(tl("playerNeverOnServer", args[1])); } - String mail = tl("mailFormat", user.getName(), StringUtil.sanitizeString(FormatUtil.stripFormat(getFinalArg(args, 2)))); - mail = FormatUtil.formatMessage(user, "essentials.mail", mail); + String mail = tl("mailFormat", user.getName(), FormatUtil.formatMessage(user, "essentials.mail", StringUtil.sanitizeString(FormatUtil.stripFormat(getFinalArg(args, 2))))); if (mail.length() > 1000) { throw new Exception(tl("mailTooLong")); }