Skip to main content

@Arg

Marks a method parameter as a command argument. The framework parses and validates the value automatically based on the parameter's type.

Usage


@Sub(value = "give", description = "Give items")
public void give(CommandContext ctx, @Arg("player") Player target, @Arg("amount") int amount){
// ...
}

Supported Types

Java TypeBehaviour
StringPassed through as-is.
int / IntegerParsed as an integer.
double / DoubleParsed as a double.
float / FloatParsed as a float.
boolean / BooleanParsed as a boolean.
PlayerResolved to an online player by exact name.
OfflinePlayerResolved from the offline player list by exact name.

Choice Arguments

If the argument name matches a key in your command's choices() map, the framework will use that provider for tab-completion and validation instead of the type:


@Override
public Map<String, ChoicesProvider> choices(){
return Map.of("mode", () -> List.of("fast", "slow", "normal"));
}

Optional Arguments

Mark an argument as optional with optional = true. Optional arguments must be trailing and must also be annotated @Nullable:


@Sub(value = "list", description = "List items")
public void list(CommandContext ctx, @Nullable @Arg(value = "page", optional = true) Integer page){
int p = page != null ? page : 1;
}

Attributes

AttributeRequiredDescription
valueThe argument name. Used as the key in CommandContext.args().
optionalWhether the argument is optional. Defaults to false.