diff --git a/common/src/main/java/me/lucko/luckperms/common/api/ApiUtils.java b/common/src/main/java/me/lucko/luckperms/common/api/ApiUtils.java index 53da8cb7d..865345463 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/ApiUtils.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/ApiUtils.java @@ -29,14 +29,14 @@ import lombok.experimental.UtilityClass; import com.google.common.base.Preconditions; -import me.lucko.luckperms.common.utils.ArgumentChecker; +import me.lucko.luckperms.common.constants.DataConstraints; @UtilityClass public class ApiUtils { public static String checkUsername(String s) { Preconditions.checkArgument( - !ArgumentChecker.checkUsername(s), + DataConstraints.PLAYER_USERNAME_TEST.test(s), "Invalid username entry '" + s + "'. Usernames must be less than 16 chars and only contain 'a-z A-Z 1-9 _'." ); return s; @@ -44,14 +44,14 @@ public class ApiUtils { public static String checkName(String s) { Preconditions.checkArgument( - !ArgumentChecker.checkName(s), + DataConstraints.GROUP_NAME_TEST.test(s), "Invalid name entry '" + s + "'. Names must be less than 37 chars and only contain 'a-z A-Z 1-9'." ); return s.toLowerCase(); } public static long checkTime(long l) { - Preconditions.checkArgument(!ArgumentChecker.checkTime(l), "Unix time '" + l + "' is invalid, as it has already passed."); + Preconditions.checkArgument(DataConstraints.TIME_TEST.test(l), "Unix time '" + l + "' is invalid, as it has already passed."); return l; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/CommandManager.java b/common/src/main/java/me/lucko/luckperms/common/commands/CommandManager.java index 09c20ce01..a3c43526b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/CommandManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/CommandManager.java @@ -273,8 +273,8 @@ public class CommandManager { return CommandResult.INVALID_ARGS; } - if (e instanceof ArgumentUtils.InvalidServerException) { - Message.SERVER_INVALID_ENTRY.send(sender); + if (e instanceof ArgumentUtils.InvalidServerWorldException) { + Message.SERVER_WORLD_INVALID_ENTRY.send(sender); return CommandResult.INVALID_ARGS; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/abstraction/SharedMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/abstraction/SharedMainCommand.java index f144085fc..3eb583c05 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/abstraction/SharedMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/abstraction/SharedMainCommand.java @@ -172,8 +172,8 @@ public class SharedMainCommand extends SubCommand return CommandResult.INVALID_ARGS; } - if (e instanceof ArgumentUtils.InvalidServerException) { - Message.SERVER_INVALID_ENTRY.send(sender); + if (e instanceof ArgumentUtils.InvalidServerWorldException) { + Message.SERVER_WORLD_INVALID_ENTRY.send(sender); return CommandResult.INVALID_ARGS; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/CreateGroup.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/CreateGroup.java index 4cb570bfd..912d08eea 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/CreateGroup.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/CreateGroup.java @@ -30,11 +30,11 @@ import me.lucko.luckperms.common.commands.Arg; import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.abstraction.SingleCommand; import me.lucko.luckperms.common.commands.sender.Sender; +import me.lucko.luckperms.common.constants.DataConstraints; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.data.LogEntry; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; -import me.lucko.luckperms.common.utils.ArgumentChecker; import me.lucko.luckperms.common.utils.Predicates; import java.util.List; @@ -56,7 +56,7 @@ public class CreateGroup extends SingleCommand { } String groupName = args.get(0).toLowerCase(); - if (ArgumentChecker.checkName(groupName)) { + if (!DataConstraints.GROUP_NAME_TEST.test(groupName)) { Message.GROUP_INVALID_ENTRY.send(sender); return CommandResult.INVALID_ARGS; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/GroupClone.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/GroupClone.java index afe9cc9a8..33789f70d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/GroupClone.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/GroupClone.java @@ -31,12 +31,12 @@ import me.lucko.luckperms.common.commands.CommandException; import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.abstraction.SubCommand; import me.lucko.luckperms.common.commands.sender.Sender; +import me.lucko.luckperms.common.constants.DataConstraints; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.model.Group; import me.lucko.luckperms.common.data.LogEntry; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; -import me.lucko.luckperms.common.utils.ArgumentChecker; import me.lucko.luckperms.common.utils.Predicates; import java.util.List; @@ -51,7 +51,7 @@ public class GroupClone extends SubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List args, String label) throws CommandException { String newGroupName = args.get(0).toLowerCase(); - if (ArgumentChecker.checkName(newGroupName)) { + if (!DataConstraints.GROUP_NAME_TEST.test(newGroupName)) { Message.GROUP_INVALID_ENTRY.send(sender); return CommandResult.INVALID_ARGS; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/GroupRename.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/GroupRename.java index 3527b6b5d..46f524bd8 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/GroupRename.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/GroupRename.java @@ -32,12 +32,12 @@ import me.lucko.luckperms.common.commands.CommandException; import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.abstraction.SubCommand; import me.lucko.luckperms.common.commands.sender.Sender; +import me.lucko.luckperms.common.constants.DataConstraints; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.model.Group; import me.lucko.luckperms.common.data.LogEntry; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; -import me.lucko.luckperms.common.utils.ArgumentChecker; import me.lucko.luckperms.common.utils.Predicates; import java.util.List; @@ -52,7 +52,7 @@ public class GroupRename extends SubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List args, String label) throws CommandException { String newGroupName = args.get(0).toLowerCase(); - if (ArgumentChecker.checkName(newGroupName)) { + if (!DataConstraints.GROUP_NAME_TEST.test(newGroupName)) { Message.GROUP_INVALID_ENTRY.send(sender); return CommandResult.INVALID_ARGS; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/log/subcommands/LogGroupHistory.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/log/subcommands/LogGroupHistory.java index a29de7962..52c145dc4 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/log/subcommands/LogGroupHistory.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/log/subcommands/LogGroupHistory.java @@ -31,11 +31,11 @@ import me.lucko.luckperms.common.commands.CommandException; import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.abstraction.SubCommand; import me.lucko.luckperms.common.commands.sender.Sender; +import me.lucko.luckperms.common.constants.DataConstraints; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.data.Log; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; -import me.lucko.luckperms.common.utils.ArgumentChecker; import me.lucko.luckperms.common.utils.DateUtil; import me.lucko.luckperms.common.utils.Predicates; @@ -68,7 +68,7 @@ public class LogGroupHistory extends SubCommand { } } - if (ArgumentChecker.checkName(group)) { + if (!DataConstraints.GROUP_NAME_TEST.test(group)) { Message.GROUP_INVALID_ENTRY.send(sender); return CommandResult.INVALID_ARGS; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/log/subcommands/LogTrackHistory.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/log/subcommands/LogTrackHistory.java index f7bd6789a..1b5e2bb26 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/log/subcommands/LogTrackHistory.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/log/subcommands/LogTrackHistory.java @@ -31,11 +31,11 @@ import me.lucko.luckperms.common.commands.CommandException; import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.abstraction.SubCommand; import me.lucko.luckperms.common.commands.sender.Sender; +import me.lucko.luckperms.common.constants.DataConstraints; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.data.Log; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; -import me.lucko.luckperms.common.utils.ArgumentChecker; import me.lucko.luckperms.common.utils.DateUtil; import me.lucko.luckperms.common.utils.Predicates; @@ -68,7 +68,7 @@ public class LogTrackHistory extends SubCommand { } } - if (ArgumentChecker.checkName(track)) { + if (!DataConstraints.TRACK_NAME_TEST.test(track)) { Message.TRACK_INVALID_ENTRY.send(sender); return CommandResult.INVALID_ARGS; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/CreateTrack.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/CreateTrack.java index 9f89520cc..9a886eefa 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/CreateTrack.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/CreateTrack.java @@ -30,11 +30,11 @@ import me.lucko.luckperms.common.commands.Arg; import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.abstraction.SingleCommand; import me.lucko.luckperms.common.commands.sender.Sender; +import me.lucko.luckperms.common.constants.DataConstraints; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.data.LogEntry; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; -import me.lucko.luckperms.common.utils.ArgumentChecker; import me.lucko.luckperms.common.utils.Predicates; import java.util.List; @@ -56,7 +56,7 @@ public class CreateTrack extends SingleCommand { } String trackName = args.get(0).toLowerCase(); - if (ArgumentChecker.checkName(trackName)) { + if (!DataConstraints.TRACK_NAME_TEST.test(trackName)) { Message.TRACK_INVALID_ENTRY.send(sender); return CommandResult.INVALID_ARGS; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackAppend.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackAppend.java index 13d6cb347..ef5ae7938 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackAppend.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackAppend.java @@ -31,13 +31,13 @@ import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.abstraction.SubCommand; import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.commands.utils.Util; +import me.lucko.luckperms.common.constants.DataConstraints; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.model.Group; import me.lucko.luckperms.common.core.model.Track; import me.lucko.luckperms.common.data.LogEntry; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; -import me.lucko.luckperms.common.utils.ArgumentChecker; import me.lucko.luckperms.common.utils.Predicates; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; @@ -53,8 +53,7 @@ public class TrackAppend extends SubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List args, String label) throws CommandException { String groupName = args.get(0).toLowerCase(); - - if (ArgumentChecker.checkName(groupName)) { + if (!DataConstraints.GROUP_NAME_TEST.test(groupName)) { sendDetailedUsage(sender, label); return CommandResult.INVALID_ARGS; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackClone.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackClone.java index be9fd005f..74f597464 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackClone.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackClone.java @@ -31,12 +31,12 @@ import me.lucko.luckperms.common.commands.CommandException; import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.abstraction.SubCommand; import me.lucko.luckperms.common.commands.sender.Sender; +import me.lucko.luckperms.common.constants.DataConstraints; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.model.Track; import me.lucko.luckperms.common.data.LogEntry; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; -import me.lucko.luckperms.common.utils.ArgumentChecker; import me.lucko.luckperms.common.utils.Predicates; import java.util.List; @@ -51,7 +51,7 @@ public class TrackClone extends SubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List args, String label) throws CommandException { String newTrackName = args.get(0).toLowerCase(); - if (ArgumentChecker.checkName(newTrackName)) { + if (!DataConstraints.TRACK_NAME_TEST.test(newTrackName)) { Message.TRACK_INVALID_ENTRY.send(sender); return CommandResult.INVALID_ARGS; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackInsert.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackInsert.java index bd043c6e8..0b81627a2 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackInsert.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackInsert.java @@ -31,13 +31,13 @@ import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.abstraction.SubCommand; import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.commands.utils.Util; +import me.lucko.luckperms.common.constants.DataConstraints; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.model.Group; import me.lucko.luckperms.common.core.model.Track; import me.lucko.luckperms.common.data.LogEntry; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; -import me.lucko.luckperms.common.utils.ArgumentChecker; import me.lucko.luckperms.common.utils.Predicates; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; @@ -56,8 +56,7 @@ public class TrackInsert extends SubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List args, String label) throws CommandException { String groupName = args.get(0).toLowerCase(); - - if (ArgumentChecker.checkName(groupName)) { + if (!DataConstraints.GROUP_NAME_TEST.test(groupName)) { sendDetailedUsage(sender, label); return CommandResult.INVALID_ARGS; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackRemove.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackRemove.java index fc681105c..af4cd1fc6 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackRemove.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackRemove.java @@ -31,12 +31,12 @@ import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.abstraction.SubCommand; import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.commands.utils.Util; +import me.lucko.luckperms.common.constants.DataConstraints; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.model.Track; import me.lucko.luckperms.common.data.LogEntry; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; -import me.lucko.luckperms.common.utils.ArgumentChecker; import me.lucko.luckperms.common.utils.Predicates; import me.lucko.luckperms.exceptions.ObjectLacksException; @@ -52,8 +52,7 @@ public class TrackRemove extends SubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List args, String label) throws CommandException { String groupName = args.get(0).toLowerCase(); - - if (ArgumentChecker.checkName(groupName)) { + if (!DataConstraints.GROUP_NAME_TEST.test(groupName)) { sendDetailedUsage(sender, label); return CommandResult.INVALID_ARGS; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackRename.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackRename.java index 9f28f7695..63adb64b0 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackRename.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/track/TrackRename.java @@ -32,12 +32,12 @@ import me.lucko.luckperms.common.commands.CommandException; import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.abstraction.SubCommand; import me.lucko.luckperms.common.commands.sender.Sender; +import me.lucko.luckperms.common.constants.DataConstraints; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.model.Track; import me.lucko.luckperms.common.data.LogEntry; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; -import me.lucko.luckperms.common.utils.ArgumentChecker; import me.lucko.luckperms.common.utils.Predicates; import java.util.List; @@ -52,7 +52,7 @@ public class TrackRename extends SubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List args, String label) throws CommandException { String newTrackName = args.get(0).toLowerCase(); - if (ArgumentChecker.checkName(newTrackName)) { + if (!DataConstraints.TRACK_NAME_TEST.test(newTrackName)) { Message.TRACK_INVALID_ENTRY.send(sender); return CommandResult.INVALID_ARGS; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserDemote.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserDemote.java index 89b1b50b1..c410573e1 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserDemote.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserDemote.java @@ -34,6 +34,7 @@ import me.lucko.luckperms.common.commands.abstraction.SubCommand; import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.commands.utils.ArgumentUtils; import me.lucko.luckperms.common.commands.utils.Util; +import me.lucko.luckperms.common.constants.DataConstraints; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.NodeFactory; @@ -42,7 +43,6 @@ import me.lucko.luckperms.common.core.model.Track; import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.data.LogEntry; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; -import me.lucko.luckperms.common.utils.ArgumentChecker; import me.lucko.luckperms.common.utils.Predicates; import me.lucko.luckperms.exceptions.ObjectLacksException; @@ -63,7 +63,7 @@ public class UserDemote extends SubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List args, String label) throws CommandException { final String trackName = args.get(0).toLowerCase(); - if (ArgumentChecker.checkName(trackName)) { + if (!DataConstraints.TRACK_NAME_TEST.test(trackName)) { Message.TRACK_INVALID_ENTRY.send(sender); return CommandResult.INVALID_ARGS; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserPromote.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserPromote.java index 83f5746ba..37f81c71b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserPromote.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserPromote.java @@ -34,6 +34,7 @@ import me.lucko.luckperms.common.commands.abstraction.SubCommand; import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.commands.utils.ArgumentUtils; import me.lucko.luckperms.common.commands.utils.Util; +import me.lucko.luckperms.common.constants.DataConstraints; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.NodeFactory; @@ -42,7 +43,6 @@ import me.lucko.luckperms.common.core.model.Track; import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.data.LogEntry; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; -import me.lucko.luckperms.common.utils.ArgumentChecker; import me.lucko.luckperms.common.utils.Predicates; import me.lucko.luckperms.exceptions.ObjectLacksException; @@ -63,7 +63,7 @@ public class UserPromote extends SubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List args, String label) throws CommandException { final String trackName = args.get(0).toLowerCase(); - if (ArgumentChecker.checkName(trackName)) { + if (!DataConstraints.TRACK_NAME_TEST.test(trackName)) { Message.TRACK_INVALID_ENTRY.send(sender); return CommandResult.INVALID_ARGS; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/utils/ArgumentUtils.java b/common/src/main/java/me/lucko/luckperms/common/commands/utils/ArgumentUtils.java index 57e215ee1..bdbdaf203 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/utils/ArgumentUtils.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/utils/ArgumentUtils.java @@ -28,12 +28,10 @@ package me.lucko.luckperms.common.commands.utils; import lombok.AllArgsConstructor; import lombok.Getter; -import com.google.common.base.Splitter; - import me.lucko.luckperms.api.context.ImmutableContextSet; import me.lucko.luckperms.api.context.MutableContextSet; import me.lucko.luckperms.common.commands.CommandException; -import me.lucko.luckperms.common.utils.ArgumentChecker; +import me.lucko.luckperms.common.constants.DataConstraints; import me.lucko.luckperms.common.utils.DateUtil; import java.util.ArrayList; @@ -44,7 +42,6 @@ import java.util.function.Function; * Utility class to help process arguments, and throw checked exceptions if the arguments are invalid. */ public class ArgumentUtils { - private static final Splitter CONTEXT_SPLITTER = Splitter.on('=').limit(2).omitEmptyStrings(); public static final Function WRAPPER = s -> s.contains(" ") ? "\"" + s + "\"" : s; @@ -84,7 +81,7 @@ public class ArgumentUtils { public static String handleName(int index, List args) throws ArgumentException { String groupName = args.get(index).toLowerCase(); - if (ArgumentChecker.checkName(groupName)) { + if (!DataConstraints.GROUP_NAME_TEST.test(groupName)) { throw new DetailedUsageException(); } return groupName; @@ -92,7 +89,7 @@ public class ArgumentUtils { public static String handleNameWithSpace(int index, List args) throws ArgumentException { String groupName = args.get(index).toLowerCase(); - if (ArgumentChecker.checkNameWithSpace(groupName)) { + if (!DataConstraints.GROUP_NAME_TEST_ALLOW_SPACE.test(groupName)) { throw new DetailedUsageException(); } return groupName; @@ -140,7 +137,7 @@ public class ArgumentUtils { return args.size() > index ? args.get(index).toLowerCase() : null; } - public static MutableContextSet handleContext(int fromIndex, List args) { + public static MutableContextSet handleContext(int fromIndex, List args) throws CommandException { if (args.size() > fromIndex) { MutableContextSet set = MutableContextSet.create(); @@ -152,6 +149,14 @@ public class ArgumentUtils { // one of the first two values, and doesn't have a key if (i <= 1 && !pair.contains("=")) { String key = i == 0 ? "server" : "world"; + + if (key.equals("server") && !DataConstraints.SERVER_NAME_TEST.test(pair)) { + throw new InvalidServerWorldException(); + } + if (key.equals("world") && !DataConstraints.WORLD_NAME_TEST.test(pair)) { + throw new InvalidServerWorldException(); + } + set.add(key, pair); continue; } @@ -171,6 +176,13 @@ public class ArgumentUtils { continue; } + if (key.equals("server") && !DataConstraints.SERVER_NAME_TEST.test(value)) { + throw new InvalidServerWorldException(); + } + if (key.equals("world") && !DataConstraints.WORLD_NAME_TEST.test(value)) { + throw new InvalidServerWorldException(); + } + set.add(key, value); } @@ -250,7 +262,7 @@ public class ArgumentUtils { public static class UseInheritException extends ArgumentException { } - public static class InvalidServerException extends ArgumentException { + public static class InvalidServerWorldException extends ArgumentException { } public static class PastDateException extends ArgumentException { 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 new file mode 100644 index 000000000..b34b01c4b --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/constants/DataConstraints.java @@ -0,0 +1,161 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck) + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.lucko.luckperms.common.constants; + +import lombok.experimental.UtilityClass; + +import me.lucko.luckperms.common.utils.DateUtil; + +import java.util.function.Predicate; +import java.util.regex.Pattern; + +@UtilityClass +public class DataConstraints { + + public static final Pattern RESERVED_CHARACTERS_PATTERN = Pattern.compile("[\\/\\$\\.]"); + + public static final int MAX_PERMISSION_LENGTH = 200; + + public static final int MAX_TRACK_NAME_LENGTH = 36; + public static final int MAX_GROUP_NAME_LENGTH = 36; + + public static final int MAX_PLAYER_USERNAME_LENGTH = 16; + public static final Pattern PLAYER_USERNAME_INVALID_CHAR_MATCHER = Pattern.compile("[^A-Za-z0-9_ ]"); + + public static final int MAX_SERVER_LENGTH = 36; + public static final int MAX_WORLD_LENGTH = 36; + + public static final Predicate PERMISSION_TEST = s -> { + if (s.length() <= 0 || s.length() > MAX_PERMISSION_LENGTH) { + return false; + } + + return true; + }; + + public static final Predicate PLAYER_USERNAME_TEST = s -> { + if (s.length() <= 0 || s.length() > MAX_PLAYER_USERNAME_LENGTH) { + return false; + } + + if (PLAYER_USERNAME_INVALID_CHAR_MATCHER.matcher(s).find()) { + return false; + } + + return true; + }; + + public static final Predicate GROUP_NAME_TEST = s -> { + if (s.length() <= 0 || s.length() > MAX_GROUP_NAME_LENGTH) { + return false; + } + + if (s.contains(" ")) { + return false; + } + + if (RESERVED_CHARACTERS_PATTERN.matcher(s).find()) { + return false; + } + + return true; + }; + + public static final Predicate GROUP_NAME_TEST_ALLOW_SPACE = s -> { + if (s.length() <= 0 || s.length() > MAX_GROUP_NAME_LENGTH) { + return false; + } + + if (RESERVED_CHARACTERS_PATTERN.matcher(s).find()) { + return false; + } + + return true; + }; + + public static final Predicate TRACK_NAME_TEST = s -> { + if (s.length() <= 0 || s.length() > MAX_TRACK_NAME_LENGTH) { + return false; + } + + if (s.contains(" ")) { + return false; + } + + if (RESERVED_CHARACTERS_PATTERN.matcher(s).find()) { + return false; + } + + return true; + }; + + public static final Predicate TRACK_NAME_TEST_ALLOW_SPACE = s -> { + if (s.length() <= 0 || s.length() > MAX_TRACK_NAME_LENGTH) { + return false; + } + + if (RESERVED_CHARACTERS_PATTERN.matcher(s).find()) { + return false; + } + + return true; + }; + + public static final Predicate TIME_TEST = DateUtil::shouldExpire; + + public static final Predicate SERVER_NAME_TEST = s -> { + if (s.length() <= 0 || s.length() > MAX_SERVER_LENGTH) { + return false; + } + + if (s.contains(" ")) { + return false; + } + + if (RESERVED_CHARACTERS_PATTERN.matcher(s).find()) { + return false; + } + + return true; + }; + + public static final Predicate WORLD_NAME_TEST = s -> { + if (s.length() <= 0 || s.length() > MAX_WORLD_LENGTH) { + return false; + } + + if (s.contains(" ")) { + return false; + } + + if (RESERVED_CHARACTERS_PATTERN.matcher(s).find()) { + return false; + } + + return true; + }; + +} diff --git a/common/src/main/java/me/lucko/luckperms/common/constants/Message.java b/common/src/main/java/me/lucko/luckperms/common/constants/Message.java index a0a8c2ddc..275121907 100644 --- a/common/src/main/java/me/lucko/luckperms/common/constants/Message.java +++ b/common/src/main/java/me/lucko/luckperms/common/constants/Message.java @@ -93,7 +93,7 @@ public enum Message { USER_INVALID_ENTRY("&d{0}&c is not a valid username/uuid.", true), GROUP_INVALID_ENTRY("Group names can only contain alphanumeric characters.", true), TRACK_INVALID_ENTRY("Track names can only contain alphanumeric characters.", true), - SERVER_INVALID_ENTRY("Server names can only contain alphanumeric characters.", true), + SERVER_WORLD_INVALID_ENTRY("Server/world names can only contain alphanumeric characters and cannot exceed 36 characters in length.", true), USE_INHERIT_COMMAND("Use the 'parent add' and 'parent remove' commands instead of specifying the node.", true), diff --git a/common/src/main/java/me/lucko/luckperms/common/utils/ArgumentChecker.java b/common/src/main/java/me/lucko/luckperms/common/utils/ArgumentChecker.java deleted file mode 100644 index d3f881dc2..000000000 --- a/common/src/main/java/me/lucko/luckperms/common/utils/ArgumentChecker.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This file is part of LuckPerms, licensed under the MIT License. - * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.lucko.luckperms.common.utils; - -import lombok.experimental.UtilityClass; - -import me.lucko.luckperms.common.constants.Patterns; - -/** - * Utility for checking arguments for consistency - */ -@UtilityClass -public class ArgumentChecker { - - public static boolean checkUsername(String s) { - return (s.length() > 16 || Patterns.NON_USERNAME.matcher(s).find()); - } - - public static boolean checkName(String s) { - return (s.length() > 36 || Patterns.NON_ALPHA_NUMERIC.matcher(s).find()); - } - - public static boolean checkNameWithSpace(String s) { - return (s.length() > 36 || Patterns.NON_ALPHA_NUMERIC_SPACE.matcher(s).find()); - } - - public static boolean checkTime(long l) { - return DateUtil.shouldExpire(l); - } - -}