Hello everyone, new here and just trying to learn the sponge api.
I am currently trying to create a command with a subcommand. My code works, however I am a bit confused on how the help command and invalid argument error output is produced. My code is at the bottom of this post.
So in my example i have created a command called “credit”. It takes one command of a Player. I have also created a sub command of “send” which takes two arguments of a Player and an Integer. Both commands work as they should. My question or problem comes in when someone runs the help command or just /credit and gets the error output.
When I run the command “/help credit” is get the output:
Credit description send|<player>
I assume this output is correct. Has the credit description as tells us that we can run the send sub command or pass a player argument. But if I run the command “/credit send” I get this output
No values matching pattern 'send' present for player! send ^ Usage: /credit send|<player>
Is this the intended output? It is a confusing sentence to begin with, but shouldn’t it show the usage for the send sub command? Not the parent command?
Thanks for reading and helping
Code:
CommandSpec childCommand = CommandSpec.builder() .permission("test.send") .arguments( GenericArguments.player(Texts.of("player"), core.getGame()), GenericArguments.integer(Texts.of("num")) ) .description(Texts.of("send description")) .executor(new CommandExecutor() { @Override public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { src.sendMessage(Texts.of("Child command successfully executed")); return CommandResult.success(); } }).build();
CommandSpec mainCommand = CommandSpec.builder() .permission("test") .child(childCommand, "send") .description(Texts.of("Credit description")) .arguments( GenericArguments.player(Texts.of("player"), core.getGame()) ) .executor(new CommandExecutor() { @Override public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { src.sendMessage(Texts.of("Main command successfully executed")); return CommandResult.success(); } }).build();
core.getGame().getCommandDispatcher().register(core, mainCommand, "credit", "cr");