New permission essentials.nick.color

Allows control over who can use colour codes in nicknames.
This commit is contained in:
KHobbits 2011-11-23 22:24:31 +00:00
parent b35d5f30f9
commit af456a73dd

View File

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