diff --git a/api/src/main/java/net/luckperms/api/node/types/DisplayNameNode.java b/api/src/main/java/net/luckperms/api/node/types/DisplayNameNode.java index 4f84be800..36a20b5bb 100644 --- a/api/src/main/java/net/luckperms/api/node/types/DisplayNameNode.java +++ b/api/src/main/java/net/luckperms/api/node/types/DisplayNameNode.java @@ -79,6 +79,7 @@ public interface DisplayNameNode extends ScopedNode { * * @param key the meta key * @return the builder + * @throws IllegalArgumentException if {@code key} is empty */ @NonNull Builder key(@NonNull String key); diff --git a/api/src/main/java/net/luckperms/api/node/types/PermissionNode.java b/api/src/main/java/net/luckperms/api/node/types/PermissionNode.java index bcd699de7..d6c852d4b 100644 --- a/api/src/main/java/net/luckperms/api/node/types/PermissionNode.java +++ b/api/src/main/java/net/luckperms/api/node/types/PermissionNode.java @@ -104,6 +104,7 @@ public interface PermissionNode extends ScopedNode plugin.getConfiguration().get(ConfigKeys.TEMPORARY_ADD_BEHAVIOUR)); MutableContextSet context = args.getContextOrDefault(3, plugin); + if (key.isEmpty()) { + Message.INVALID_META_KEY_EMPTY.send(sender); + return; + } + if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context) || ArgumentPermissions.checkArguments(plugin, sender, permission, key)) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnset.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnset.java index 67269172b..797f59319 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnset.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnset.java @@ -62,6 +62,11 @@ public class MetaUnset extends GenericChildCommand { String key = args.get(0); MutableContextSet context = args.getContextOrDefault(1, plugin); + if (key.isEmpty()) { + Message.INVALID_META_KEY_EMPTY.send(sender); + return; + } + if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context) || ArgumentPermissions.checkArguments(plugin, sender, permission, key)) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnsetTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnsetTemp.java index e7050c801..48a165938 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnsetTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnsetTemp.java @@ -62,6 +62,11 @@ public class MetaUnsetTemp extends GenericChildCommand { String key = args.get(0); MutableContextSet context = args.getContextOrDefault(1, plugin); + if (key.isEmpty()) { + Message.INVALID_META_KEY_EMPTY.send(sender); + return; + } + if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context) || ArgumentPermissions.checkArguments(plugin, sender, permission, key)) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheck.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheck.java index 679f93d4d..f341c3f35 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheck.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheck.java @@ -72,6 +72,10 @@ public class PermissionCheck extends GenericChildCommand { } String node = args.get(0); + if (node.isEmpty()) { + Message.INVALID_PERMISSION_EMPTY.send(sender); + return; + } // accumulate nodes List own = new ArrayList<>(); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSet.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSet.java index 7ec065ed9..c629408d4 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSet.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSet.java @@ -67,7 +67,8 @@ public class PermissionSet extends GenericChildCommand { MutableContextSet context = args.getContextOrDefault(2, plugin); if (node.isEmpty()) { - Message.PERMISSION_INVALID_ENTRY_EMPTY.send(sender); + Message.INVALID_PERMISSION_EMPTY.send(sender); + return; } if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSetTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSetTemp.java index 36ac9785c..5b59d2a68 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSetTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSetTemp.java @@ -72,7 +72,8 @@ public class PermissionSetTemp extends GenericChildCommand { MutableContextSet context = args.getContextOrDefault(3, plugin); if (node.isEmpty()) { - Message.PERMISSION_INVALID_ENTRY_EMPTY.send(sender); + Message.INVALID_PERMISSION_EMPTY.send(sender); + return; } if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnset.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnset.java index 544d29e71..ed2f2e25b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnset.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnset.java @@ -66,7 +66,8 @@ public class PermissionUnset extends GenericChildCommand { MutableContextSet context = args.getContextOrDefault(1, plugin); if (node.isEmpty()) { - Message.PERMISSION_INVALID_ENTRY_EMPTY.send(sender); + Message.INVALID_PERMISSION_EMPTY.send(sender); + return; } if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnsetTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnsetTemp.java index 2ba38edce..cfc8e9fe0 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnsetTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnsetTemp.java @@ -69,7 +69,8 @@ public class PermissionUnsetTemp extends GenericChildCommand { MutableContextSet context = args.getContextOrDefault(fromIndex, plugin); if (node.isEmpty()) { - Message.PERMISSION_INVALID_ENTRY_EMPTY.send(sender); + Message.INVALID_PERMISSION_EMPTY.send(sender); + return; } if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/DeleteGroup.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/DeleteGroup.java index 57794664e..29e5ee9d4 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/DeleteGroup.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/DeleteGroup.java @@ -50,6 +50,7 @@ import me.lucko.luckperms.common.model.manager.group.GroupManager; import me.lucko.luckperms.common.node.types.Inheritance; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.sender.Sender; +import me.lucko.luckperms.common.storage.misc.DataConstraints; import me.lucko.luckperms.common.util.Predicates; import net.luckperms.api.actionlog.Action; @@ -72,6 +73,10 @@ public class DeleteGroup extends SingleCommand { } String groupName = args.get(0).toLowerCase(Locale.ROOT); + if (!DataConstraints.GROUP_NAME_TEST.test(groupName)) { + Message.GROUP_INVALID_ENTRY.send(sender, groupName); + return; + } if (groupName.equalsIgnoreCase(GroupManager.DEFAULT_GROUP_NAME)) { Message.DELETE_GROUP_ERROR_DEFAULT.send(sender); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupSetDisplayName.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupSetDisplayName.java index fe00b961b..9326fa7a4 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupSetDisplayName.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupSetDisplayName.java @@ -64,6 +64,11 @@ public class GroupSetDisplayName extends ChildCommand { String name = args.get(0); ImmutableContextSet context = args.getContextOrDefault(1, plugin).immutableCopy(); + if (name.isEmpty()) { + Message.INVALID_DISPLAY_NAME_EMPTY.send(sender); + return; + } + String previousName = target.normalData().nodesInContext(context).stream() .filter(NodeType.DISPLAY_NAME::matches) .map(NodeType.DISPLAY_NAME::cast) diff --git a/common/src/main/java/me/lucko/luckperms/common/locale/Message.java b/common/src/main/java/me/lucko/luckperms/common/locale/Message.java index 0be4e97e1..34eed5df7 100644 --- a/common/src/main/java/me/lucko/luckperms/common/locale/Message.java +++ b/common/src/main/java/me/lucko/luckperms/common/locale/Message.java @@ -2200,13 +2200,18 @@ public interface Message { .append(FULL_STOP) ); - Args0 PERMISSION_INVALID_ENTRY_EMPTY = () -> prefixed(translatable() - // "&cThe empty string is not a valid permission." - .key("luckperms.command.misc.permission-invalid-empty") + Args1 INVALID_INPUT_EMPTY = s -> prefixed(translatable() + // "&cThe empty string is not a valid {s}." + .key("luckperms.command.misc.invalid-input-empty-" + s) .color(RED) .append(FULL_STOP) ); + // Predefined shorthands for the above message + Args0 INVALID_PERMISSION_EMPTY = () -> INVALID_INPUT_EMPTY.build("permission"); + Args0 INVALID_META_KEY_EMPTY = () -> INVALID_INPUT_EMPTY.build("meta-key"); + Args0 INVALID_DISPLAY_NAME_EMPTY = () -> INVALID_INPUT_EMPTY.build("display-name"); + Args3 SET_INHERIT_SUCCESS = (holder, parent, context) -> prefixed(translatable() // "&b{}&a now inherits permissions from &b{}&a in context {}&a." .key("luckperms.command.generic.parent.add") diff --git a/common/src/main/java/me/lucko/luckperms/common/node/types/DisplayName.java b/common/src/main/java/me/lucko/luckperms/common/node/types/DisplayName.java index d09b026f6..b61d8de5b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/node/types/DisplayName.java +++ b/common/src/main/java/me/lucko/luckperms/common/node/types/DisplayName.java @@ -95,7 +95,11 @@ public class DisplayName extends AbstractNode Inheritance.parse(key)); + } + @ParameterizedTest @CsvSource({ "displayname.test, test", @@ -92,6 +99,14 @@ public class NodeParseTest { assertNull(builder); } + @ParameterizedTest + @ValueSource(strings = { + "displayname." + }) + public void testDisplayNameThrows(String key) { + assertThrows(IllegalArgumentException.class, () -> DisplayName.parse(key)); + } + @ParameterizedTest @CsvSource({ "weight.100, 100",