☎️Events
Everything about events.
Custom Events
PlayerAnchorDeathEvent
This event is triggered when a player dies from a detonated Respawn Anchor. It provides information about the block, the player that died and the player who detonated the Respawn Anchor.
There are plans to let you change the death message, etc just like in PlayerCrystalDeathEvent
@EventHandler
public void onAnchorDeath(@NotNull PlayerAnchorDeathEvent event) {
Player detonatorAttacker = event.attacker();
Player deadVictim = event.victim();
@Nullable RespawnAnchor anchor = event.anchor();
BlockState block = event.block();
// Do whatever you want to do.
}
attacker()
- Retrieves the Respawn Anchors detonator.victim()
- Retrieves the player that died to the Respawn Anchor explosion detonated by the attacker.anchor()
- Retrieves the (already exploded) Respawn Anchorblock()
- Retrieves theBlockState
of the nullable block.
PlayerCrystalDeathEvent
This event is triggered when a player dies from a destroyed end crystal. It provides information about the end crystal, the player that died and the player who destroyed the end crystal.
This class lets you change the death message, etc.
@EventHandler
public void onAnchorDeath(@NotNull PlayerCrystalDeathEvent event) {
Player killer = event.killer();
Player victim = event.victim();
Entity entity = event.crystal();
// Do whatever you want to do.
}
killer()
- Retrieves the End Crystals destroyer.victim()
- Retrieves the player that died to the End Crystal explosion caused by the killer/attacker.crystal()
- Retrieves the End Crystal associated with this event.
Abstract Event Listener
This is a easy way to automatically register your event listeners.
This currently only supports one singular event per class.
Let's make a PlayerJoinEvent
listener.
package dev.manere.example;
import dev.manere.utils.event.EventListener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.jetbrains.annotations.NotNull;
public class JoinListener extends EventListener<PlayerJoinEvent> {
public JoinListener() {
super(PlayerJoinEvent.class);
}
@Override
protected void execute(@NotNull PlayerJoinEvent event) {
// Do literally anything with the event
}
}
Event Builder
The EventBuilder
is an easy way to create a event listener without creating any new methods, instead by just using a Consumer.
Let's also make a PlayerJoinEvent
listener.
EventBuilder.event(PlayerJoinEvent.class)
.execute(event -> {
// Do anything you want to do with the PlayerJoinEvent.
})
.build() // EventHandler<PlayerJoinEvent>
.ignoreCancelled(false) // Default
.priority(400) // Alternatively: .priority(EventPriority.NORMAL), Default
.register(); // EventCallback<PlayerJoinEvent>
execute(Consumer<E>)
- What should be ran when listening to a event.build()
- Returns theEventHandler<E>
which configures your event listener options.ignoreCancelled(boolean)
- Sets whether cancelled events should be ignored.priority(int)
- Sets the event priority.register()
- Finally registers the event.
PluginWrapper
Events
PluginWrapper
EventsIn PluginWrapper
you will find a events()
method which returns PluginEvents
. It's an alternative to the PluginManager
.
Here's the example PlayerJoinEvent
listener.
public class TestPlugin extends PluginWrapper {
@Override
protected void start() {
events().register(PlayerJoinEvent.class, event -> {
// Whatever you want to do with the PlayerJoinEvent.
});
}
}
Last updated
Was this helpful?