diff options
author | KHobbits <rob@khobbits.co.uk> | 2011-11-23 22:24:31 +0000 |
---|---|---|
committer | KHobbits <rob@khobbits.co.uk> | 2011-11-23 22:24:31 +0000 |
commit | af456a73dd575d8ecb994e153c06c0f6ec1fdf5a (patch) | |
tree | 2f26d299df3316411bf3588d2de6d84f46f52225 | |
parent | b35d5f30f99a6bb29da61668633d3316dd621499 (diff) | |
download | Essentials-af456a73dd575d8ecb994e153c06c0f6ec1fdf5a.tar Essentials-af456a73dd575d8ecb994e153c06c0f6ec1fdf5a.tar.gz Essentials-af456a73dd575d8ecb994e153c06c0f6ec1fdf5a.tar.lz Essentials-af456a73dd575d8ecb994e153c06c0f6ec1fdf5a.tar.xz Essentials-af456a73dd575d8ecb994e153c06c0f6ec1fdf5a.zip |
New permission essentials.nick.color
Allows control over who can use colour codes in nicknames.
-rw-r--r-- | Essentials/src/com/earth2me/essentials/commands/Commandnick.java | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandnick.java b/Essentials/src/com/earth2me/essentials/commands/Commandnick.java index d4610f26c..a1f1c77ca 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandnick.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandnick.java @@ -32,11 +32,11 @@ public class Commandnick extends EssentialsCommand { throw new Exception(_("nickOthersPermission")); } - setNickname(server, getPlayer(server, args, 0), args[1]); + setNickname(server, getPlayer(server, args, 0), formatNickname(user, args[1])); user.sendMessage(_("nickChanged")); return; } - setNickname(server, user, args[0]); + setNickname(server, user, formatNickname(user, args[0])); } @Override @@ -50,10 +50,19 @@ public class Commandnick extends EssentialsCommand { throw new Exception(_("nickDisplayName")); } - setNickname(server, getPlayer(server, args, 0), args[1]); + setNickname(server, getPlayer(server, args, 0), formatNickname(null, args[1])); sender.sendMessage(_("nickChanged")); } + private String formatNickname(final User user, final String nick) + { + if (user == null || user.isAuthorized("essentials.nick.color")) + { + return nick.replace('&', '\u00a7').replace("\u00a7\u00a7", "&"); + } + return nick; + } + private void setNickname(final Server server, final User target, final String nick) throws Exception { if (nick.matches("[^a-zA-Z_0-9]")) @@ -68,7 +77,6 @@ public class Commandnick extends EssentialsCommand } else { - final String formattedNick = nick.replace('&', '\u00a7').replace("\u00a7\u00a7", "&"); for (Player p : server.getOnlinePlayers()) { if (target.getBase() == p) @@ -77,14 +85,14 @@ public class Commandnick extends EssentialsCommand } String dn = p.getDisplayName().toLowerCase(Locale.ENGLISH); String n = p.getName().toLowerCase(Locale.ENGLISH); - String nk = formattedNick.toLowerCase(Locale.ENGLISH); + String nk = nick.toLowerCase(Locale.ENGLISH); if (nk.equals(dn) || nk.equals(n)) { throw new Exception(_("nickInUse")); } } - target.setNickname(formattedNick); + target.setNickname(nick); target.setDisplayNick(); target.sendMessage(_("nickSet", target.getDisplayName() + "ยง7.")); } |