Optional argument

You can add one optional argument. It must be last it function, has annotation @Optional and be nullable type:

@Command("testCommand")
fun testCommand(sender: Sender, notOptionalArg0: String, @Optional arg1: String?) {
    sender.sendMessage("notOptionalArg0 = $notOptionalArg0")
    //if args has 3 argument
    if (arg1 != null) {
        sender.sendMessage(arg3)
    }
}

If sender did not enter an optional argument it will be null

Last updated