Repository navigation
Events
Hackusate_PvP edited this page Jul 29, 2023
·
4 revisions
Events are actions that happen during the game or in the background. For example, if a player clicks on a button a ButtonClickEvent is called which will allow you to execute code when that happens.
To setup Events you will need to have a EventListener class. An EventListener is an interface that groups Event methods together.
public class ExampleEventListener implements EventListener {
}To add Listeners to the class you will need to use the @Listener annotation and define a method with an Event as a parameter.
@Listener
public void onGameStart(GameStartEvent event) {
// Called when the game starts!
RenJava.getInstance().getLogger().info("Game has started.");
}This goes right inside the class we just created. Next you will have to register the listener inside the class that extends RenJava.
@Override
public void preEnabled() {
// Register Events here.
this.registerListener(new ExampleEventListener());
}You can create as many EventListener classes as you want.