mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-02-10 01:11:22 +01:00
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:
parent
a48f6c8c30
commit
fee3d7c0d3
@ -263,75 +263,78 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
|||||||
return teleportRequestHere;
|
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();
|
final String nick = getNickname();
|
||||||
if (ess.getSettings().isCommandDisabled("nick") || nick == null || nick.isEmpty() || nick.equals(getName()))
|
if (ess.getSettings().isCommandDisabled("nick") || nick == null || nick.isEmpty() || nick.equals(getName()))
|
||||||
{
|
{
|
||||||
nickname.append(getName());
|
nickname = getName();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
nickname.append(ess.getSettings().getNicknamePrefix()).append(nick);
|
nickname = ess.getSettings().getNicknamePrefix() + nick;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (addprefixsuffix && isOp())
|
if (isOp())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
final String opPrefix = ess.getSettings().getOperatorColor().toString();
|
final String opPrefix = ess.getSettings().getOperatorColor().toString();
|
||||||
if (opPrefix.length() > 0)
|
if (opPrefix.length() > 0)
|
||||||
{
|
{
|
||||||
nickname.insert(0, opPrefix);
|
prefix.insert(0, opPrefix);
|
||||||
nickname.append("§f");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (addprefixsuffix && ess.getSettings().addPrefixSuffix())
|
|
||||||
|
if (ess.getSettings().addPrefixSuffix())
|
||||||
{
|
{
|
||||||
if (!ess.getSettings().disablePrefix())
|
if (!ess.getSettings().disablePrefix())
|
||||||
{
|
{
|
||||||
final String prefix = ess.getPermissionsHandler().getPrefix(base).replace('&', '§');
|
final String ptext = ess.getPermissionsHandler().getPrefix(base).replace('&', '§');
|
||||||
nickname.insert(0, prefix);
|
prefix.insert(0, ptext);
|
||||||
}
|
}
|
||||||
if (!ess.getSettings().disableSuffix())
|
if (!ess.getSettings().disableSuffix())
|
||||||
{
|
{
|
||||||
final String suffix = ess.getPermissionsHandler().getSuffix(base).replace('&', '§');
|
final String stext = ess.getPermissionsHandler().getSuffix(base).replace('&', '§');
|
||||||
nickname.append(suffix);
|
suffix = stext + "§f";
|
||||||
if (suffix.length() < 2 || suffix.charAt(suffix.length() - 2) != '§')
|
suffix = suffix.replace("§f§f", "§f");
|
||||||
{
|
|
||||||
nickname.append("§f");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
nickname.append("§f");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
final String strPrefix = prefix.toString();
|
||||||
return nickname.toString();
|
String output = strPrefix + nickname + suffix;
|
||||||
|
if (!longnick && output.length() > 16)
|
||||||
|
{
|
||||||
|
output = strPrefix + nickname;
|
||||||
|
}
|
||||||
|
if (!longnick && output.length() > 16)
|
||||||
|
{
|
||||||
|
output = Util.lastCode(strPrefix) + nickname;
|
||||||
|
}
|
||||||
|
if (!longnick && output.length() > 16)
|
||||||
|
{
|
||||||
|
output = Util.lastCode(strPrefix) + nickname.substring(0, 14);
|
||||||
|
}
|
||||||
|
if (output.charAt(output.length() - 1) == '§') {
|
||||||
|
output = output.substring(0, output.length() - 1);
|
||||||
|
}
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDisplayNick()
|
public void setDisplayNick()
|
||||||
{
|
{
|
||||||
if (base.isOnline() && ess.getSettings().changeDisplayName())
|
if (base.isOnline() && ess.getSettings().changeDisplayName())
|
||||||
{
|
{
|
||||||
String name = getNick(true);
|
setDisplayName(getNick(true));
|
||||||
setDisplayName(name);
|
|
||||||
if (name.length() > 16)
|
|
||||||
{
|
|
||||||
name = getNick(false);
|
|
||||||
}
|
|
||||||
if (name.length() > 16)
|
|
||||||
{
|
|
||||||
name = Util.stripFormat(name);
|
|
||||||
}
|
|
||||||
if (ess.getSettings().changePlayerListName())
|
if (ess.getSettings().changePlayerListName())
|
||||||
{
|
{
|
||||||
|
String name = getNick(false);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
setPlayerListName(name);
|
setPlayerListName(name);
|
||||||
|
@ -510,6 +510,15 @@ public class Util
|
|||||||
}
|
}
|
||||||
return buf.toString();
|
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 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 VANILLA_PATTERN = Pattern.compile("\u00A7+[0-9A-FK-ORa-fk-or]");
|
||||||
private static transient final Pattern REPLACE_PATTERN = Pattern.compile("&([0-9a-fk-or])");
|
private static transient final Pattern REPLACE_PATTERN = Pattern.compile("&([0-9a-fk-or])");
|
||||||
|
Loading…
Reference in New Issue
Block a user