server.event
fn new_bus #
fn new_bus() &Bus
fn new_context #
fn new_context[T](val T) Context[T]
new_context wraps val in a fresh, uncancelled Context.
fn Priority.from #
fn Priority.from[W](input W) !Priority
interface Handler #
interface Handler {
mut:
on_player_join(mut ctx Context[JoinData])
on_player_quit(mut ctx Context[QuitData])
on_player_chat(mut ctx Context[ChatData])
on_player_command(mut ctx Context[CommandData])
on_start_break(mut ctx Context[StartBreakData])
on_block_break(mut ctx Context[BlockBreakData])
on_block_place(mut ctx Context[BlockPlaceData])
on_player_interact(mut ctx Context[InteractData])
on_item_use(mut ctx Context[ItemUseData])
on_player_attack(mut ctx Context[AttackData])
on_player_hurt(mut ctx Context[HurtData])
on_player_death(mut ctx Context[DeathData])
on_player_respawn(mut ctx Context[RespawnData])
on_player_move(mut ctx Context[MoveData])
on_gamemode_change(mut ctx Context[GameModeChangeData])
}
Handler is the dragonfly-style listener interface: one method per event, each receiving a mutable Context. A plugin embeds NopHandler and overrides only the events it cares about.
fn (Context[T]) cancel #
fn (mut c Context[T]) cancel()
cancel marks the event as cancelled. Whether that stops anything is up to the code that dispatched the Context.
fn (Context[T]) is_cancelled #
fn (c &Context[T]) is_cancelled() bool
is_cancelled reports whether any handler cancelled the event.
enum Priority #
enum Priority {
lowest
low
normal
high
highest
monitor
}
Priority orders handlers on the Bus. Lowest runs first so that highest and monitor see the final, already-modified state - monitor handlers are expected to only observe, never mutate. Mirrors PocketMine's EventPriority.
struct AttackData #
struct AttackData {
pub:
victim_runtime_id u64
critical bool
pub mut:
player cmd.Sender
damage f32
}
AttackData is dispatched when a player attacks an entity. player is the attacker, victim_runtime_id the target. Editing damage changes the hit; cancelling it deals no damage and no knockback.
struct BlockBreakData #
struct BlockBreakData {
pub:
x int
y int
z int
block_id int
pub mut:
player cmd.Sender
}
BlockBreakData is dispatched before a block is broken. block_id is the block being removed. Cancelling it leaves the block in place.
struct BlockPlaceData #
struct BlockPlaceData {
pub:
x int
y int
z int
block_id int
pub mut:
player cmd.Sender
}
BlockPlaceData is dispatched before a block is placed. block_id is the block being placed. Cancelling it stops the placement.
struct Bus #
struct Bus {
mut:
handlers []Registered
}
Bus fans a dispatched Context out to every registered handler in priority order. It is the single event pipe the session code talks to; plugins never touch it directly, they register through the plugin Api.
fn (Bus) register #
fn (mut b Bus) register(handler Handler, priority Priority)
register adds a handler at the given priority. Handlers are kept sorted so dispatch always walks lowest -> monitor.
fn (Bus) len #
fn (b &Bus) len() int
len reports how many handlers are registered.
fn (Bus) player_join #
fn (mut b Bus) player_join(mut ctx Context[JoinData])
fn (Bus) player_quit #
fn (mut b Bus) player_quit(mut ctx Context[QuitData])
fn (Bus) player_chat #
fn (mut b Bus) player_chat(mut ctx Context[ChatData])
fn (Bus) player_command #
fn (mut b Bus) player_command(mut ctx Context[CommandData])
fn (Bus) start_break #
fn (mut b Bus) start_break(mut ctx Context[StartBreakData])
fn (Bus) block_break #
fn (mut b Bus) block_break(mut ctx Context[BlockBreakData])
fn (Bus) block_place #
fn (mut b Bus) block_place(mut ctx Context[BlockPlaceData])
fn (Bus) player_interact #
fn (mut b Bus) player_interact(mut ctx Context[InteractData])
fn (Bus) item_use #
fn (mut b Bus) item_use(mut ctx Context[ItemUseData])
fn (Bus) player_attack #
fn (mut b Bus) player_attack(mut ctx Context[AttackData])
fn (Bus) player_hurt #
fn (mut b Bus) player_hurt(mut ctx Context[HurtData])
fn (Bus) player_death #
fn (mut b Bus) player_death(mut ctx Context[DeathData])
fn (Bus) player_respawn #
fn (mut b Bus) player_respawn(mut ctx Context[RespawnData])
fn (Bus) player_move #
fn (mut b Bus) player_move(mut ctx Context[MoveData])
fn (Bus) gamemode_change #
fn (mut b Bus) gamemode_change(mut ctx Context[GameModeChangeData])
struct ChatData #
struct ChatData {
pub mut:
player cmd.Sender
message string
}
ChatData is dispatched for a public chat message. Cancelling it drops the message; editing message rewrites what everyone sees.
struct CommandData #
struct CommandData {
pub mut:
player cmd.Sender
command string
}
CommandData is dispatched before a player command runs. Cancelling it stops the command; editing command rewrites what is executed.
struct Context #
struct Context[T] {
pub mut:
cancelled bool
val T
}
Context is a homage to dragonfly's event.Context[T]. It wraps the subject of an event and lets handlers cancel the outcome or mutate the subject in place. Callers dispatch a Context through the Bus, then read back is_cancelled() and the possibly-modified val to decide what actually happens.
struct DeathData #
struct DeathData {
pub:
params []string
pub mut:
player cmd.Sender
message_key string
}
DeathData is dispatched when a player dies. message_key/params are the death broadcast; cancelling it suppresses the broadcast, editing message_key rewrites it.
struct GameModeChangeData #
struct GameModeChangeData {
pub mut:
player cmd.Sender
mode int
}
GameModeChangeData is dispatched before a player's gamemode changes. Editing mode changes the target gamemode; cancelling it keeps the current one.
struct HurtData #
struct HurtData {
pub:
attacker_name string
pub mut:
player cmd.Sender
amount f32
}
HurtData is dispatched when a player takes damage. player is the victim, attacker_name the source. Editing amount changes the damage; cancelling it negates the damage entirely.
struct InteractData #
struct InteractData {
pub:
x int
y int
z int
face int
pub mut:
player cmd.Sender
}
InteractData is dispatched when a player right-clicks a block, before any placement is decided. Useful for lobby signs and NPC-style interactions. Cancelling it stops the interaction (and any place that would follow).
struct ItemUseData #
struct ItemUseData {
pub:
item_name string
meta int
on_block bool
x int
y int
z int
pub mut:
player cmd.Sender
}
ItemUseData is dispatched right before a held item's effect is applied, either in the air (e.g. a goat horn's sound) or on a block (e.g. bone meal advancing a crop's growth). on_block reports which; x/y/z are only meaningful when on_block is true. Cancelling it stops the effect.
struct JoinData #
struct JoinData {
pub mut:
player cmd.Sender
message string
}
JoinData is dispatched right after a player finishes spawning. Cancelling it suppresses the broadcast join message; editing message changes it.
struct MoveData #
struct MoveData {
pub:
x f32
y f32
z f32
pub mut:
player cmd.Sender
}
MoveData is dispatched when a player moves. Editing x/y/z is ignored; cancel rejects the movement and snaps the player back to where they were.
struct NopHandler #
struct NopHandler {}
NopHandler is an embeddable no-op implementation of Handler. Embed it so a listener satisfies the whole interface while only defining the handlers it actually needs.
fn (NopHandler) on_player_join #
fn (mut h NopHandler) on_player_join(mut ctx Context[JoinData])
fn (NopHandler) on_player_quit #
fn (mut h NopHandler) on_player_quit(mut ctx Context[QuitData])
fn (NopHandler) on_player_chat #
fn (mut h NopHandler) on_player_chat(mut ctx Context[ChatData])
fn (NopHandler) on_player_command #
fn (mut h NopHandler) on_player_command(mut ctx Context[CommandData])
fn (NopHandler) on_start_break #
fn (mut h NopHandler) on_start_break(mut ctx Context[StartBreakData])
fn (NopHandler) on_block_break #
fn (mut h NopHandler) on_block_break(mut ctx Context[BlockBreakData])
fn (NopHandler) on_block_place #
fn (mut h NopHandler) on_block_place(mut ctx Context[BlockPlaceData])
fn (NopHandler) on_player_interact #
fn (mut h NopHandler) on_player_interact(mut ctx Context[InteractData])
fn (NopHandler) on_item_use #
fn (mut h NopHandler) on_item_use(mut ctx Context[ItemUseData])
fn (NopHandler) on_player_attack #
fn (mut h NopHandler) on_player_attack(mut ctx Context[AttackData])
fn (NopHandler) on_player_hurt #
fn (mut h NopHandler) on_player_hurt(mut ctx Context[HurtData])
fn (NopHandler) on_player_death #
fn (mut h NopHandler) on_player_death(mut ctx Context[DeathData])
fn (NopHandler) on_player_respawn #
fn (mut h NopHandler) on_player_respawn(mut ctx Context[RespawnData])
fn (NopHandler) on_player_move #
fn (mut h NopHandler) on_player_move(mut ctx Context[MoveData])
fn (NopHandler) on_gamemode_change #
fn (mut h NopHandler) on_gamemode_change(mut ctx Context[GameModeChangeData])
struct QuitData #
struct QuitData {
pub mut:
player cmd.Sender
message string
}
QuitData is dispatched when a spawned player leaves. Same rules as JoinData.
struct RespawnData #
struct RespawnData {
pub mut:
player cmd.Sender
x f32
y f32
z f32
}
RespawnData is dispatched before a player respawns. Handlers may move the respawn point by editing x/y/z (e.g. to send players back to a lobby).
struct StartBreakData #
struct StartBreakData {
pub:
x int
y int
z int
face int
pub mut:
player cmd.Sender
}
StartBreakData is dispatched the moment a player left clicks a block before any break timer starts, separate from BlockBreakData which only fires once the break actually completes.
- fn new_bus
- fn new_context
- fn Priority.from
- interface Handler
- type Context[T]
- enum Priority
- struct AttackData
- struct BlockBreakData
- struct BlockPlaceData
- struct Bus
- struct ChatData
- struct CommandData
- struct Context
- struct DeathData
- struct GameModeChangeData
- struct HurtData
- struct InteractData
- struct ItemUseData
- struct JoinData
- struct MoveData
- struct NopHandler
- struct QuitData
- struct RespawnData
- struct StartBreakData