Skip to content

KairoStartupBeforeEvent

import { router } from '@kairo-js/router'

router.beforeEvents.startup のイベントオブジェクトです。ユーザーが直接インスタンス化することはありません。

Minecraft の worldLoad より前に発火します。API の登録・フック宣言・カスタムコマンド登録・カスタムコンポーネント登録・イベント購読登録は、このイベントハンドラ内でのみ有効です。

プロパティ

addonApi

readonly addonApi: ApiRegistration

API の登録・フック宣言に使用。


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

addonApi の deprecated alias です。


events

readonly events: AddonEventRegistration

addonEvents の deprecated alias です。


使用例

typescript
import { router } from '@kairo-js/router'

router.beforeEvents.startup.subscribe((ev) => {
  // API の登録
  ev.addonApi.register<{ playerId: string }, { balance: number }>(
    'economy/getBalance',
    async ({ playerId }) => {
      return { balance: getBalance(playerId) }
    },
  )

  // 他アドオンのイベントを購読
  ev.addonEvents.on('other-addon', 'someEvent', (payload) => {
    console.log('イベントを受信:', payload)
  })

  // Minecraft custom component の登録
  ev.itemComponentRegistry.registerCustomComponent('my:addon_item', {
    onUse(event) {
      console.log(event.source?.name)
    },
  })

  // カスタムコマンドの登録
  ev.customCommandRegistry.registerCommand(
    { name: 'mycommand', description: 'My command' },
    (origin) => {
      console.log('コマンドを実行しました')
    },
  )
})

Released under the MIT License.