Cannot resolve symbol 'game' and 'plugin'

I am trying to create a command with CommandDispatcher however it cannot resolve ‘game’ and ‘plugin’. I am aware that there have been some changes to the SpongeAPI though I do wish to not scan through Github as it will take some time.

I have capitalized the portion producing the error for clarity thus the capitalization for ‘game’ and ‘plugin’ do not reflect the actual code.

Other Info:
Sponge 2.1 Snapshot
Intellij IDEA Community Edition 15.0.2

Code Snippet:
public class HelloWorldCommand implements CommandExecutor {
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
src.sendMessage(Texts.of(“Hello, world!”));
return CommandResult.success();
}
}

public void onServerInitialization(GameInitializationEvent event) {
    // Global event handlers and command registration are handled here and the plugin should be   functional

CommandSpec myCommandSpec = CommandSpec.builder()
        .description(Texts.of("Hello,world!"))
        .permission("myplugin.command.helloworld")
        .executor(new HelloWorldCommand())
        .build();
GAME.getCommandDispatcher().register(PLUGIN, myCommandSpec, "helloworld", "hello", "test");

}

we can’t see where GAME and PLUGIN is defined, so it makes it awkward to see what the issues are.

if you are getting GAME from the events, you might want to move to either an injected instance from your main plugin class, or use the new Sponge.getGame() static access method.

Otherwise worth checking is your imports, some of the packages changed recently, so you may need to redo them.

2 Likes

I concur with @ryantheleach you need to initialize GAME so somewhere in the main class you need

Game GAME;
and then you need plugin to be initialized above the mainclass like so

@Plugin(id = “Explosion Guard”, name = “ExplosionGuard”, version = “Beta.1.0”)

then import the types Game and plugin and you should be good :slight_smile: