Events in separate classes


I’ve been trying to make events work in different classes.
So what I’m trying to do is to have my main file. And then a separate class with an event in it.
The code that I’m using doesn’t work. If someone could help me figuring this out.

public class Core {
public void onInitialization(InitializationEvent e) {
	Game.getEventManager().register(this, new PlayerJoin());
} }

It prints out the following error:

Cannot make a static reference to the non-static method getEventManager() from the type Game

I’m sort of new to Sponge coding so don’t judge ;-;.


you can’t call Game.getEventManager() because getEventManager() isn’t static!
That means you need an Object of Game wich you get by calling e.getGame().
So you need to use e.getGame().getEventManager().register(this, new PlayerJoin());

Thanks, that made more sense. :stuck_out_tongue: