- 
                Notifications
    You must be signed in to change notification settings 
- Fork 2
Arguments Usage
This guide covers how to add and customize arguments for your commands using CommandsAPI v4βs modular system.
You can add arguments to a command using:
- 
addArgs(...)for required arguments
- 
addOptionalArgs(...)for optional arguments
The recommended and modern approach is to pass argument types directly using Java classes:
addArgs("name", String.class);
addOptionalArgs("amount", Integer.class);This method provides better type safety, supports IDE autocompletion, and avoids parsing ambiguity.
While still supported for backward compatibility and for certain features (like infinite), the "name:type" syntax is now deprecated.
Use it only when dealing with infinite arguments:
addArgs("message:infinite"); // still valid and required for infinite supportpublic class GreetCommand extends Command<MyPlugin> {
    public GreetCommand(MyPlugin plugin) {
        super(plugin, "greet");
        setDescription("A greeting command");
        setUsage("/greet <name>");
        // Preferred
        addArgs("name", String.class);
        // Deprecated (only for infinite)
        // addArgs("name:string");
    }
    @Override
    public void execute(CommandSender sender, Arguments args) {
        String name = args.get("name");
        sender.sendMessage("Hello, " + name + "!");
    }
}| Java Type | Identifier | Description | 
|---|---|---|
| String | string | Accepts a basic string. | 
| Integer | integer | Parses as integer. | 
| Double | double | Parses as double. | 
| Long | long | Parses as long. | 
| Player | player | Online player (Spigot only). | 
| OfflinePlayer | offlineplayer | Offline or online player. | 
| String | infinite | Accepts infinite trailing arguments. Must be defined as "name:infinite" | 
β οΈ infiniteonly works using the deprecated syntax"name:infinite".
Create your own argument types by implementing the ArgumentConverter<T> interface:
public class CustomConverter implements ArgumentConverter<CustomType> {
    @Override
    public CustomType apply(String input) {
        return new CustomType(input);
    }
}This form is deprecated and only necessary if using legacy "name:type" syntax (e.g., for infinite):
commandManager.registerConverter(CustomType.class, "customtype", new CustomConverter());Use this form instead:
commandManager.registerConverter(CustomType.class, new CustomConverter());This works with:
addArgs("name", CustomType.class);Support tab-completion by implementing the TabCompleter interface:
public class CustomConverter implements ArgumentConverter<CustomType>, TabCompleter {
    @Override
    public CustomType apply(String input) {
        return new CustomType(input);
    }
    @Override
    public List<String> onCompletion(CommandSender sender) {
        return Arrays.asList("Alice", "Bob", "Charlie");
    }
}addArgs("name", CustomType.class);
addArgs("number", Integer.class, (sender, args) -> Arrays.asList("1", "2", "3"));- Tab completions respect command permissions.
- If a sender lacks permission, they won't see suggestions.
- Prefer using addArgs("name", Type.class)instead of"name:type"
- Use "name:infinite"only for infinite string collection
- Retrieve infinite args using String infinireStr = args.get("name")
- Completions are platform-aware and permission-sensitive
Happy command building with CommandsAPI!