Add option to customize nickname regex filter (#5200)

This commit is contained in:
Angelillo15 2025-03-24 17:43:53 +01:00 committed by GitHub
parent 40540ebb3d
commit cb6187bbf2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 13 additions and 1 deletions

View File

@ -424,6 +424,8 @@ public interface ISettings extends IConf {
boolean showZeroBaltop();
String getNickRegex();
BigDecimal getMultiplier(final User user);
int getMaxItemLore();

View File

@ -2120,6 +2120,11 @@ public class Settings implements net.ess3.api.ISettings {
return config.getBoolean("show-zero-baltop", true);
}
@Override
public String getNickRegex() {
return config.getString("allowed-nicks-regex", "^[a-zA-Z_0-9§]+$");
}
@Override
public BigDecimal getMultiplier(final User user) {
BigDecimal multiplier = defaultMultiplier;

View File

@ -63,7 +63,7 @@ public class Commandnick extends EssentialsLoopCommand {
private String formatNickname(final User user, final String nick) throws Exception {
final String newNick = user == null ? FormatUtil.replaceFormat(nick) : FormatUtil.formatString(user, "essentials.nick", nick);
if (!newNick.matches("^[a-zA-Z_0-9" + ChatColor.COLOR_CHAR + "]+$") && user != null && !user.isAuthorized("essentials.nick.allowunsafe")) {
if (!newNick.matches(ess.getSettings().getNickRegex()) && user != null && !user.isAuthorized("essentials.nick.allowunsafe")) {
throw new TranslatableException("nickNamesAlpha");
} else if (getNickLength(newNick) > ess.getSettings().getMaxNickLength()) {
throw new TranslatableException("nickTooLong");

View File

@ -33,6 +33,11 @@ nickname-prefix: '~'
# The maximum length allowed in nicknames. The nickname prefix is not included in this.
max-nick-length: 15
# The regex pattern used to determine if a requested nickname should be allowed for use.
# If the a request nickname does not matched this pattern, the nickname will be rejected.
# Users with essentials.nick.allowunsafe will be able to bypass this check.
allowed-nicks-regex: '^[a-zA-Z_0-9§]+$'
# A list of phrases that cannot be used in nicknames. You can include regular expressions here.
# Users with essentials.nick.blacklist.bypass will be able to bypass this filter.
nick-blacklist: