Game Events

Catching Events

To catch an event, you can use the executeEvents method.

The index 0 of the events array will be a GameEvent enum. The index 1 will be the event itself.

Here's an example of how you can listen to an event where the holder attacks another player:

@Override
public Object executeEvents(Object... events) {
    if (!GameEvent.HOLDER_DAMAGE_PLAYER.equals(events[0])) return null;

    EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) events[1];
    Player victim = (Player) event.getEntity();

    // Do stuff with the event.
    return null;
}

There's no need to worry about casting the Player class to event.getEntity() as HOLDER_DAMAGE_PLAYER will ensure the method is run only when a player attacks another player.

Last updated