Add prefix/suffix toggle for playerlist. Resolves #771

This commit adds two new configurable options:
- `add-prefix-in-playerlist`: enable prefix in playerlist
- `add-suffix-in-playerlist`: enable suffix in playerlist

These were added to prevent very long names in the playerlist.
This commit is contained in:
Ali Moghnieh 2016-07-28 17:17:26 +01:00
parent 30d5fbdf8d
commit 63b5cb9ec7
No known key found for this signature in database
GPG Key ID: F09D3A1BAF2E6D70
4 changed files with 31 additions and 3 deletions

View File

@ -269,4 +269,8 @@ public interface ISettings extends IConf {
boolean isPastebinCreateKit();
boolean isAllowBulkBuySell();
boolean isAddingPrefixInPlayerlist();
boolean isAddingSuffixInPlayerlist();
}

View File

@ -1364,4 +1364,14 @@ public class Settings implements net.ess3.api.ISettings {
public boolean isAllowBulkBuySell() {
return config.getBoolean("allow-bulk-buy-sell", false);
}
@Override
public boolean isAddingPrefixInPlayerlist() {
return config.getBoolean("add-prefix-in-playerlist", false);
}
@Override
public boolean isAddingSuffixInPlayerlist() {
return config.getBoolean("add-suffix-in-playerlist", false);
}
}

View File

@ -253,6 +253,10 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
}
public String getNick(final boolean longnick) {
return getNick(longnick, true, true);
}
public String getNick(final boolean longnick, final boolean withPrefix, final boolean withSuffix) {
final StringBuilder prefix = new StringBuilder();
String nickname;
String suffix = "";
@ -279,12 +283,12 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
if (ess.getSettings().addPrefixSuffix()) {
//These two extra toggles are not documented, because they are mostly redundant #EasterEgg
if (!ess.getSettings().disablePrefix()) {
if (withPrefix || !ess.getSettings().disablePrefix()) {
final String ptext = ess.getPermissionsHandler().getPrefix(base).replace('&', '§');
prefix.insert(0, ptext);
suffix = "§r";
}
if (!ess.getSettings().disableSuffix()) {
if (withSuffix || !ess.getSettings().disableSuffix()) {
final String stext = ess.getPermissionsHandler().getSuffix(base).replace('&', '§');
suffix = stext + "§r";
suffix = suffix.replace("§f§f", "§f").replace("§f§r", "§r").replace("§r§r", "§r");
@ -314,7 +318,7 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
// 1.8 enabled player list-names longer than 16 characters.
// If the server is on 1.8 or higher, provide that functionality. Otherwise, keep prior functionality.
boolean higherOrEqualTo1_8 = ReflUtil.getNmsVersionObject().isHigherThanOrEqualTo(ReflUtil.V1_8_R1);
String name = getNick(higherOrEqualTo1_8);
String name = getNick(higherOrEqualTo1_8, ess.getSettings().isAddingPrefixInPlayerlist(), ess.getSettings().isAddingSuffixInPlayerlist());
try {
this.getBase().setPlayerListName(name);
} catch (IllegalArgumentException e) {

View File

@ -45,6 +45,16 @@ change-displayname: true
# Do not edit this setting unless you know what you are doing!
#add-prefix-suffix: false
# When this option is enabled, player prefixes will be shown in the playerlist.
# This feature only works for Minecraft version 1.8 and higher.
# This value of change-playerlist has to be true
#add-prefix-in-playerlist: true
# When this option is enabled, player suffixes will be shown in the playerlist.
# This feature only works for Minecraft version 1.8 and higher.
# This value of change-playerlist has to be true
#add-suffix-in-playerlist: true
# If the teleport destination is unsafe, should players be teleported to the nearest safe location?
# If this is set to true, Essentials will attempt to teleport players close to the intended destination.
# If this is set to false, attempted teleports to unsafe locations will be cancelled with a warning.