diff --git a/bukkit/src/main/resources/config.yml b/bukkit/src/main/resources/config.yml index d8978f40..6d3b2306 100644 --- a/bukkit/src/main/resources/config.yml +++ b/bukkit/src/main/resources/config.yml @@ -70,6 +70,12 @@ use-server-uuids: true # in the LuckPerms cache. use-server-uuid-cache: false +# If set to true, LuckPerms will allow usernames with non alphanumeric characters. +# +# Note that due to the design of the storage implementation, usernames must still be +# 16 characters or less. +allow-invalid-usernames: false + # If LuckPerms should produce extra logging output when it handles logins. # Useful if you're having issues with UUID forwarding or data not being loaded. debug-logins: false diff --git a/bungee/src/main/resources/config.yml b/bungee/src/main/resources/config.yml index 8122eea3..a6158c0a 100644 --- a/bungee/src/main/resources/config.yml +++ b/bungee/src/main/resources/config.yml @@ -73,6 +73,12 @@ use-server-uuids: true # try to find a uuid for a username using RedisBungee, if installed. use-server-uuid-cache: false +# If set to true, LuckPerms will allow usernames with non alphanumeric characters. +# +# Note that due to the design of the storage implementation, usernames must still be +# 16 characters or less. +allow-invalid-usernames: false + # If LuckPerms should produce extra logging output when it handles logins. # Useful if you're having issues with UUID forwarding or data not being loaded. debug-logins: false diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/log/LogRecent.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/log/LogRecent.java index 0064d0ed..f6a6803a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/log/LogRecent.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/log/LogRecent.java @@ -73,9 +73,16 @@ public class LogRecent extends SubCommand { final String target = args.get(0); UUID uuid = Util.parseUuid(target.toLowerCase()); if (uuid == null) { - if (!DataConstraints.PLAYER_USERNAME_TEST.test(target)) { - Message.USER_INVALID_ENTRY.send(sender, target); - return CommandResult.INVALID_ARGS; + if (!plugin.getConfiguration().get(ConfigKeys.ALLOW_INVALID_USERNAMES)) { + if (!DataConstraints.PLAYER_USERNAME_TEST.test(target)) { + Message.USER_INVALID_ENTRY.send(sender, target); + return CommandResult.INVALID_ARGS; + } + } else { + if (!DataConstraints.PLAYER_USERNAME_TEST_LENIENT.test(target)) { + Message.USER_INVALID_ENTRY.send(sender, target); + return CommandResult.INVALID_ARGS; + } } uuid = plugin.getStorage().getUUID(target.toLowerCase()).join(); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/log/LogUserHistory.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/log/LogUserHistory.java index 34775962..44345bd4 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/log/LogUserHistory.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/log/LogUserHistory.java @@ -68,22 +68,29 @@ public class LogUserHistory extends SubCommand { UUID uuid = Util.parseUuid(target.toLowerCase()); if (uuid == null) { - if (!DataConstraints.PLAYER_USERNAME_TEST.test(target)) { - Message.USER_INVALID_ENTRY.send(sender, target); - return null; + if (!plugin.getConfiguration().get(ConfigKeys.ALLOW_INVALID_USERNAMES)) { + if (!DataConstraints.PLAYER_USERNAME_TEST.test(target)) { + Message.USER_INVALID_ENTRY.send(sender, target); + return CommandResult.INVALID_ARGS; + } + } else { + if (!DataConstraints.PLAYER_USERNAME_TEST_LENIENT.test(target)) { + Message.USER_INVALID_ENTRY.send(sender, target); + return CommandResult.INVALID_ARGS; + } } uuid = plugin.getStorage().getUUID(target.toLowerCase()).join(); if (uuid == null) { if (!plugin.getConfiguration().get(ConfigKeys.USE_SERVER_UUID_CACHE)) { Message.USER_NOT_FOUND.send(sender, target); - return null; + return CommandResult.INVALID_ARGS; } uuid = plugin.lookupUuid(target).orElse(null); if (uuid == null) { Message.USER_NOT_FOUND.send(sender, target); - return null; + return CommandResult.INVALID_ARGS; } } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserMainCommand.java index 2751edd6..abf4238c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserMainCommand.java @@ -83,9 +83,16 @@ public class UserMainCommand extends MainCommand { protected UserIdentifier parseTarget(String target, LuckPermsPlugin plugin, Sender sender) { UUID uuid = Util.parseUuid(target.toLowerCase()); if (uuid == null) { - if (!DataConstraints.PLAYER_USERNAME_TEST.test(target)) { - Message.USER_INVALID_ENTRY.send(sender, target); - return null; + if (!plugin.getConfiguration().get(ConfigKeys.ALLOW_INVALID_USERNAMES)) { + if (!DataConstraints.PLAYER_USERNAME_TEST.test(target)) { + Message.USER_INVALID_ENTRY.send(sender, target); + return null; + } + } else { + if (!DataConstraints.PLAYER_USERNAME_TEST_LENIENT.test(target)) { + Message.USER_INVALID_ENTRY.send(sender, target); + return null; + } } uuid = plugin.getStorage().getUUID(target.toLowerCase()).join(); diff --git a/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java b/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java index e5985c66..b0a9668a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java +++ b/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java @@ -122,6 +122,11 @@ public class ConfigKeys { */ public static final ConfigKey USE_SERVER_UUID_CACHE = BooleanKey.of("use-server-uuid-cache", false); + /** + * If LuckPerms should allow usernames with non alphanumeric characters. + */ + public static final ConfigKey ALLOW_INVALID_USERNAMES = BooleanKey.of("allow-invalid-usernames", false); + /** * If LuckPerms should produce extra logging output when it handles logins. */ diff --git a/common/src/main/java/me/lucko/luckperms/common/constants/DataConstraints.java b/common/src/main/java/me/lucko/luckperms/common/constants/DataConstraints.java index af831439..354aede0 100644 --- a/common/src/main/java/me/lucko/luckperms/common/constants/DataConstraints.java +++ b/common/src/main/java/me/lucko/luckperms/common/constants/DataConstraints.java @@ -68,6 +68,14 @@ public class DataConstraints { return true; }; + public static final Predicate PLAYER_USERNAME_TEST_LENIENT = s -> { + if (s.length() <= 0 || s.length() > MAX_PLAYER_USERNAME_LENGTH) { + return false; + } + + return true; + }; + public static final Predicate GROUP_NAME_TEST = s -> { if (s.length() <= 0 || s.length() > MAX_GROUP_NAME_LENGTH) { return false; diff --git a/sponge/src/main/resources/luckperms.conf b/sponge/src/main/resources/luckperms.conf index f1ed8fe2..12a42878 100644 --- a/sponge/src/main/resources/luckperms.conf +++ b/sponge/src/main/resources/luckperms.conf @@ -69,6 +69,12 @@ use-server-uuids=true # in the LuckPerms cache. use-server-uuid-cache=false +# If set to true, LuckPerms will allow usernames with non alphanumeric characters. +# +# Note that due to the design of the storage implementation, usernames must still be +# 16 characters or less. +allow-invalid-usernames=false + # If LuckPerms should produce extra logging output when it handles logins. # Useful if you're having issues with UUID forwarding or data not being loaded. debug-logins=false