Note: spongePrivate is the name of my plugin.
When i’m trying to start the server i have this error :
[Server thread/ERROR] [Sponge] : Could not pass FMLServerStartedEvent to org.spongepowerd.mod.plugin.SpongeModPluginContainer@b6b6ad0 Java.lang.NullPointerException at me.pogo.spongeprivate.SpongePrivate.onServerStart
And here’s the function onServerStart:
@Listener public void onServerStart(GameInitializationEvent e) { getLogger().info("[SPONGE PRIVATE] Starting the server..."); getCommandManager().register(this, helloWorldSpec, "helloworld", "hello", "test"); getCommandManager().register(this, giveRandomDiamantSpec); }
getLogger() or getCommandManager() or both return null, please post your whole code or we can’t help you
`
@Plugin(id = “me.pogo.spongeprivate”, name = “Sponge Private”, version = “0.0.1”)
public class spongePrivate {
@Listener
public void onServerStart(GameInitializationEvent e) {
getLogger().info("[SPONGE PRIVATE] Demarrage du plugin en cours...");
getCommandManager().register(this, helloWorldSpec, "helloworld", "hello", "test");
getCommandManager().register(this, giveRandomDiamantSpec);
}
private static Logger logger;
@Inject
public static void setLogger(Logger logger) {
logger = logger;
}
public static Logger getLogger() {
return logger;
}
//***********************COMMANDES****************************
//INSTANCES:
private final CMD_HelloWorld inst_helloWorld = new CMD_HelloWorld();
private final CMD_giveRandomDiamant inst_giveRandomDiamant = new CMD_giveRandomDiamant();
//COMMANDES:
CommandSpec helloWorldSpec = CommandSpec.builder()
.description(Text.of("Hello World"))
.permission("spongePrivate.cmd.helloWorld")
.executor(inst_helloWorld)
.build();
CommandSpec giveRandomDiamantSpec = CommandSpec.builder()
.description(Text.of("Give to a random player a dimond."))
.permission("spongePrivate.cmd.giveRandomDiamant")
.executor(inst_giveRandomDiamant)
.build();
}
You need to initialize the logger:
@Listener
public void onPreInit(GamePreInitializationEvent event) {
MyPluginClass.logger = LoggerFactory.getLogger('plugin-name');
}
1 Like
logger = logger
This does not work. When a method argument has the same name as a member variable, the variable name only refers to the method argument. Change to this:
this.logger = logger
1 Like
False. As you can see, it is @Injected.
In fact, I’ve never heard of anyone doing that; if the mere sight of @Inject sends you into a gibbering fit, most people settle for getting the PluginContainer from the PluginManager, and getting the Logger from that.