Command Manager

Hello,

I’m working on a sort off permission thing and I’m trying to get it working using a command e.g. /mod Jumperlow
when I try to register the command, it says that my classname can’t be used as a variable…
The line of code I’m using is the following: cmdManager.register(this, ModCommand, “mod”);
It gives the error at the ModCommand part. :confused:

Register expects an instance of CommandCallable.
So if your ModCommand is that:

cmdManager.register(this, new ModCommand(), "mod");
1 Like

Still doesn`t work though :confused:

you forgot the new. It is supposed to be new ModCommand().

Please refer to the Oracle Java Tutorials. Sponge does require at least basic knowledge of Java.

Sorry, I have been awake for a long time, remembering things is quite hard…

sorry for spamming your feed, but I`m getting another error…
‘The type java.util.Optional cannot be resolved. It is indirectly referenced from required .class files
The method register(Object, CommandCallable, String…) from the type CommandManager refers to the missing type Optional’

Make sure you have the Java 8 JDK on your build path.

The code you guys are giving me still gives me an error. Am I doing something wrong?

Does ModCommand implement CommandCallable or CommandExecutor?

If it’s CommandExecutor, you need to create a CommandSpec with it and pass that to cmdManager.register instead of new ModCommand(). Check the docs to see how to use CommandSpec.

If it’s CommandCallable, it should work as-is.