Events
Subscribe to Bukkit events with lambdas, filters and limits, and have them removed automatically on shutdown.
bloom.events() registers listeners that belong to your plugin and are removed by bloom.shutdown(). You can still
use ordinary @EventHandler listeners alongside it.
Lambda subscriptions
Subscription welcome = bloom.events()
.subscribe(PlayerJoinEvent.class, event -> bloom.messages().send(event.getPlayer(), "&dWelcome!"));
welcome.unsubscribe(); // or let Bloom remove it on shutdownThe handler runs at NORMAL priority and also receives cancelled events. Subscribe to concrete events such as
PlayerJoinEvent; abstract ones such as PlayerEvent have no handler list and are rejected with an explanation.
Priority, filters and limits
bloom.events()
.listen(EntityDamageByEntityEvent.class)
.priority(EventPriority.HIGH)
.ignoreCancelled()
.filter(event -> event.getDamager().getType().name().equals("PLAYER"))
.handler(event -> event.setDamage(event.getDamage() * 0.8));
bloom.events()
.listen(BlockBreakEvent.class)
.limit(1) // unsubscribes itself after the first matching event
.handler(event -> event.getPlayer().sendMessage("Your first block!"));priority(...)takes Bukkit'sEventPriority.ignoreCancelled()skips events another listener already cancelled.filter(...)can be called several times; all filters must pass.limit(n)unsubscribes afternhandled events, which suits one-off reactions.
Classic listeners
static final class QuitListener implements Listener {
@EventHandler
public void onQuit(PlayerQuitEvent event) {
event.setQuitMessage(null);
}
}
static void register(Bloom bloom) {
bloom.events().register(new QuitListener()); // unregistered when Bloom shuts down
}Threads and errors
Handlers run on the thread that fires the event: the main thread for most events, a background thread for
asynchronous events such as AsyncPlayerPreLoginEvent. Exceptions are reported by the server with your plugin's
name, exactly like exceptions from @EventHandler methods.