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("player");
        String message = (String) args.get("message"); // Note that the IntegerArgument is not available in the CommandArguments
        player.sendMessage(message);
    })
    .register();
CommandAPICommand("mycommand")
    .withArguments(PlayerArgument("player"))
    .withArguments(IntegerArgument("value").setListed(false))
    .withArguments(GreedyStringArgument("message"))
    .executes(CommandExecutor { _, args ->
        // args == [player, message]
        val player = args["player"] as Player
        val message = args["message"] as String // Note that the IntegerArgument is not available in the CommandArguments
        player.sendMessage(message)
    })
    .register()

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