I want to make a teleport command with the usage /tp [<player>] <target>. Is this possible using generic arguments?
I tried GenericArguments.optional(GenericArguments.player(Text.of("player"))), GenericArguments.player(Text.of("target")));
but when calling with only one argument, the “player” element catches the argument and “target” doesn’t seem able to backtrack, yielding a “Not enough arguments” error.
I could of course swap the arguments but /tp <target> [<player>] seems less intuitive.
This is a bit of a hack, but you can reverse the argument order.
args(player, player)
/tp player1 player2
/tp player1
if(player2.isabsent) player2 = player1
if(commandsource is a player) player 1 = (player) commandSource
else {
throw new CommandException(Text.of(“Missing player argument.”))
}
There’s also probably a solution by wrapping something in an optionalWeak, but I’m not experienced enough to know what without an IDE to test with.
Thanks, that’s what I’ve done. My issue here isn’t really implementing the command, it’s making the command usage in /help look proper. I’d like it to say /tp [<player>] <target>. I guess it’s not extremely important, but it does bug me