Permissions for Certain Arguments

I want to know how I can separate my 1 command to have different permissions depending on the arguments. Currently I have:

    CommandSpec myCommandSpec2 = CommandSpec.builder()
            .description(Text.of("Main Gym Command"))
            .permission("gymleader.commands.gym")
            .arguments(GenericArguments.seq(
                    GenericArguments.string(Text.of("gymElement")),
                    GenericArguments.optional(GenericArguments.seq(
                            GenericArguments.choices(Text.of("add/remove"), arg1),
                            GenericArguments.string(Text.of("playerName"))
                    ))
            ))
            .executor(new GymLeaderHandler())
            .child(addGym, "add", "a")
            .child(removeGym, "remove", "r", "delete", "d")
            .build();

    Sponge.getCommandManager().register(plugin, myCommandSpec2, "gym");

I want all players to be able to use /gym gymElement, but only staff be able to use /gym gymElement add/remove player. I was thinking of making gymElement a child of gym, and add/remove a child of gymElement to do this. The problem is gymElement can be any String and I do not know how to set the parameters of .child to do this. If anyone has advice for me that would be great.

You can wrap GenericArguments.seq in GenericArguments.requiringPermission. Alternatively, since these are clearly meant to be subcommands, you could instead turn them into subcommand CommandSpecs and give them their own permissions.

1 Like