Skip to content

These docs describe Bloom 0.1.0, a pre-release. APIs may change before 1.0, and Bloom is not on Maven Central yet (see Installation).

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

JavaView source
Subscription welcome = bloom.events()
        .subscribe(PlayerJoinEvent.class, event -> bloom.messages().send(event.getPlayer(), "&dWelcome!"));
welcome.unsubscribe(); // or let Bloom remove it on shutdown

The 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

JavaView source
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's EventPriority.
  • ignoreCancelled() skips events another listener already cancelled.
  • filter(...) can be called several times; all filters must pass.
  • limit(n) unsubscribes after n handled events, which suits one-off reactions.

Classic listeners

JavaView source
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.