Events
The normalised event surface, cancellation semantics, and the thread contract.
Conduit republishes equivalent provider events as one type. A consumer that cares about "an item was given" writes one handler, whether the stack came from Oraxen, MMOItems or ItemsAdder.
Subscribing
ConduitEvents events = conduit.events();
Subscription all = events.onItem(event -> { /* ... */ });
Subscription gives = events.onItem(ItemAction.Kind.GIVE, event -> { /* ... */ });Each on* method returns a Subscription. Keep it and call unsubscribe();
drop it on disable.
| Method | Fires for |
|---|---|
onPluginReady(Consumer<PluginReadyEvent>) |
A provider loaded or reloaded. |
onBlock(Consumer<BlockEvent>) |
Any block action. |
onBlock(BlockAction.Kind, Consumer<BlockEvent>) |
One block kind. |
onItem(Consumer<ItemEvent>) |
Any item action. |
onItem(ItemAction.Kind, Consumer<ItemEvent>) |
One item kind. |
onResourcePack(Consumer<ResourcePackEvent>) |
Any pack stage. |
onResourcePack(Pack.Stage, Consumer<ResourcePackEvent>) |
One pack stage. |
diagnostics() |
The diagnostics surface. |
The events
BlockEvent — BlockAction.Kind
BREAK · DAMAGE · PLACE · INTERACT · SIT · UNSIT
Carries a BlockAction payload: the block, an optional player, an optional
location, and an optional entity.
ItemEvent — ItemAction.Kind
DROP · GIVE · PICKUP · EQUIP · UNEQUIP · CONSUME · USE · BREAK ·
DAMAGE · CRAFT
Carries an ItemAction payload with the ItemStack and an optional actor.
ResourcePackEvent — Pack.Stage
GENERATED · UPLOADING · UPLOADED · SENT
Carries a Pack: the URL, the hash, and — for SENT only — the player it was
sent to. UPLOADING is the only cancellable stage.
PluginReadyEvent
Carries a Ready: which provider, LOADED or RELOADED, and a count of types
or -1 if the provider does not expose one.
MobEvent is published by the MythicMobs binding but has no onMob
subscription method. It is not currently reachable through ConduitEvents —
see Mob events.
Cancellation
Cancellation is exposed only when the source event genuinely implements
Bukkit's Cancellable. Check before you use it:
conduit.events().onItem(event -> {
if (event.isCancellable()) {
event.setCancelled(true);
}
});Calling setCancelled(true) on an event whose source is not Cancellable
throws UnsupportedOperationException with the provider named. Conduit will not
pretend a cancel succeeded.
The decision is deferred. Conduit collects what subscribers asked for, then
writes it onto the provider's event after every handler has run — so a HIGH or
MONITOR handler's decision is included rather than overwritten.
Two flags, not one
This trips people up, so it is worth stating plainly:
event.setCancelled(true);
event.isCancelRequested(); // true — a subscriber asked
event.isCancelled(); // false — reads the SOURCE, not the requestisCancelled() reports the provider's event, which has not been written to
yet. It only becomes true after applyCancellation() runs, which the engine
calls for you. So:
- Use
isCancelRequested()to ask "did a subscriber ask to cancel?" - Use
isCancelled()to ask "has the provider's event actually been cancelled?"
If you assert isCancelled() immediately after setCancelled(true), you will see
false, and that is correct rather than broken.
MobEvent spells the request flag cancelRequested() rather than
isCancelRequested(). It is the one event that does.
Threads
Check isAsynchronous() before calling into the server.
Every Conduit event carries the source event's own thread flag, not an
assumption. Bukkit's only thread-safety signal is isAsynchronous(): a handler
for a synchronous event is documented to run on the primary server thread, and
one for an asynchronous event is documented not to.
conduit.events().onItem(event -> {
if (event.isAsynchronous()) {
Bukkit.getScheduler().runTask(this, () -> handle(event));
return;
}
handle(event);
});Conduit forwards the flag rather than normalising everything to synchronous because a normalised event that claimed to be synchronous while being dispatched from a worker thread would tell you the main-thread API was safe to touch when it was not — and nothing would say otherwise at the call site or in the log.
If you would rather know once at startup than defend in every handler, read
diagnostics().asynchronous(provider).
Priority
Conduit registers its own provider listeners at MONITOR so it sees the
provider's event after every other plugin has had its turn, and with
ignoreCancelled off — cancellation is decided by Conduit's own subscribers,
so the registration must not short-circuit on a consumer's decision.
Your own handlers use ordinary Bukkit priority, via the annotation:
@EventHandler(priority = EventPriority.HIGHEST)
public void onItem(ItemEvent event) { /* ... */ }Registering a raw handler
Every event class has a static HandlerList, so a hand-written Bukkit
registration works if you need one — this is currently the only route to
MobEvent:
getServer().getPluginManager().registerEvent(
MobEvent.class,
new Listener() { },
EventPriority.NORMAL,
(listener, event) -> handle((MobEvent) event),
this,
false);Prefer the on* methods where they exist. They return a Subscription, they
cannot be registered against the wrong plugin, and they are cleaned up with the
bus.
Mob events
MobEvent carries a MobAction covering MythicMobs: PRE_SPAWN · SPAWN ·
DEATH · DESPAWN · INTERACT · EGG · LOOT · DAMAGE · HEAL · SKILL.
There is no onMob on ConduitEvents. The binding publishes the event and
the coverage report counts the forwards, but the subscription entry point is
missing, so the event is not reachable through the bus. Use the raw
HandlerList registration above until that is added.
For which MythicMobs events are forwarded and which are not, see Coverage.