Documentation
¶
Overview ¶
Package dfplugin provides a lightweight plugin/event-bus layer for the df-mc/dragonfly Minecraft Bedrock server. Plugins are registered via Register() (typically from init()) and receive callbacks for events emitted by Dragonfly's player.Handler, world.Handler and inventory.Handler interfaces.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Install ¶
Install attaches the composite player and inventory handlers to a player and fires OnJoin hooks. Call this once per player from the srv.Accept() loop.
func InstallWorld ¶ added in v0.2.0
InstallWorld attaches the composite world handler to a world. Call this once per world on server startup (typically for srv.World(), srv.Nether(), srv.End()).
func InventoryHandler ¶ added in v0.2.0
InventoryHandler returns an inventory.Handler that fans out to all registered plugins' OnInventory* callbacks. Attach it to any inventory you want plugins to observe.
Types ¶
type Plugin ¶
type Plugin struct {
Name string
// Player events (attached per player via Install).
OnJoin func(p *player.Player)
OnMove func(ctx *player.Context, p *player.Player, newPos mgl64.Vec3, newRot cube.Rotation)
OnJump func(p *player.Player)
OnTeleport func(ctx *player.Context, p *player.Player, pos mgl64.Vec3)
OnChangeWorld func(p *player.Player, before, after *world.World)
OnToggleSprint func(ctx *player.Context, p *player.Player, after bool)
OnToggleSneak func(ctx *player.Context, p *player.Player, after bool)
OnChat func(ctx *player.Context, p *player.Player, msg *string)
OnFoodLoss func(ctx *player.Context, p *player.Player, from int, to *int)
OnHeal func(ctx *player.Context, p *player.Player, health *float64, src world.HealingSource)
OnHurt func(ctx *player.Context, p *player.Player, damage *float64, immune bool, attackImmunity *time.Duration, src world.DamageSource)
OnDeath func(p *player.Player, src world.DamageSource, keepInv *bool)
OnRespawn func(p *player.Player, pos *mgl64.Vec3, w **world.World)
OnSkinChange func(ctx *player.Context, p *player.Player, skin *skin.Skin)
OnFireExtinguish func(ctx *player.Context, p *player.Player, pos cube.Pos)
OnStartBreak func(ctx *player.Context, p *player.Player, pos cube.Pos)
OnBlockBreak func(ctx *player.Context, p *player.Player, pos cube.Pos, drops *[]item.Stack, xp *int)
OnBlockPlace func(ctx *player.Context, p *player.Player, pos cube.Pos, b world.Block)
OnBlockPick func(ctx *player.Context, p *player.Player, pos cube.Pos, b world.Block)
OnItemUse func(ctx *player.Context, p *player.Player)
OnItemUseOnBlock func(ctx *player.Context, p *player.Player, pos cube.Pos, face cube.Face, clickPos mgl64.Vec3)
OnItemUseOnEntity func(ctx *player.Context, p *player.Player, e world.Entity)
OnItemRelease func(ctx *player.Context, p *player.Player, i item.Stack, dur time.Duration)
OnItemConsume func(ctx *player.Context, p *player.Player, i item.Stack)
OnAttackEntity func(ctx *player.Context, p *player.Player, e world.Entity, force, height *float64, critical *bool)
OnExperienceGain func(ctx *player.Context, p *player.Player, amount *int)
OnPunchAir func(ctx *player.Context, p *player.Player)
OnSignEdit func(ctx *player.Context, p *player.Player, pos cube.Pos, frontSide bool, oldText, newText string)
OnSleep func(ctx *player.Context, p *player.Player, sendReminder *bool)
OnLecternPageTurn func(ctx *player.Context, p *player.Player, pos cube.Pos, oldPage int, newPage *int)
OnItemDamage func(ctx *player.Context, p *player.Player, i item.Stack, damage *int)
OnItemPickup func(ctx *player.Context, p *player.Player, i *item.Stack)
OnHeldSlotChange func(ctx *player.Context, p *player.Player, from, to int)
OnItemDrop func(ctx *player.Context, p *player.Player, s item.Stack)
OnTransfer func(ctx *player.Context, p *player.Player, addr *net.UDPAddr)
OnCommand func(ctx *player.Context, p *player.Player, command cmd.Command, args []string)
OnQuit func(p *player.Player)
OnDiagnostics func(p *player.Player, d session.Diagnostics)
// World events (attached per world via InstallWorld).
OnLiquidFlow func(ctx *world.Context, from, into cube.Pos, liquid world.Liquid, replaced world.Block)
OnLiquidDecay func(ctx *world.Context, pos cube.Pos, before, after world.Liquid)
OnLiquidHarden func(ctx *world.Context, hardenedPos cube.Pos, liquidHardened, otherLiquid, newBlock world.Block)
OnSound func(ctx *world.Context, s world.Sound, pos mgl64.Vec3)
OnFireSpread func(ctx *world.Context, from, to cube.Pos)
OnBlockBurn func(ctx *world.Context, pos cube.Pos)
OnCropTrample func(ctx *world.Context, pos cube.Pos)
OnLeavesDecay func(ctx *world.Context, pos cube.Pos)
OnEntitySpawn func(tx *world.Tx, e world.Entity)
OnEntityDespawn func(tx *world.Tx, e world.Entity)
OnExplosion func(ctx *world.Context, position mgl64.Vec3, entities *[]world.Entity, blocks *[]cube.Pos, itemDropChance *float64, spawnFire *bool)
OnWorldClose func(tx *world.Tx)
// Inventory events. Attached to the player's main inventory by Install.
// Hook other inventories (armour, ender chest, containers) manually with
// inv.Handle(dfplugin.InventoryHandler()).
OnInventoryTake func(ctx *inventory.Context, slot int, it item.Stack)
OnInventoryPlace func(ctx *inventory.Context, slot int, it item.Stack)
OnInventoryDrop func(ctx *inventory.Context, slot int, it item.Stack)
}
Plugin describes a unit of behavior. Set only the fields whose events you care about — the rest stay nil and are skipped at dispatch time.