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.