summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2012-03-22 22:07:13 +0000
committerKHobbits <rob@khobbits.co.uk>2012-03-22 22:07:13 +0000
commit0dc1270aedb932d19d5c1c2e313c4f2fb099bbc0 (patch)
tree8be8ee7a650f6c8eb89f819bdc92070ea27a4d96
parentcd0d37f73c5d8f2e9990d96ff95eb04ab4322bd5 (diff)
downloadEssentials-0dc1270aedb932d19d5c1c2e313c4f2fb099bbc0.tar
Essentials-0dc1270aedb932d19d5c1c2e313c4f2fb099bbc0.tar.gz
Essentials-0dc1270aedb932d19d5c1c2e313c4f2fb099bbc0.tar.lz
Essentials-0dc1270aedb932d19d5c1c2e313c4f2fb099bbc0.tar.xz
Essentials-0dc1270aedb932d19d5c1c2e313c4f2fb099bbc0.zip
Split colour permissions into 3: color/magic/format
-rw-r--r--Essentials/src/com/earth2me/essentials/Settings.java4
-rw-r--r--Essentials/src/com/earth2me/essentials/User.java4
-rw-r--r--Essentials/src/com/earth2me/essentials/Util.java69
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandgive.java1
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandlist.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandmail.java4
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandme.java9
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandmsg.java11
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandnick.java10
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandping.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandr.java11
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandrealname.java4
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandwhois.java4
-rw-r--r--Essentials/src/com/earth2me/essentials/signs/SignBlockListener.java4
-rw-r--r--Essentials/src/com/earth2me/essentials/signs/SignProtection.java2
-rw-r--r--EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java9
17 files changed, 92 insertions, 60 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java
index f094dda6e..2aa1d93c1 100644
--- a/Essentials/src/com/earth2me/essentials/Settings.java
+++ b/Essentials/src/com/earth2me/essentials/Settings.java
@@ -327,7 +327,7 @@ public class Settings implements ISettings
{
String format = config.getString("chat.group-formats." + (group == null ? "Default" : group),
config.getString("chat.format", "&7[{GROUP}]&f {DISPLAYNAME}&7:&f {MESSAGE}"));
- format = Util.replaceColor(format);
+ format = Util.replaceFormat(format);
format = format.replace("{DISPLAYNAME}", "%1$s");
format = format.replace("{GROUP}", "{0}");
format = format.replace("{MESSAGE}", "%2$s");
@@ -349,7 +349,7 @@ public class Settings implements ISettings
@Override
public IText getAnnounceNewPlayerFormat()
{
- return new SimpleTextInput(Util.replaceColor(config.getString("newbies.announce-format", "&dWelcome {DISPLAYNAME} to the server!")));
+ return new SimpleTextInput(Util.replaceFormat(config.getString("newbies.announce-format", "&dWelcome {DISPLAYNAME} to the server!")));
}
@Override
diff --git a/Essentials/src/com/earth2me/essentials/User.java b/Essentials/src/com/earth2me/essentials/User.java
index 51e10dbf5..c4293cc63 100644
--- a/Essentials/src/com/earth2me/essentials/User.java
+++ b/Essentials/src/com/earth2me/essentials/User.java
@@ -194,7 +194,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
@Override
public int compareTo(final User other)
{
- return Util.stripColor(this.getDisplayName()).compareToIgnoreCase(Util.stripColor(other.getDisplayName()));
+ return Util.stripFormat(this.getDisplayName()).compareToIgnoreCase(Util.stripFormat(other.getDisplayName()));
}
@Override
@@ -326,7 +326,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
}
if (name.length() > 16)
{
- name = Util.stripColor(name);
+ name = Util.stripFormat(name);
}
try
{
diff --git a/Essentials/src/com/earth2me/essentials/Util.java b/Essentials/src/com/earth2me/essentials/Util.java
index fbb8deb08..7a6de8730 100644
--- a/Essentials/src/com/earth2me/essentials/Util.java
+++ b/Essentials/src/com/earth2me/essentials/Util.java
@@ -495,26 +495,83 @@ public class Util
}
return buf.toString();
}
- 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])");
+ private static transient final Pattern VANILLA_PATTERN = Pattern.compile("\u00A7+[0-9A-FK-ORa-fk-or]");
+ private static transient final Pattern REPLACE_PATTERN = Pattern.compile("&([0-9a-fk-or])");
+ private static transient final Pattern VANILLA_COLOR_PATTERN = Pattern.compile("\u00A7+[0-9A-Fa-f]");
+ private static transient final Pattern VANILLA_MAGIC_PATTERN = Pattern.compile("\u00A7+[Kk]");
+ private static transient final Pattern VANILLA_FORMAT_PATTERN = Pattern.compile("\u00A7+[L-ORl-or]");
+ private static transient final Pattern REPLACE_COLOR_PATTERN = Pattern.compile("&([0-9a-f])");
+ private static transient final Pattern REPLACE_MAGIC_PATTERN = Pattern.compile("&(k)");
+ private static transient final Pattern REPLACE_FORMAT_PATTERN = Pattern.compile("&([l-or])");
+
+ public static String stripFormat(final String input)
+ {
+ if (input == null)
+ {
+ return null;
+ }
+ return VANILLA_PATTERN.matcher(input).replaceAll("");
+ }
- public static String stripColor(final String input)
+ public static String replaceFormat(final String input)
{
if (input == null)
{
return null;
}
+ return REPLACE_PATTERN.matcher(input).replaceAll("");
+ }
- return VANILLA_COLOR_PATTERN.matcher(input).replaceAll("");
+ public static String blockURL(final String input)
+ {
+ if (input == null)
+ {
+ return null;
+ }
+ return input.replace(".", ". ").replace(". ", ". ");
}
- public static String replaceColor(final String input)
+ public static String formatString(final IUser user, final String permBase, final String input)
{
if (input == null)
{
return null;
}
+ String message;
+ if (user.isAuthorized(permBase + ".color"))
+ {
+ message = Util.replaceColor(input, REPLACE_COLOR_PATTERN);
+ }
+ else
+ {
+ message = Util.stripColor(input, VANILLA_COLOR_PATTERN);
+ }
+ if (user.isAuthorized(permBase + ".magic"))
+ {
+ message = Util.replaceColor(message, REPLACE_MAGIC_PATTERN);
+ }
+ else
+ {
+ message = Util.stripColor(message, VANILLA_MAGIC_PATTERN);
+ }
+ if (user.isAuthorized(permBase + ".format"))
+ {
+ message = Util.replaceColor(message, REPLACE_FORMAT_PATTERN);
+ }
+ else
+ {
+ message = Util.stripColor(message, VANILLA_FORMAT_PATTERN);
+ }
+ return message;
+ }
- return EASY_COLOR_PATTERN.matcher(input).replaceAll("\u00a7$1");
+ private static String stripColor(final String input, final Pattern pattern)
+ {
+ return pattern.matcher(input).replaceAll("");
+ }
+
+ private static String replaceColor(final String input, final Pattern pattern)
+ {
+ return pattern.matcher(input).replaceAll("\u00a7$1");
}
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java
index 9db7d4da3..701fa6577 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java
@@ -85,6 +85,7 @@ public class Commandgive extends EssentialsCommand
throw new Exception(_("cantSpawnItem", "Air"));
}
+ //TODO: TL this.
final String itemName = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace('_', ' ');
sender.sendMessage(ChatColor.BLUE + "Giving " + stack.getAmount() + " of " + itemName + " to " + giveTo.getDisplayName() + ".");
if (giveTo.isAuthorized("essentials.oversizedstacks"))
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java b/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java
index f26154f71..948cfa769 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java
@@ -23,7 +23,7 @@ public class Commandhelpop extends EssentialsCommand
throw new NotEnoughArgumentsException();
}
user.setDisplayNick();
- final String message = _("helpOp", user.getDisplayName(), Util.stripColor(getFinalArg(args, 0)));
+ final String message = _("helpOp", user.getDisplayName(), Util.stripFormat(getFinalArg(args, 0)));
logger.log(Level.INFO, message);
for (Player onlinePlayer : server.getOnlinePlayers())
{
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandlist.java b/Essentials/src/com/earth2me/essentials/commands/Commandlist.java
index 7e699328b..c981f45c1 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandlist.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandlist.java
@@ -75,7 +75,7 @@ public class Commandlist extends EssentialsCommand
for (String group : groups)
{
final StringBuilder groupString = new StringBuilder();
- groupString.append(_("listGroupTag", Util.replaceColor(group)));
+ groupString.append(_("listGroupTag", Util.replaceFormat(group)));
final List<User> users = sort.get(group);
Collections.sort(users);
boolean first = true;
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java
index abc551f58..fa4643875 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java
@@ -59,7 +59,7 @@ public class Commandmail extends EssentialsCommand
}
if (!u.isIgnoredPlayer(user.getName()))
{
- final String mail = Util.sanitizeString(Util.stripColor(getFinalArg(args, 2)));
+ final String mail = Util.sanitizeString(Util.stripFormat(getFinalArg(args, 2)));
u.addMail(user.getName() + ": " + mail);
}
user.sendMessage(_("mailSent"));
@@ -71,7 +71,7 @@ public class Commandmail extends EssentialsCommand
{
throw new Exception(_("noPerm", "essentials.mail.sendall"));
}
- ess.scheduleAsyncDelayedTask(new SendAll(user.getName() + ": " + Util.stripColor(getFinalArg(args, 1))));
+ ess.scheduleAsyncDelayedTask(new SendAll(user.getName() + ": " + Util.stripFormat(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 0bf2a536d..ec2857841 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandme.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandme.java
@@ -27,14 +27,7 @@ public class Commandme extends EssentialsCommand
}
String message = getFinalArg(args, 0);
- if (user.isAuthorized("essentials.chat.color"))
- {
- message = Util.replaceColor(message);
- }
- else
- {
- message = Util.stripColor(message);
- }
+ message = Util.formatString(user, "essentials.chat", message);
user.setDisplayNick();
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 128d8eeb5..8a6cdad32 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java
@@ -34,18 +34,11 @@ public class Commandmsg extends EssentialsCommand
{
throw new Exception(_("voiceSilenced"));
}
- if (user.isAuthorized("essentials.msg.color"))
- {
- message = Util.replaceColor(message);
- }
- else
- {
- message = Util.stripColor(message);
- }
+ message = Util.formatString(user, "essentials.msg", message);
}
else
{
- message = Util.replaceColor(message);
+ message = Util.replaceFormat(message);
}
final String translatedMe = _("me");
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandnick.java b/Essentials/src/com/earth2me/essentials/commands/Commandnick.java
index b9fbccb37..808e0be70 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandnick.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandnick.java
@@ -64,11 +64,13 @@ public class Commandnick extends EssentialsCommand
private String formatNickname(final User user, final String nick)
{
- if (user == null || user.isAuthorized("essentials.nick.color"))
+ if (user == null)
{
- return nick.replace('&', '\u00a7').replaceAll("\u00a7+k", "");
- } else {
- return Util.stripColor(nick);
+ return Util.replaceFormat(nick);
+ }
+ else
+ {
+ return Util.formatString(user, "essentials.nick", nick);
}
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandping.java b/Essentials/src/com/earth2me/essentials/commands/Commandping.java
index 0956f4082..43aa18d5f 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandping.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandping.java
@@ -23,7 +23,7 @@ public class Commandping extends EssentialsCommand
}
else
{
- sender.sendMessage(Util.replaceColor(getFinalArg(args, 0)));
+ sender.sendMessage(Util.replaceFormat(getFinalArg(args, 0)));
}
}
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandr.java b/Essentials/src/com/earth2me/essentials/commands/Commandr.java
index fe2a4e5b1..00072fded 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandr.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandr.java
@@ -32,20 +32,13 @@ public class Commandr extends EssentialsCommand
if (sender instanceof Player)
{
User user = ess.getUser(sender);
- if (user.isAuthorized("essentials.msg.color"))
- {
- message = Util.replaceColor(message);
- }
- else
- {
- message = Util.stripColor(message);
- }
+ message = Util.formatString(user, "essentials.msg", message);
replyTo = user;
senderName = user.getDisplayName();
}
else
{
- message = Util.replaceColor(message);
+ message = Util.replaceFormat(message);
replyTo = Console.getConsoleReplyTo();
senderName = Console.NAME;
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java b/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java
index 6f9049756..c99018211 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java
@@ -32,9 +32,9 @@ public class Commandrealname extends EssentialsCommand
continue;
}
u.setDisplayNick();
- final String displayName = Util.stripColor(u.getDisplayName()).toLowerCase(Locale.ENGLISH);
+ final String displayName = Util.stripFormat(u.getDisplayName()).toLowerCase(Locale.ENGLISH);
if (!whois.equals(displayName)
- && !displayName.equals(Util.stripColor(ess.getSettings().getNicknamePrefix()) + whois)
+ && !displayName.equals(Util.stripFormat(ess.getSettings().getNicknamePrefix()) + whois)
&& !whois.equalsIgnoreCase(u.getName()))
{
continue;
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java b/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java
index 4f1c2267a..6c7919163 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java
@@ -37,7 +37,7 @@ public class Commandwhois extends EssentialsCommand
showhidden = true;
}
final String whois = args[0].toLowerCase(Locale.ENGLISH);
- final int prefixLength = Util.stripColor(ess.getSettings().getNicknamePrefix()).length();
+ final int prefixLength = Util.stripFormat(ess.getSettings().getNicknamePrefix()).length();
for (Player onlinePlayer : server.getOnlinePlayers())
{
final User user = ess.getUser(onlinePlayer);
@@ -45,7 +45,7 @@ public class Commandwhois extends EssentialsCommand
{
continue;
}
- final String nickName = Util.stripColor(user.getNickname());
+ final String nickName = Util.stripFormat(user.getNickname());
if (!whois.equalsIgnoreCase(nickName)
&& !whois.substring(prefixLength).equalsIgnoreCase(nickName)
&& !whois.equalsIgnoreCase(user.getName()))
diff --git a/Essentials/src/com/earth2me/essentials/signs/SignBlockListener.java b/Essentials/src/com/earth2me/essentials/signs/SignBlockListener.java
index bd90d6c47..fc020aa88 100644
--- a/Essentials/src/com/earth2me/essentials/signs/SignBlockListener.java
+++ b/Essentials/src/com/earth2me/essentials/signs/SignBlockListener.java
@@ -88,14 +88,14 @@ public class SignBlockListener implements Listener
{
for (int i = 0; i < 4; i++)
{
- event.setLine(i, Util.replaceColor(event.getLine(i)));
+ event.setLine(i, Util.replaceFormat(event.getLine(i)));
}
}
else
{
for (int i = 0; i < 4; i++)
{
- event.setLine(i, Util.stripColor(event.getLine(i)));
+ event.setLine(i, Util.stripFormat(event.getLine(i)));
}
}
diff --git a/Essentials/src/com/earth2me/essentials/signs/SignProtection.java b/Essentials/src/com/earth2me/essentials/signs/SignProtection.java
index 088e74f01..2f2d25c46 100644
--- a/Essentials/src/com/earth2me/essentials/signs/SignProtection.java
+++ b/Essentials/src/com/earth2me/essentials/signs/SignProtection.java
@@ -147,7 +147,7 @@ public class SignProtection extends EssentialsSign
{
return SignProtectionState.OWNER;
}
- if (Util.stripColor(sign.getLine(3)).equalsIgnoreCase(username))
+ if (Util.stripFormat(sign.getLine(3)).equalsIgnoreCase(username))
{
return SignProtectionState.OWNER;
}
diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java
index 5a8cde62d..2c0906cbf 100644
--- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java
+++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java
@@ -37,14 +37,7 @@ public class EssentialsChatPlayerListenerLowest extends EssentialsChatPlayer
/**
* This listener should apply the general chat formatting only...then return control back the event handler
*/
- if (user.isAuthorized("essentials.chat.color"))
- {
- event.setMessage(Util.replaceColor(event.getMessage()));
- }
- else
- {
- event.setMessage(Util.stripColor(event.getMessage()));
- }
+ event.setMessage(Util.formatString(user, "essentials.chat", event.getMessage()));
String group = user.getGroup();
String world = user.getWorld().getName();
event.setFormat(ess.getSettings().getChatFormat(group).format(new Object[] {group, world, world.substring(0, 1).toUpperCase(Locale.ENGLISH)}));