Adding arguments
You can add arguments just by adding parameters to your execute methods.
For example, command /tellmini <players> <message> could look like this (Player API):
@Executesvoid tellMini(CommandSender sender, List<Player> players, @StringArg(GREEDY) String message) { Component component = MiniMessage.miniMessage().deserialize(message); players.forEach(p -> p.sendMessage(component));}On the Brigadier side this adds two new arguments: ArgumentTypes.players() and StringArgumentType.greedy().
The argument values are automatically resolved by StrokkCommands.
// StrokkCommands generates all of this from just the parameters!Commands.literal("tellmini") .then(Commands.argument("players", ArgumentTypes.players()) .then(Commands.argument("message", StringArgumentType.greedyString()) .executes(ctx -> { instance.tellMini( ctx.getSource().getSender(), ctx.getArgument("players", PlayerSelectorArgumentResolver.class).resolve(ctx.getSource()), StringArgumentType.getString(ctx, "message") ); return Command.SINGLE_SUCCESS; }) ) );Literal parameters
Section titled “Literal parameters”To declare literals, you can use the @Literal annotation. You can pass a list of strings for multiple-choice
literals. For example, a command /tellpreset <player> <first|second|last> could be declared as follows:
@Executesvoid executeTellPreset( Player player, @Literal({"first", "second", "last"}) String preset) { final String message = switch (preset) { case "first" -> "You selected the first choice!"; case "second" -> "This is the second one..."; case "last" -> "...and this is the last one."; // This will never happen default -> throw new IllegalStateException("Illegal literal."); };
// Do something with the message player.sendPlainMessage(message);}This will generate the following Brigadier command tree:
Warning: Brigadier jumpscare
final TellPresetCommand instance = new TellPresetCommand();return Commands.literal("tellpreset") .then(Commands.argument("player", ArgumentTypes.player()) .then(Commands.literal("second") .executes(ctx -> { instance.executeTellPreset( ctx.getSource().getSender(), ctx.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(ctx.getSource()).getFirst(), "second" ); return Command.SINGLE_SUCCESS; }) )
.then(Commands.literal("first") .executes(ctx -> { instance.executeTellPreset( ctx.getSource().getSender(), ctx.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(ctx.getSource()).getFirst(), "first" ); return Command.SINGLE_SUCCESS; }) )
.then(Commands.literal("last") .executes(ctx -> { instance.executeTellPreset( ctx.getSource().getSender(), ctx.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(ctx.getSource()).getFirst(), "last" ); return Command.SINGLE_SUCCESS; }) ) ) .build();Primitive argument types
Section titled “Primitive argument types”(( You can find general information on primitive arguments on Paper’s documentation page ))
The following primitive types can be added as parameters:
boolean,Booleanint,Integerlong,Longfloat,Floatdouble,Double
The number ones always have an extra @<Number>Arg(min = <value>, max = <value>) annotation you can add
to optionally specify a max or min value:
/// The speed argument is limited to be 1 or 10 or in-between.@Executesvoid execute(@IntArg(min = 1, max = 10) int speed) { // ...}String argument types
Section titled “String argument types”(( You can find general information on String arguments on Paper’s documentation page ))
When you add a String parameter, StrokkCommands defaults to adding a word string argument type.
You can change the type of the String argument by adding a @StringArg() annotation and specifying
a StringArgType inside. The following types exist:
StringArgType.WORD- The default type. Only supports alphanumerical characters and+,-,_, and..StringArgType.STRING- Similar to theWORDone, but if you add quotes, you can enter any unicode characters.StringargType.GREEDY- Accepts all inputs, but cannot have any arguments follow it.
You can statically import these types for better readability in source code.