mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-03 15:08:18 +01:00
[Fix] Fixes drtshock/Essentials#189, adds toggleable config option 'ignore-colors-in-max-nick-length' to exclude ChatColors from nickname length
This commit is contained in:
parent
d4ab25b200
commit
77eb430b0b
@ -208,6 +208,8 @@ public interface ISettings extends IConf {
|
||||
|
||||
int getMaxNickLength();
|
||||
|
||||
boolean ignoreColorsInMaxLength();
|
||||
|
||||
int getMaxUserCacheCount();
|
||||
|
||||
boolean allowSilentJoinQuit();
|
||||
|
@ -1046,6 +1046,11 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
return config.getInt("max-nick-length", 30);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ignoreColorsInMaxLength() {
|
||||
return config.getBoolean("ignore-colors-in-max-nick-length", false);
|
||||
}
|
||||
|
||||
private boolean allowSilentJoin;
|
||||
|
||||
public boolean _allowSilentJoinQuit() {
|
||||
|
@ -4,6 +4,7 @@ import com.earth2me.essentials.CommandSource;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.FormatUtil;
|
||||
import net.ess3.api.events.NickChangeEvent;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -74,7 +75,7 @@ public class Commandnick extends EssentialsLoopCommand {
|
||||
String newNick = user == null ? FormatUtil.replaceFormat(nick) : FormatUtil.formatString(user, "essentials.nick", nick);
|
||||
if (!newNick.matches("^[a-zA-Z_0-9\u00a7]+$")) {
|
||||
throw new Exception(tl("nickNamesAlpha"));
|
||||
} else if (newNick.length() > ess.getSettings().getMaxNickLength()) {
|
||||
} else if (getNickLength(newNick) > ess.getSettings().getMaxNickLength()) {
|
||||
throw new Exception(tl("nickTooLong"));
|
||||
} else if (FormatUtil.stripFormat(newNick).length() < 1) {
|
||||
throw new Exception(tl("nickNamesAlpha"));
|
||||
@ -82,6 +83,10 @@ public class Commandnick extends EssentialsLoopCommand {
|
||||
return newNick;
|
||||
}
|
||||
|
||||
private int getNickLength(final String nick) {
|
||||
return ess.getSettings().ignoreColorsInMaxLength() ? ChatColor.stripColor(nick).length() : nick.length();
|
||||
}
|
||||
|
||||
private boolean nickInUse(final Server server, final User target, String nick) {
|
||||
final String lowerNick = FormatUtil.stripFormat(nick.toLowerCase(Locale.ENGLISH));
|
||||
for (final Player onlinePlayer : ess.getOnlinePlayers()) {
|
||||
|
@ -28,6 +28,10 @@ nickname-prefix: '~'
|
||||
# The maximum length allowed in nicknames. The nickname prefix is included in this.
|
||||
max-nick-length: 15
|
||||
|
||||
# When this option is enabled, nickname length checking will exclude color codes in player names.
|
||||
# ie: "&6Notch" has 7 characters (2 are part of a color code), a length of 5 is used when this option is set to true
|
||||
ignore-colors-in-max-nick-length: false
|
||||
|
||||
# Disable this if you have any other plugin, that modifies the displayname of a user.
|
||||
change-displayname: true
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user