Try to trim long displaynicks instead of blankly refusing to show them.

Will try trimming prefixes and dropping suffixes before trimming nicknames.
This commit is contained in:
KHobbits 2012-05-13 18:58:50 +01:00
parent a48f6c8c30
commit fee3d7c0d3
2 changed files with 44 additions and 32 deletions

View File

@ -263,75 +263,78 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
return teleportRequestHere;
}
public String getNick(final boolean addprefixsuffix)
public String getNick(final boolean longnick)
{
final StringBuilder nickname = new StringBuilder();
final StringBuilder prefix = new StringBuilder();
String nickname;
String suffix = "§f";
final String nick = getNickname();
if (ess.getSettings().isCommandDisabled("nick") || nick == null || nick.isEmpty() || nick.equals(getName()))
{
nickname.append(getName());
nickname = getName();
}
else
{
nickname.append(ess.getSettings().getNicknamePrefix()).append(nick);
nickname = ess.getSettings().getNicknamePrefix() + nick;
}
if (addprefixsuffix && isOp())
if (isOp())
{
try
{
final String opPrefix = ess.getSettings().getOperatorColor().toString();
if (opPrefix.length() > 0)
{
nickname.insert(0, opPrefix);
nickname.append("§f");
prefix.insert(0, opPrefix);
}
}
catch (Exception e)
{
}
}
if (addprefixsuffix && ess.getSettings().addPrefixSuffix())
if (ess.getSettings().addPrefixSuffix())
{
if (!ess.getSettings().disablePrefix())
{
final String prefix = ess.getPermissionsHandler().getPrefix(base).replace('&', '§');
nickname.insert(0, prefix);
final String ptext = ess.getPermissionsHandler().getPrefix(base).replace('&', '§');
prefix.insert(0, ptext);
}
if (!ess.getSettings().disableSuffix())
{
final String suffix = ess.getPermissionsHandler().getSuffix(base).replace('&', '§');
nickname.append(suffix);
if (suffix.length() < 2 || suffix.charAt(suffix.length() - 2) != '§')
final String stext = ess.getPermissionsHandler().getSuffix(base).replace('&', '§');
suffix = stext + "§f";
suffix = suffix.replace("§f§f", "§f");
}
}
final String strPrefix = prefix.toString();
String output = strPrefix + nickname + suffix;
if (!longnick && output.length() > 16)
{
nickname.append("§f");
output = strPrefix + nickname;
}
}
else
if (!longnick && output.length() > 16)
{
nickname.append("§f");
output = Util.lastCode(strPrefix) + nickname;
}
if (!longnick && output.length() > 16)
{
output = Util.lastCode(strPrefix) + nickname.substring(0, 14);
}
return nickname.toString();
if (output.charAt(output.length() - 1) == '§') {
output = output.substring(0, output.length() - 1);
}
return output;
}
public void setDisplayNick()
{
if (base.isOnline() && ess.getSettings().changeDisplayName())
{
String name = getNick(true);
setDisplayName(name);
if (name.length() > 16)
{
name = getNick(false);
}
if (name.length() > 16)
{
name = Util.stripFormat(name);
}
setDisplayName(getNick(true));
if (ess.getSettings().changePlayerListName())
{
String name = getNick(false);
try
{
setPlayerListName(name);

View File

@ -510,6 +510,15 @@ public class Util
}
return buf.toString();
}
public static String lastCode(final String input) {
int pos = input.lastIndexOf("§");
if (pos == -1 || (pos + 1) == input.length()) {
return "";
}
return input.substring(pos, pos + 2);
}
private static transient final Pattern URL_PATTERN = Pattern.compile("((?:(?:https?)://)?[\\w-_\\.]{2,})\\.([a-z]{2,3}(?:/\\S+)?)");
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])");