Compiled regex is faster.

This commit is contained in:
KHobbits 2012-01-18 23:35:30 +00:00
parent 36bc1adf83
commit a10f6850e5
5 changed files with 19 additions and 8 deletions

View File

@ -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");
}
}

View File

@ -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);

View File

@ -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");

View File

@ -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;
}

View File

@ -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
{