Listed arguments

Arguments have a setting which determine whether or not they are present in the CommandArguments args that is populated when executing a command.

By default, the LiteralArgument has this setting set to false, hence the literal values are not present in the CommandArguments args.

This flag is set using the following function:

Argument setListed(boolean listed);

Example - Setting listed arguments

Say we have the following command:

/mycommand <player> <value> <message>

Let's also say that in our implementation of this command, we don't actually perform any processing for <value>. Hence, listing it in the CommandArguments args is unnecessary.

new CommandAPICommand("mycommand")
    .withArguments(new PlayerArgument("player"))
    .withArguments(new IntegerArgument("value").setListed(false))
    .withArguments(new GreedyStringArgument("message"))
    .executes((sender, args) -> {
        // args == [player, message]
        Player player = (Player) args.get(0);
        String message = (String) args.get(1); // Note that this is args.get(1) and NOT args.get(2)
    .executes(CommandExecutor { _, args ->
        // args == [player, message]
        val player = args[0] as Player
        val message = args[1] as String // Note that this is args[1] and NOT args[2]

In this scenario, the argument <value> is not present in the CommandArguments args for the executor.