Skip to content
768 words 4 min read

Custom Events ​

Besides LeviLamina and vanilla Minecraft events, LOICollectionA publishes 12 custom event headers (22 event types in total) under src/LOICollectionA/include/server/Events/. They are all published through ll::event::EventBus, so you listen to them in exactly the same way as any other event.

NOTE

All of these headers are server-only. For the client target, xmake.lua removes them from the distribution manifest with remove_headerfiles("src/LOICollectionA/include/(server/**.h)").

Event reference ​

HeaderEvent typeExposed gettersPublisherWhen it fires
modules/BlacklistEvent.hBlacklistAddBeforeEventgetCause, getTimeEvents adaptersBefore BlacklistPlugin::addBlacklist runs; cancellable
modules/BlacklistEvent.hBlacklistAddAfterEventgetCause, getTimeEvents adaptersAfter BlacklistPlugin::addBlacklist runs
modules/BlacklistEvent.hBlacklistRemoveEventgetTargetEvents adaptersBefore BlacklistPlugin::delBlacklist runs; cancellable
modules/MarketItemSoldEvent.hMarketItemSoldEventgetItemName, getPrice, getTax, getBuyerUuid, getSellerUuid, getTimeMarketPluginWhen a trade completes (published by all three settlement paths: player stores, wanted orders and auctions)
modules/MuteEvent.hMuteAddBeforeEventgetCause, getTimeEvents adaptersBefore MutePlugin::addMute runs; cancellable
modules/MuteEvent.hMuteAddAfterEventgetCause, getTimeEvents adaptersAfter MutePlugin::addMute runs; cancellable
modules/MuteEvent.hMuteRemoveEventgetTargetEvents adaptersBefore MutePlugin::delMute runs; cancellable
modules/NoticeEvent.hNoticeCreateEventgetTarget, getTitle, getPriority, isPoiontoutEvents adaptersBefore NoticePlugin::create runs; cancellable
modules/NoticeEvent.hNoticeDeleteEventgetTargetEvents adaptersBefore NoticePlugin::remove runs; cancellable
modules/RedEnvelopeCompletedEvent.hRedEnvelopeCompletedEventgetEnvelopeId, getSenderUuid, getKingUuid, getKingName, getKingAmount, getTotal, getTimeWalletPluginWhen a red envelope has been fully claimed
modules/WalletTransferEvent.hWalletTransferEventgetFromUuid, getFromName, getToUuid, getToName, getAmount, getFee, getType, getTimeWalletPluginWhen a transfer or fund movement is written to the ledger
player/PlayerContainerEvent.hPlayerOpenContainerEventgetPosition, getDimensionIdEvents adaptersWhen a player opens a container; cancellable
player/PlayerHurtEvent.hPlayerHurtEventgetSource, getDamage, isKnock, isIgnite, getReasonEvents adaptersWhen a player takes damage from another entity; cancellable
player/PlayerScoreChangedEvent.hPlayerScoreChangedEventgetObjective, getScoreChangedType, getScoreEvents adaptersWhen a player's scoreboard score changes; cancellable
server/NetworkPacketEvent.hNetworkPacketBeforeEventgetNetworkIdentifier, getPacket, getSubClientId, getTypeEvents adaptersAround packet send / receive; cancellable
server/NetworkPacketEvent.hNetworkPacketAfterEventgetNetworkIdentifier, getPacket, getSubClientId, getTypeEvents adaptersAfter a packet is sent / received
server/NetworkPacketEvent.hNetworkBroadcastPacketEventgetPacketEvents adaptersWhen a packet is broadcast; cancellable
world/BlockExplodedEvent.hBlockExplodedEventgetPosition, getBlock, getDimensionId, getSourceEvents adaptersWhen a block is destroyed by an explosion
world/RedStoneEvent.hRedStoneEventgetPosition, getSource, getDimensionId, getStrength, isFirstTimeEvents adaptersWhen a redstone wire, redstone torch, comparator or observer receives a redstone update

NOTE

"Events adapters" above refers to the bridge implementations under src/LOICollectionA/modules/server/Events/**. They register themselves through LL_TYPE_INSTANCE_HOOK + ll::event::Emitter, so they are independent of module switches: as soon as the plugin is loaded, these hooks are already active.

Event layers ​

Cancellable events ​

Most events inherit ll::event::Cancellable, so a listener can call event.cancel() to suppress the default behaviour. Whether that actually takes effect depends on the publisher:

  • BlacklistAddBeforeEvent, BlacklistRemoveEvent, MuteAddBeforeEvent, MuteRemoveEvent, NoticeCreateEvent, NoticeDeleteEvent: cancelling makes the corresponding plugin method return immediately and nothing is written to the database
  • PlayerOpenContainerEvent, PlayerHurtEvent, PlayerScoreChangedEvent: cancelling makes the hook return EventResult::StopProcessing or return early, so the vanilla behaviour is blocked
  • NetworkPacketBeforeEvent, NetworkBroadcastPacketEvent: cancelling stops the packet from being sent

WARNING

BlacklistAddAfterEvent and MuteAddAfterEvent are published after the database write has already completed, so cancelling them does not roll back the stored data. Their base classes are not the same either: BlacklistAddAfterEvent inherits from plain PlayerEvent, while MuteAddAfterEvent inherits Cancellable<PlayerEvent> — so it can be cancelled, but that still has no rollback effect.

Non-cancellable events ​

The following events are notifications only and cannot be intercepted: MarketItemSoldEvent, RedEnvelopeCompletedEvent, WalletTransferEvent, BlockExplodedEvent, RedStoneEvent, NetworkPacketAfterEvent.

Enum parameters ​

Three events carry an enum you can branch on:

EnumValuesEvent
PlayerHurtReasonHurt, Effect, ProjectilePlayerHurtEvent
ScoreChangedTypeadd, reducePlayerScoreChangedEvent
NetworkPacketTypesend, receiveNetworkPacketBeforeEvent / NetworkPacketAfterEvent

Listening to events ​

cpp
void XxxPlugin::listenEvent() {
    ll::event::EventBus& eventBus = ll::event::EventBus::getInstance();

    this->mImpl->myListener = eventBus.emplaceListener<LOICollection::server::Events::PlayerScoreChangedEvent>(
        [this](LOICollection::server::Events::PlayerScoreChangedEvent& event) -> void {
            if (event.getScoreChangedType() == LOICollection::server::Events::ScoreChangedType::reduce)
                return;

            // event.cancel(); // only needed for cancellable events
        });
}

void XxxPlugin::unlistenEvent() {
    ll::event::EventBus::getInstance().removeListener(this->mImpl->myListener);
}

TIP

Every event type lives in the LOICollection::server::Events namespace and its header path starts with LOICollectionA/include/server/Events/, for example #include "LOICollectionA/include/server/Events/player/PlayerScoreChangedEvent.h".

WARNING

Always call unlistenEvent() from the module's unregistry(), otherwise a listener outlives the module and keeps a dangling this pointer.

LOICollectionA · A ready-to-use multifunctional plugin set for LeviLamina