Add config option to allow invalid usernames (#516)

This commit is contained in:
Luck
2017-10-22 09:00:10 +01:00
Unverified
parent 6e429d6c78
commit ecfbed00b1
8 changed files with 63 additions and 11 deletions
@@ -73,9 +73,16 @@ public class LogRecent extends SubCommand<Log> {
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();
@@ -68,22 +68,29 @@ public class LogUserHistory extends SubCommand<Log> {
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;
}
}
}
@@ -83,9 +83,16 @@ public class UserMainCommand extends MainCommand<User, UserIdentifier> {
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();
@@ -122,6 +122,11 @@ public class ConfigKeys {
*/
public static final ConfigKey<Boolean> USE_SERVER_UUID_CACHE = BooleanKey.of("use-server-uuid-cache", false);
/**
* If LuckPerms should allow usernames with non alphanumeric characters.
*/
public static final ConfigKey<Boolean> ALLOW_INVALID_USERNAMES = BooleanKey.of("allow-invalid-usernames", false);
/**
* If LuckPerms should produce extra logging output when it handles logins.
*/
@@ -68,6 +68,14 @@ public class DataConstraints {
return true;
};
public static final Predicate<String> PLAYER_USERNAME_TEST_LENIENT = s -> {
if (s.length() <= 0 || s.length() > MAX_PLAYER_USERNAME_LENGTH) {
return false;
}
return true;
};
public static final Predicate<String> GROUP_NAME_TEST = s -> {
if (s.length() <= 0 || s.length() > MAX_GROUP_NAME_LENGTH) {
return false;