How to register commands on a server?

I have a plugin that I am trying to test the command API with. Here is the code:

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package me.punky.hello;

import com.google.common.base.Optional;

import java.util.List;

import org.slf4j.*;
import org.spongepowered.api.entity.player.Player;
import org.spongepowered.api.event.state.*;
import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.service.command.*;
import org.spongepowered.api.util.command.CommandCallable;
import org.spongepowered.api.util.command.CommandException;
import org.spongepowered.api.util.command.CommandSource;
import org.spongepowered.api.util.event.*;
import org.spongepowered.mod.SpongeGame;

@Plugin(id="commandlet",name="commandlet")
public class Commandlet {
    Logger lg;
    SpongeGame game;
    SimpleCommandService scs;
    @Subscribe
    public void onPreInit(PreInitializationEvent pie){
        lg=pie.getPluginLog();
        lg.info("I hope this works!");
        
     }
    @Subscribe
    public void onServerStarting(ServerStartingEvent sse){
        game=(SpongeGame)sse.getGame();
        scs=game.getCommandDispatcher();
        try{
            scs.register(this, new Comm1(), "cats");
            lg.info("Command \"cats\" registered!");
        }catch(Exception e){
            lg.error(e.getMessage());
        }
    }
    public class Comm1 implements CommandCallable{

        @Override
        public boolean call(CommandSource source, String arguments, List<String> parents) throws CommandException {
            if(source instanceof Player){
                lg.info("MEOW");
                return true;
            }else return false;
        }

        @Override
        public boolean testPermission(CommandSource source) {
            return true;
        }

        @Override
        public Optional<String> getShortDescription() {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        @Override
        public Optional<String> getHelp() {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        @Override
        public String getUsage() {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        @Override
        public List<String> getSuggestions(CommandSource source, String arguments) throws CommandException {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }    
    }
}

Any idea what is wrong with it?
I keep getting a “[18:01:13] [Server thread/ERROR]: The provided plugin object does not have an associated plugin container (in other words, is ‘plugin’ actually your plugin object?” when I run it.

Take a look at this plugin example https://github.com/sk89q/SpongeExample

Oh… okay, thanks!

How do you run a server when Sponge isn’t out yet? :o Can’t run the API tho

You can use a development version, though it is very basic and has very few features at the moment.

Also it will not be a server when it is out. It’s made with Bukkit developers in mind, but it’s a mod for Forge.

I know…I’m just lazy :smiley:

@piepie62 Command registration should be working fine in latest dev from our github repo. For example on how to register commands, check Hidendra’s LWC sponge plugin here - LWC/mods/sponge at 5.0 · Hidendra/LWC · GitHub

Okay, thanks for all of your hard work!