Basic argument-free ComplexCommand

There are actually a lot of scenarios where Lambda Commands are too verbose and also lack functionality, that’s why Catalyst comes with a built-in massive Command Framework.

Let’s say you have a package com.mycompany.catalystexample.commands that has all the commands of your plugin. Create a new class there called ExampleCommand and make it extend the ComplexCommand class

package com.mycompany.catalystexample.commands;

import com.reigindustries.catalyst.command.factory.ComplexCommand;
import com.reigindustries.catalyst.command.factory.annotations.Command;
import com.reigindustries.catalyst.command.factory.annotations.RequiresPlayer;

@Command("examplecommand|example") /* This is mandatory!!! */
@RequiresPlayer /* This is optional */
@Permission("myplugin.command.example") /* This is optional */
public class ExampleCommand extends ComplexCommand {

    @Index
    public void indexMethod() {

				/* Everything inside a method annotated with @Index will run if the command 
           is called without arguments, or if there are no registered subcommands.
           Yes, I was a PHP developer. */

        getPlayer().sendMessage("You just ran the example command.");

    }

}

Now it’s cool that we have a ComplexCommand class, but it must be registered.

Registering all ComplexCommands in a package

We have a static method for this, that you must call in your plugin’s onEnable():

Catalyst.commands().load(String package);

Where package stands for the exact path of your package, in our case:

public class CatalystExample extends JavaPlugin {

    @Override
    public void onEnable() {

        Catalyst.init(this);

        Catalyst.commands().load("com.mycompany.catalystexample.commands");

    }

}

This will go through all classes in our package and register the commands for us, even if you have more than one.

Subcommands

Now that we’ve acquired the great knowledge of defining plain commands, let’s find out how can i add subcommands to a command.