mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-05-07 00:00:45 +00:00
Trim long nicknames for use in tab list
Colour Nicknames Refactor /nick Command Fix nickother validity checks.
This commit is contained in:
parent
d264c26310
commit
d171cce45d
2 changed files with 37 additions and 60 deletions
|
@ -285,11 +285,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||||
public void setDisplayNick(String name)
|
public void setDisplayNick(String name)
|
||||||
{
|
{
|
||||||
setDisplayName(name);
|
setDisplayName(name);
|
||||||
//TODO: Maybe we need to limit nick length, or try use a string trim.
|
setPlayerListName(name.length() > 16 ? name.substring(0, 16) : name);
|
||||||
if (name.length() <= 16)
|
|
||||||
{
|
|
||||||
setPlayerListName(name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -15,85 +15,51 @@ public class Commandnick extends EssentialsCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(Server server, User user, String commandLabel, String[] args) throws Exception
|
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
||||||
{
|
{
|
||||||
if (args.length < 1)
|
if (args.length < 1)
|
||||||
{
|
{
|
||||||
throw new NotEnoughArgumentsException();
|
throw new NotEnoughArgumentsException();
|
||||||
}
|
}
|
||||||
|
if (!ess.getSettings().changeDisplayName())
|
||||||
if (!ess.getSettings().changeDisplayName()) {
|
{
|
||||||
throw new Exception(Util.i18n("nickDisplayName"));
|
throw new Exception(Util.i18n("nickDisplayName"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length > 1)
|
if (args.length > 1)
|
||||||
{
|
{
|
||||||
if (!user.isAuthorized("essentials.nick.others"))
|
if (!user.isAuthorized("essentials.nick.others"))
|
||||||
{
|
{
|
||||||
throw new Exception(Util.i18n("nickOthersPermission"));
|
throw new Exception(Util.i18n("nickOthersPermission"));
|
||||||
}
|
}
|
||||||
|
setNickname(server, getPlayer(server, args, 0), args[1]);
|
||||||
setOthersNickname(server, user, args);
|
user.sendMessage(Util.i18n("nickChanged"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
setNickname(server, user, args[0]);
|
||||||
|
|
||||||
String nick = args[0];
|
|
||||||
if ("off".equalsIgnoreCase(nick) || user.getName().equalsIgnoreCase(nick))
|
|
||||||
{
|
|
||||||
user.setDisplayNick(user.getName());
|
|
||||||
user.setNickname(null);
|
|
||||||
user.sendMessage(Util.i18n("nickNoMore"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nick.matches("[^a-zA-Z_0-9]"))
|
|
||||||
{
|
|
||||||
throw new Exception(Util.i18n("nickNamesAlpha"));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Player p : server.getOnlinePlayers())
|
|
||||||
{
|
|
||||||
if (user == p)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
String dn = p.getDisplayName().toLowerCase();
|
|
||||||
String n = p.getName().toLowerCase();
|
|
||||||
String nk = nick.toLowerCase();
|
|
||||||
if (nk.equals(dn) || nk.equals(n))
|
|
||||||
{
|
|
||||||
throw new Exception(Util.i18n("nickInUse"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
user.setDisplayNick(ess.getSettings().getNicknamePrefix() + nick);
|
|
||||||
user.setNickname(nick);
|
|
||||||
user.sendMessage(Util.format("nickSet", user.getDisplayName() + "§7."));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
|
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
||||||
{
|
{
|
||||||
if (args.length < 2)
|
if (args.length < 2)
|
||||||
{
|
{
|
||||||
throw new NotEnoughArgumentsException();
|
throw new NotEnoughArgumentsException();
|
||||||
}
|
}
|
||||||
|
if (!ess.getSettings().changeDisplayName())
|
||||||
if (!ess.getSettings().changeDisplayName()) {
|
|
||||||
sender.sendMessage(Util.i18n("nickDisplayName"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setOthersNickname(server, sender, args);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setOthersNickname(Server server, CommandSender sender, String[] args) throws Exception
|
|
||||||
{
|
{
|
||||||
User target = getPlayer(server, args, 0);
|
throw new Exception(Util.i18n("nickDisplayName"));
|
||||||
String nick = args[1];
|
}
|
||||||
if ("off".equalsIgnoreCase(nick) || target.getName().equalsIgnoreCase(nick))
|
setNickname(server, getPlayer(server, args, 0), args[1]);
|
||||||
|
sender.sendMessage(Util.i18n("nickChanged"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setNickname(final Server server, final User target, final String nick) throws Exception
|
||||||
|
{
|
||||||
|
if (nick.matches("[^a-zA-Z_0-9]"))
|
||||||
|
{
|
||||||
|
throw new Exception(Util.i18n("nickNamesAlpha"));
|
||||||
|
}
|
||||||
|
else if ("off".equalsIgnoreCase(nick) || target.getName().equalsIgnoreCase(nick))
|
||||||
{
|
{
|
||||||
target.setDisplayNick(target.getName());
|
target.setDisplayNick(target.getName());
|
||||||
target.setNickname(null);
|
target.setNickname(null);
|
||||||
|
@ -101,10 +67,25 @@ public class Commandnick extends EssentialsCommand
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
target.setDisplayNick(ess.getSettings().getNicknamePrefix() + nick);
|
final String formattedNick = nick.replace('&', '§').replace('§§', '&');
|
||||||
target.setNickname(nick);
|
for (Player p : server.getOnlinePlayers())
|
||||||
|
{
|
||||||
|
if (target.getBase() == p)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String dn = p.getDisplayName().toLowerCase();
|
||||||
|
String n = p.getName().toLowerCase();
|
||||||
|
String nk = formattedNick.toLowerCase();
|
||||||
|
if (nk.equals(dn) || nk.equals(n))
|
||||||
|
{
|
||||||
|
throw new Exception(Util.i18n("nickInUse"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
target.setDisplayNick(ess.getSettings().getNicknamePrefix() + formattedNick);
|
||||||
|
target.setNickname(formattedNick);
|
||||||
target.sendMessage(Util.format("nickSet", target.getDisplayName() + "§7."));
|
target.sendMessage(Util.format("nickSet", target.getDisplayName() + "§7."));
|
||||||
}
|
}
|
||||||
sender.sendMessage(Util.i18n("nickChanged"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue