Fix long prefix breaking setPlayerListName(), because they are too long.

If Essentials detects, that the player name would be too long with prefix and suffix to fit in the player list, it will only update the name without prefix and suffix but with nickname and opcolor.
This commit is contained in:
snowleo 2011-11-20 16:43:38 +01:00
parent 6633b39954
commit 14cc499421
4 changed files with 18 additions and 13 deletions

View File

@ -39,7 +39,7 @@ public class EssentialsPlayerListener extends PlayerListener
updateCompass(user);
if (ess.getSettings().changeDisplayName())
{
user.setDisplayNick(user.getNick());
user.setDisplayNick();
}
}
@ -65,7 +65,7 @@ public class EssentialsPlayerListener extends PlayerListener
user.updateActivity(true);
if (ess.getSettings().changeDisplayName())
{
user.setDisplayNick(user.getNick());
user.setDisplayNick();
}
}
@ -155,7 +155,7 @@ public class EssentialsPlayerListener extends PlayerListener
if (ess.getSettings().changeDisplayName())
{
user.setDisplayNick(user.getNick());
user.setDisplayNick();
}
user.setLastLoginAddress(user.getAddress().getAddress().getHostAddress());
user.updateActivity(false);
@ -248,7 +248,7 @@ public class EssentialsPlayerListener extends PlayerListener
final User user = ess.getUser(event.getPlayer());
if (ess.getSettings().changeDisplayName())
{
user.setDisplayNick(user.getNick());
user.setDisplayNick();
}
updateCompass(user);
}

View File

@ -235,7 +235,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
return teleportRequestHere;
}
public String getNick()
public String getNick(boolean addprefixsuffix)
{
final StringBuilder nickname = new StringBuilder();
final String nick = getNickname();
@ -259,7 +259,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
}
}
if (ess.getSettings().addPrefixSuffix())
if (addprefixsuffix && ess.getSettings().addPrefixSuffix())
{
if (!ess.getSettings().disablePrefix())
{
@ -284,10 +284,15 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
return nickname.toString();
}
public void setDisplayNick(String name)
public void setDisplayNick()
{
String name = getNick(true);
setDisplayName(name);
if (name.length() > 16)
{
name = getNick(false);
}
if (name.length() > 16)
{
name = name.substring(0, name.charAt(15) == '§' ? 15 : 16);
}
@ -306,7 +311,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
{
if (!(base instanceof OfflinePlayer) && ess.getSettings().changeDisplayName())
{
setDisplayNick(getNick());
setDisplayNick();
}
return super.getDisplayName() == null ? super.getName() : super.getDisplayName();
}

View File

@ -61,8 +61,8 @@ public class Commandnick extends EssentialsCommand
}
else if ("off".equalsIgnoreCase(nick) || target.getName().equalsIgnoreCase(nick))
{
target.setDisplayNick(target.getName());
target.setNickname(null);
target.setDisplayNick();
target.sendMessage(Util.i18n("nickNoMore"));
}
else
@ -83,8 +83,8 @@ public class Commandnick extends EssentialsCommand
}
}
target.setDisplayNick(ess.getSettings().getNicknamePrefix() + formattedNick);
target.setNickname(formattedNick);
target.setDisplayNick();
target.sendMessage(Util.format("nickSet", target.getDisplayName() + "§7."));
}
}

View File

@ -43,9 +43,9 @@ public class Commandwhois extends EssentialsCommand
{
continue;
}
final String displayName = ChatColor.stripColor(user.getNick());
if (!whois.equalsIgnoreCase(displayName)
&& !whois.equalsIgnoreCase(displayName.substring(prefixLength))
final String nickName = ChatColor.stripColor(user.getNickname());
if (!whois.equalsIgnoreCase(nickName)
&& !whois.substring(prefixLength).equalsIgnoreCase(nickName)
&& !whois.equalsIgnoreCase(user.getName()))
{
continue;