yeow-command
v0.2.0
Published
Yeow command builder: typed overloads, completers, permissions
Readme
yeow-command
Yeow 插件的命令构建器:类型化多重重载、Tab 补全、权限节点。
基于 yeow-api 的 registerCommand 封装——为每个命令提供链式 schema 定义(参数类型、枚举、必填/可选)、自动生成的补全与权限声明。
安装
npm install yeow-command环境应有 yeow-api(运行时已内置)。
快速开始
import { Command, CommandSchema } from 'yeow-command';
const cmd = Command.create('warp', { description: '传送到地标', permission: 'myplugin.warp' });
cmd.add(new CommandSchema().string('name'), (p) => {
const name = p.parsed.name; // 类型推断:string
p.sender.sendMessage(`传送到 ${name}`);
});
Command.register(cmd);参数 schema(链式)
new CommandSchema()
.enum('action', ['info', 'delete', 'paste']) // 枚举(补全 + 匹配校验)
.string('name', false) // 可选参数(required=false)
.number('count') // 数字
.player('target') // 在线玩家(自动补全)
.pos('to') // 坐标 x y z(3 token,支持 ~ 相对)- 参数按链式顺序对应命令 token;枚举值参与重载匹配(不匹配的 token 不会命中该重载)。
- 必填参数不能出现在可选参数之后(类型层面拒绝)。
多重重载
cmd.add(new CommandSchema().enum('action', ['info', 'delete']).string('name'), (p) => {
// /proj info myproj → p.parsed.action === 'info', p.parsed.name === 'myproj'
});
cmd.add(new CommandSchema().string('name'), (p) => {
// 单参数重载
});补全
枚举与玩家参数自动补全;自定义补全按参数名配置:
cmd.add(new CommandSchema().string('name'), (p) => { /* ... */ }, {
name: {
completer: async () => Object.keys(warps), // 自定义候选
default: ['spawn'], // 固定候选
maxSuggestions: 20,
},
});权限
Command.create('vip', { permission: { node: 'myplugin.vip', default: 'op' } })permission支持字符串节点或{ node, default }对象(default:'op'/'true'/'false'/'not-op')——与 yeow-apiregisterPermission语义一致。
与 yeow-api 的关系
yeow-command 是 yeow-api 的 registerCommand 的上层封装(构建期纯 TS,无运行时开销);底层事件分发、执行器桥接由运行时完成。底层 API 见 命令文档。
License
MIT
