Register a Command with the API 3.0.0

Hi there.

I was waiting an answer to my topic about player.getInventory().clear(); and spawn players on a circle shape and I actually saw the API 3.0.0 (Beta) has been released. So I updated my project to this version of the API. I changed all I had to change but I still have a problem with the command registering. Indeed, I had to change the CommandCollable implements to CommandExecutor but the register ask me a CommandCollable.

Do you know why ?

EDIT : Here is the code I use to register the command : game.getCommandManager().register(this, new FreezePlayersCommand(game.getServer(), this), "freeze-all", "freezeall");

@MrAlexan14 As of 3.0.0, commands work differently now. You must build a CommandSpec first, which covers boilerplate stuff like permissions, description, and argument parsing. It is also where you put your CommandExecutor. You then pass CommandSpec to the register function, since CommandSpec extends CommandCallable. I would just recommend reading this whole thing.

@pie_flavor That is incorrect.

CommandSpec is an optional system to manage common tasks used for parsing commands, you don’t Need to use a CommandSpec, but it is highly recommended due to the features it has, which are shared among most sponge plugins making it easier for the users as there is some sort of standard command parsing / tab completion.

@MrAlexan14 Do you have an example of the code in FreezePlayersCommand?

to elaborate on @ryantheleach’s point, if you take a look at FoxGuard and FoxCore, you’ll see that I use a custom CommandDispatcher and custom CommandCallables.

I even have an very advanced argument parser that allows a ton of extra features.

https://github.com/FoxDenStudio/FoxCore/blob/master/src/main/java/net/foxdenstudio/sponge/foxcore/plugin/command/util/AdvCmdParse.java

However, there is A CRAPTON OF BOILERPLATE CODE that you would need to write, so this is not recommended.

To put it into perspective, a normal command requires about 15 lines of code. One of my commands requires about 200 lines of code, in addition to the common boilerplate (The argument parser).

Although I feel the urge to brag about how my command system is freakin’ awesome, it’s not something most people will want to do.

Thank you. I understand now :slightly_smiling:
I just read the wrong part of the guide :wink:

I’ll build a CommandSpec as you said.

@gravityfox I’m sorry but I don’t understand your whole post. I’ll wait this week-end to find its meaning (I’m French, so that’s why I don’t understand it yet).

What you need to get out of it is that there are two ways to write commands, the easy way and the hard way. The easy way is recommended, but if you feel like taking it upon yourself to do everything sponge does and more and better, then by all means go ahead.