We can create Listeners that have direct access to the GameManager of our minigame, to start we will need to create it.
public class MyListener extends GameInstanceListener<MyMinigame, MyPlugin> {
public MyListener(GameManager<MyMinigame, MyPlugin> gameManager) {
super(gameManager);
}
}
Once created, we can start adding the events we need, in this case, we are going to add one that detects when a player joined to the server and joins them directly to the minigame.
public class MyListener extends GameInstanceListener<MyMinigame, MyPlugin> {
public MyListener(GameManager<MyMinigame, MyPlugin> gameManager) {
super(gameManager);
}
@EventHandler
public void onJoin(PlayerJoinEvent event){
Player player = event.getPlayer();
this.gameManager.joinPlayer(player);
}
}
Now you only need to add it to the GameManager
public final class MyPlugin extends JavaPlugin {
@Override
public void onEnable() {
...
minigameManager.registerListeners(
MyListener::new
);
}
}
And that's it! You now have a Listener with direct access to the Game Manager to add functionalities to your minigame.