diff options
author | KHobbits <rob@khobbits.co.uk> | 2012-01-18 23:35:30 +0000 |
---|---|---|
committer | KHobbits <rob@khobbits.co.uk> | 2012-01-18 23:35:30 +0000 |
commit | a10f6850e52c1a83530591fdfb77bc37aea604ff (patch) | |
tree | 797854acb58a65bbee8fca149e622fd6a6a15c99 | |
parent | 36bc1adf8334d64f6a8dfb96107b32758d3ac1fa (diff) | |
download | Essentials-a10f6850e52c1a83530591fdfb77bc37aea604ff.tar Essentials-a10f6850e52c1a83530591fdfb77bc37aea604ff.tar.gz Essentials-a10f6850e52c1a83530591fdfb77bc37aea604ff.tar.lz Essentials-a10f6850e52c1a83530591fdfb77bc37aea604ff.tar.xz Essentials-a10f6850e52c1a83530591fdfb77bc37aea604ff.zip |
Compiled regex is faster.
5 files changed, 19 insertions, 8 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Util.java b/Essentials/src/com/earth2me/essentials/Util.java index eeb2dd6d6..20b29c296 100644 --- a/Essentials/src/com/earth2me/essentials/Util.java +++ b/Essentials/src/com/earth2me/essentials/Util.java @@ -478,7 +478,8 @@ public class Util } return buf.toString(); } - private static transient final Pattern COLOR_PATTERN = Pattern.compile("\u00A7+[0-9A-FKa-fk]"); + private static transient final Pattern VANILLA_COLOR_PATTERN = Pattern.compile("\u00A7+[0-9A-FKa-fk]"); + private static transient final Pattern EASY_COLOR_PATTERN = Pattern.compile("&([0-9a-fk])"); public static String stripColor(final String input) { @@ -487,6 +488,16 @@ public class Util return null; } - return COLOR_PATTERN.matcher(input).replaceAll(""); + return VANILLA_COLOR_PATTERN.matcher(input).replaceAll(""); + } + + public static String replaceColor(final String input) + { + if (input == null) + { + return null; + } + + return EASY_COLOR_PATTERN.matcher(input).replaceAll("\u00a7$1"); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandme.java b/Essentials/src/com/earth2me/essentials/commands/Commandme.java index 3cdddf99c..1530f3ad7 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandme.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandme.java @@ -29,7 +29,7 @@ public class Commandme extends EssentialsCommand String message = getFinalArg(args, 0); if (user.isAuthorized("essentials.chat.color")) { - message = message.replaceAll("&([0-9a-fk])", "§$1"); + message = Util.replaceColor(message); } else { message = Util.stripColor(message); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java b/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java index de4b921e6..128d8eeb5 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java @@ -36,7 +36,7 @@ public class Commandmsg extends EssentialsCommand } if (user.isAuthorized("essentials.msg.color")) { - message = message.replaceAll("&([0-9a-fk])", "§$1"); + message = Util.replaceColor(message); } else { @@ -45,7 +45,7 @@ public class Commandmsg extends EssentialsCommand } else { - message = message.replaceAll("&([0-9a-fk])", "§$1"); + message = Util.replaceColor(message); } final String translatedMe = _("me"); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandr.java b/Essentials/src/com/earth2me/essentials/commands/Commandr.java index 9e30225ac..7ef012d0d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandr.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandr.java @@ -34,7 +34,7 @@ public class Commandr extends EssentialsCommand User user = ess.getUser(sender); if (user.isAuthorized("essentials.msg.color")) { - message = message.replaceAll("&([0-9a-fk])", "§$1"); + message = Util.replaceColor(message); } else { @@ -45,7 +45,7 @@ public class Commandr extends EssentialsCommand } else { - message = message.replaceAll("&([0-9a-fk])", "§$1"); + message = Util.replaceColor(message); replyTo = Console.getConsoleReplyTo(); senderName = Console.NAME; } diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java index afb0c2dfd..9419416b0 100644 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java +++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java @@ -36,7 +36,7 @@ public class EssentialsChatPlayerListenerLowest extends EssentialsChatPlayer */ if (user.isAuthorized("essentials.chat.color")) { - event.setMessage(event.getMessage().replaceAll("&([0-9a-fk])", "\u00a7$1")); + event.setMessage(Util.replaceColor(event.getMessage())); } else { |