Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nickname regex configurable #5200

Open
wants to merge 2 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,8 @@ public interface ISettings extends IConf {

boolean showZeroBaltop();

String getNickRegex();

int getMaxItemLore();

enum KeepInvPolicy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1944,6 +1944,11 @@ public boolean showZeroBaltop() {
return config.getBoolean("show-zero-baltop", true);
}

@Override
public String getNickRegex() {
return config.getString("nick-regex", "^[a-zA-Z_0-9§]+$");
}

@Override
public int getMaxItemLore() {
return config.getInt("max-itemlore-lines", 10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected void updatePlayer(final Server server, final CommandSource sender, fin

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 Exception(tl("nickNamesAlpha"));
} else if (getNickLength(newNick) > ess.getSettings().getMaxNickLength()) {
throw new Exception(tl("nickTooLong"));
Expand Down
5 changes: 5 additions & 0 deletions Essentials/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 to use when checking the nickname change.
# If the pattern is not matched, the nickname will be rejected.
# To bypass this check, users need the essentials.nick.allowunsafe permission.
nick-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:
Expand Down