Skip to content

KairoCustomCommandRegistry

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

The class accessed via ev.customCommandRegistry. Used inside the router.beforeEvents.startup event to register Minecraft custom commands.

Methods

registerCommand

typescript
registerCommand(
  customCommand: CustomCommand,
  callback: (origin: CustomCommandOrigin, ...args: any[]) => CustomCommandResult | undefined,
): void

Registers a Minecraft custom command.

ParameterTypeDescription
customCommandCustomCommandThe command definition
callback(origin: CustomCommandOrigin, ...args: any[]) => CustomCommandResult | undefinedHandler invoked when the command is executed

Returns: void


registerEnum

typescript
registerEnum(name: string, values: string[]): void

Registers an enum for use in command arguments. Can be referenced in a CustomCommand argument definition.

ParameterTypeDescription
namestringThe name of the enum
valuesstring[]The allowed enum values

Returns: void

Usage

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

router.beforeEvents.startup.subscribe((ev) => {
  // Register an enum
  ev.customCommandRegistry.registerEnum('myAddon:targetType', ['player', 'entity', 'block'])

  // Register a command
  ev.customCommandRegistry.registerCommand(
    {
      name: 'myaddon:spawn',
      description: 'Spawn an entity',
      permissionLevel: 'any',
      mandatoryParameters: [
        { name: 'type', type: 'enum', enumName: 'myAddon:targetType' },
      ],
    },
    (origin, type) => {
      console.log(`Command executed: type=${type}`)
      return { success: true }
    },
  )
})

Released under the MIT License.