KairoStartupBeforeEvent
import { router } from '@kairo-js/router'
router.beforeEvents.startup 的事件对象。不可直接实例化。
在 Minecraft 的 worldLoad 之前触发。注册 API、声明 hook、注册自定义命令、注册自定义组件以及订阅插件事件,均只能在此事件处理器中进行。
属性
addonApi
readonly addonApi: ApiRegistration
注册 API 和 hook。
addonEvents
readonly addonEvents: AddonEventRegistration
订阅通过 router.emit() 发送的插件事件。
blockComponentRegistry
readonly blockComponentRegistry: BlockComponentRegistry
注册 Minecraft block custom component。
customCommandRegistry
readonly customCommandRegistry: KairoCustomCommandRegistry
注册自定义命令。
itemComponentRegistry
readonly itemComponentRegistry: ItemComponentRegistry
注册 Minecraft item custom component。
api
readonly api: ApiRegistration
ev.api 是 addonApi 的 deprecated alias。
events
readonly events: AddonEventRegistration
ev.events 是 addonEvents 的 deprecated alias。
使用示例
typescript
import { router } from '@kairo-js/router'
router.beforeEvents.startup.subscribe((ev) => {
// Register an API
ev.addonApi.register<{ playerId: string }, { balance: number }>(
'economy/getBalance',
async ({ playerId }) => {
return { balance: getBalance(playerId) }
},
)
// Subscribe to another addon's event
ev.addonEvents.on('other-addon', 'someEvent', (payload) => {
console.log('Event received:', payload)
})
// Register Minecraft custom components
ev.itemComponentRegistry.registerCustomComponent('my:addon_item', {
onUse(event) {
console.log(event.source?.name)
},
})
// Register a custom command
ev.customCommandRegistry.registerCommand(
{ name: 'mycommand', description: 'My command' },
(origin) => {
console.log('Command executed')
},
)
})