How will the Command API work?

Continuing the discussion from Command API:

I’m just curious what that stuff means.

How would you go about using this theoretical API?

1 Like

Just recently stopped lurking, so I wasn’t apart of the initial conversation. But it appears as though the Command API will (as it states) be more modular in that, with Bukkit, you could only catch the first command.

Bukkit: /example

// Main class, extends JavaPlugin
public void onEnable() {
    getCommand("example").setExecutor(new ExampleCommand(this));

public class ExampleCommand implements CommandExecutor {
    private final Main plugin;

    public ExampleCommand(Main plugin) {
        this.plugin = plugin;

    public void onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        if (args.length > 0) {
            // Some OOP method of setting up subcommands, or a messy if/else map.

Whereas, with Sponge, it appears as though there will be a built-in registration for sub-commands.

I don’t know this theoretical system well enough to give a decent example code, so you might just want to ignore the mess I’m about to spew.

public void onCommand(Sender sender, CommandContext args) {
    // I have no knowledge of what CommandContext is, so... I guess I'll just pretend it's String[], for now.
    if (args.length > 0) {
        if (args[0].equals("sub")) {
            callable.execute(sender, "sub");

EDIT: Also, as demonstrated above, it also appears as though you won’t actually have to register the main command. Just annote @Command above a method in a valid class. But, again, working with code I haven’t been able to see myself, yet. :stuck_out_tongue:

EDIT2: And yes, the constructor which passes an instance of the main class in the Bukkit example is useless. Blame it on habitual programming.