外观
plugin API
模块说明
text
Small native plugin authoring facade over the existing managed Worker.Event
python
class EventSDK 说明:
text
One durable delivery. Explicit transaction/save or ack advances its cursor.Event.__init__
python
def __init__(self, context, payload: EventPayload)Event.kind
python
@property
def kind(self) -> strEvent.transaction
python
async def transaction(self, *, commit_id=None)Event.ack
python
async def ack(self)Event.context
python
self.context公开实例属性,在 __init__ 中设置。
Event.payload
python
self.payload公开实例属性,在 __init__ 中设置。
PluginContext
python
class PluginContextPluginContext.__init__
python
def __init__(self, worker, data_dir, *, bus=None)PluginContext.scope
python
@property
def scope(self)SDK 说明:
text
Current opaque scope ID; ownership is always verified by Host.PluginContext.data_dir
python
@property
def data_dir(self) -> PathPluginContext.queries
python
@property
def queries(self) -> QueriesPluginContext.inventory
python
@property
def inventory(self) -> InventoryPluginContext.actors
python
@property
def actors(self) -> ActorsPluginContext.environment
python
@property
def environment(self) -> EnvironmentPluginContext.digging
python
@property
def digging(self) -> BlockDiggingPluginContext.crafting
python
@property
def crafting(self) -> CraftingPluginContext.recipes
python
@property
def recipes(self) -> RecipesPluginContext.artifacts
python
@property
def artifacts(self) -> ArtifactsPluginContext.containers
python
@property
def containers(self) -> ContainersPluginContext.item_actions
python
@property
def item_actions(self) -> ItemActionsPluginContext.notifications
python
@property
def notifications(self) -> NotificationsPluginContext.secrets
python
@property
def secrets(self) -> SecretsPluginContext.log
python
@property
def log(self)PluginContext.installation
python
@property
def installation(self)PluginContext.operations
python
@property
def operations(self) -> OperationsPluginContext.scoreboard
python
@property
def scoreboard(self) -> ScoreboardPluginContext.commands
python
@property
def commands(self) -> CommandsPluginContext.control
python
@property
def control(self) -> RobotControlPluginContext.player_abilities
python
@property
def player_abilities(self) -> PlayerAbilitiesPluginContext.player_actions
python
@property
def player_actions(self) -> PlayerActionsPluginContext.command_queries
python
@property
def command_queries(self) -> CommandQueriesPluginContext.tickingareas
python
@property
def tickingareas(self) -> TickingAreasPluginContext.world
python
@property
def world(self) -> WorldPluginContext.observe_players
python
async def observe_players(self, **options)SDK 说明:
text
Return (stream, initial snapshot); caller closes stream in finally.PluginContext.player_events
python
async def player_events(self, **options)PluginContext.spawn
python
def spawn(self, coroutine, *, name=None)PluginContext.later
python
def later(self, seconds: float, callback, *, name=None)SDK 说明:
text
Run one async callback after a delay, owned and drained by Worker.PluginContext.every
python
def every(self, seconds: float, callback, *, immediate=False, name=None)SDK 说明:
text
Bounded Worker-owned serial timer; drain cancels and joins callbacks.
Interval follows completion, so slow callbacks never accumulate tasks.
A callback failure fails this plugin and is logged by Worker.PluginContext.robot
python
async def robot(self)PluginContext.resolve_player
python
async def resolve_player(
self,
*,
name: str | None = None,
uuid: str | None = None,
xuid: str | None = None,
) -> PlayerIdentityPluginContext.players
python
async def players(self) -> list[PlayerIdentity]PluginContext.player
python
async def player(
self,
*,
name: str | None = None,
uuid: str | None = None,
xuid: str | None = None,
) -> PlayerHandleSDK 说明:
text
Resolve a bound player handle from the current Host roster cache.PluginContext.peer
python
self.peer公开实例属性,在 __init__ 中设置。
PluginContext.storage
python
self.storage公开实例属性,在 __init__ 中设置。
PluginContext.business
python
self.business公开实例属性,在 __init__ 中设置。
PluginContext.services
python
self.services公开实例属性,在 __init__ 中设置。
PluginContext.bus
python
self.bus公开实例属性,在 __init__ 中设置。
PluginContext.scopes
python
self.scopes公开实例属性,在 __init__ 中设置。
PluginContext.positions
python
self.positions公开实例属性,在 __init__ 中设置。
PluginContext.packets
python
self.packets公开实例属性,在 __init__ 中设置。
PluginContext.raw_packets
python
self.raw_packets公开实例属性,在 __init__ 中设置。
PluginContext.chat
python
self.chat公开实例属性,在 __init__ 中设置。
PluginContext.events
python
self.events公开实例属性,在 __init__ 中设置。
PluginContext.chat_waiters
python
self.chat_waiters公开实例属性,在 __init__ 中设置。
PluginContext.config
python
self.config公开实例属性,在 __init__ 中设置。
PluginContext.capabilities
python
self.capabilities公开实例属性,在 __init__ 中设置。
Plugin
python
class PluginSDK 说明:
text
Subclass lifecycle hooks and call run(). No detached tasks or automatic ACK.
Set config_type to a dataclass. Configuration lives in data_dir/config.json
and uses dataclass defaults when absent. Advanced callers may use ctx.peer.
on_validate is read-only; start tasks only from on_start or active handlers.Plugin.config_type
python
config_type = NonePlugin.on_init
python
async def on_init(self, ctx: PluginContext)SDK 说明:
text
Register typed read/service members once per Worker during validation.Plugin.on_validate
python
async def on_validate(self, ctx: PluginContext)Plugin.on_start
python
async def on_start(self, ctx: PluginContext)Plugin.on_stop
python
async def on_stop(self, ctx: PluginContext)Plugin.on_maintenance
python
async def on_maintenance(self, ctx: PluginContext, request)SDK 说明:
text
Optionally seal/release business admission under the plugin's own lock.
Echo request token with status sealed/busy/unsupported (seal), or
released/busy/unsupported (release). Release must be idempotent. This
hook does not drain callbacks or cancel Worker-owned background tasks.Plugin.on_event
python
async def on_event(self, ctx: PluginContext, event: Event)Plugin.serve
python
async def serve(self, peer=None, *, data_dir=None)SDK 说明:
text
Own a fresh IPC connection until Host stops the plugin.Plugin.run
python
def run(self)SDK 说明:
text
Blocking executable entry point. stdout belongs to the IPC protocol.