Good Afternoon All,
I’m currently working on creating my first sponge plugin and I’m having difficulty getting commands via CommandSpec implemented correctly.
Essentialy it boils down to me having two separate issues, so I’m hoping someone could advise on both.
Issue 1: Unable to use Player as an argument because it crashes out when a Java.lang.NullPointerException when attempting to call the command.
When executing the command, the following error is observed in the Console:
[14:35:41] [Server thread/ERROR] [Sponge]: Error occurred while executing command 'permissionmanager grant plugin.test foleyl2012' for source EntityPlayerMP['foleyl2012'/426, l='world', x=89.48, y=68.00, z=243.70]: null
java.lang.NullPointerException
at org.spongepowered.api.util.command.args.GenericArguments$PlayerCommandElement.getChoices(GenericArguments.java:920) ~[GenericArguments$PlayerCommandElement.class:1.8-1499-2.1DEV-621+spongeproject-ci-b621.git-9c30171977fff8a08188f76c1489a0d8d15bbc47]
at org.spongepowered.api.util.command.args.PatternMatchingCommandElement.parseValue(PatternMatchingCommandElement.java:57) ~[PatternMatchingCommandElement.class:1.8-1499-2.1DEV-621+spongeproject-ci-b621.git-9c30171977fff8a08188f76c1489a0d8d15bbc47]
The commandspecs are implemented as follows:
CommandSpec permissionManagerGrantSpec = CommandSpec.builder()
.description(Texts.of("Grant a permission to a user"))
.permission("permissionmanager.control.grant")
.arguments(
GenericArguments.string(Texts.of("message")),
GenericArguments.onlyOne(GenericArguments.player(Texts.of("player"), this.game)))
.executor(new permissionManagerGrant())
.build();
CommandSpec permissionManagerSpec = CommandSpec.builder()
.description(Texts.of("Permission Manager control interface"))
.permission("permissionmanager.control")
.child(permissionManagerGrantSpec, "grant")
.build();
The registration of the commands are done as below:
this.game.getCommandDispatcher().register(this, permissionManagerSpec, "permissionmanager", "permman", "pm");
Could anyone advise me why this may be happening? (I’ve tried running on a Linux and Windows build, running the latest build of SpongeCoremod.
As for the second issue that I have, it’s actually to do with the usage output of the commands.
In the Chat Window if I run the following
/permissionmanager
I can output saying “Not enough arguments. Usage: /permissionmanager grant|revoke” which is what I would expect to happen because there’s no commandexecutor assigned to the main command
If however I run the following in the Chat Windows
/permissionmanager grant
I receive output saying “Not enough arguments. grant. Usage /permissionmanager grant|revoke”, however I would expect to see a usage statement similar to the following:
Usage: /permissionmanager grant <message> <player>
I’ve tried countless ways of trying to get the usage displayed correctly but I just cannot figure this one out. I’ve even tried creating commands using the Low-Level API by implementing CommandCallable and adjusting the output from getUsage() but all I seem to do with this approach is to get usage displayed twice (once without any parameters and one with custom output by throwing ArgumentParseException)
Can someone please help?
Many Thanks,
Luke