yeow-api 0.2.111 → 0.2.113

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yeow-api",
3
- "version": "0.2.111",
3
+ "version": "0.2.113",
4
4
  "description": "Yeow API",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
package/src/core.ts CHANGED
@@ -51,6 +51,7 @@ export { assets, read as assetsRead, readSync as assetsReadSync,
51
51
  extractDir as assetsExtractDir, extractDirSync as assetsExtractDirSync } from './assets.js';
52
52
  export { path } from './path.js';
53
53
  export { listen, respond, close, request, requestSync } from './http.js';
54
+ export type { RespondOptions } from './http.js';
54
55
  export { logError } from './log-error.js';
55
56
  export { InstanceId, GUIHandle, BossBarHandle, InventoryHandle } from './instance-id.js';
56
57
  export type { ItemStack } from './item.js';
@@ -90,3 +91,4 @@ export type { MaterialInfo } from './material.js';
90
91
  export { registerService, registerNativeService, request as serviceRequest, subscribe as serviceSubscribe, publish as servicePublish } from './service.js';
91
92
  export type { ServiceResult, NativeServiceResult } from './service.js';
92
93
  export { log, Logger } from './log.js';
94
+ export type { Message } from './message.js';
package/src/event.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { call } from './task.js';
2
2
  import { Player } from './player.js';
3
3
  import { Location } from './location.js';
4
+ import type { Message } from './message.js';
4
5
 
5
6
  // ── Event Data Interfaces ──────────────────────────────────────────
6
7
 
@@ -40,7 +41,8 @@ export interface PlayerCommandEvent {
40
41
  }
41
42
  export interface PlayerDeathEvent {
42
43
  player: Player;
43
- deathMessage: string;
44
+ /** 死亡消息(Message 对象):`{key, args}` 可翻译组件(客户端本地化)+ `{text}` 纯文本兜底,同时传递。 */
45
+ deathMessage: Message;
44
46
  deathType: string;
45
47
  cancelled?: boolean;
46
48
  }
@@ -179,6 +181,10 @@ export interface PlayerItemConsumeEvent {
179
181
  export interface PlayerAdvancementDoneEvent {
180
182
  player: Player;
181
183
  advancement: string;
184
+ /** 进度标题(Message 对象,`{text}` 纯文本;隐藏进度时缺失)。 */
185
+ title?: Message;
186
+ /** 进度描述(Message 对象,`{text}` 纯文本;隐藏进度时缺失)。 */
187
+ description?: Message;
182
188
  }
183
189
  export interface PlayerToggleSneakEvent {
184
190
  player: Player;
@@ -378,7 +384,7 @@ export function eventOn<K extends keyof EventMap>(
378
384
 
379
385
  const cbId = _registerCallback((data: RawEvent) => {
380
386
  const wrapped = adaptEvent(eventType, data);
381
- const dispatchId = data?._dispatchId;
387
+ const eventId = data?._eventId;
382
388
  const cancellable = data?._cancellable;
383
389
  const localMods: { cancelled?: boolean } = {};
384
390
 
@@ -394,7 +400,7 @@ export function eventOn<K extends keyof EventMap>(
394
400
  const complete = (result?: Record<string, unknown>) => {
395
401
  $send('task', {
396
402
  type: 'event.complete',
397
- params: { callbackId: cbId, dispatchId, mods: result },
403
+ params: { eventId, mods: result },
398
404
  cb: '',
399
405
  });
400
406
  };
@@ -407,7 +413,7 @@ export function eventOn<K extends keyof EventMap>(
407
413
  ...(result && typeof result === 'object' ? result : {}),
408
414
  };
409
415
  if (localMods.cancelled) mods.cancelled = true;
410
- $send('task', { type: 'event.complete', params: { callbackId: cbId, dispatchId, mods }, cb: '' });
416
+ $send('task', { type: 'event.complete', params: { eventId, mods }, cb: '' });
411
417
  }, { persistent: true });
412
418
 
413
419
  const gh = globalThis as any;
package/src/http.ts CHANGED
@@ -7,6 +7,18 @@ interface HttpResult {
7
7
  err?: string;
8
8
  }
9
9
 
10
+ /** HTTP 响应选项(respond)。 */
11
+ export interface RespondOptions {
12
+ /** HTTP 状态码(默认 200)。 */
13
+ status?: number;
14
+ /** 文本响应体(UTF-8)。 */
15
+ body?: string;
16
+ /** base64 编码的**二进制**响应体(与 body 互斥,优先)——如从 assets 读取的资源包等。 */
17
+ bodyBase64?: string;
18
+ /** 响应头。 */
19
+ headers?: Record<string, string>;
20
+ }
21
+
10
22
  function _sendHttp(payload: Record<string, unknown>): HttpResult {
11
23
  const r = $send('http', payload);
12
24
  if (!r) return {};
@@ -31,7 +43,7 @@ export function listen(callback: (req: Record<string, unknown>) => void, port?:
31
43
  return result;
32
44
  }
33
45
 
34
- export function respond(serverId: string, connId: string, opts: Record<string, unknown> = {}): void {
46
+ export function respond(serverId: string, connId: string, opts: RespondOptions = {}): void {
35
47
  _sendHttp({ t: 'respond', p: { serverId, connId, ...opts } });
36
48
  }
37
49
 
package/src/message.ts ADDED
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Message —— 可翻译组件 / 纯文本的统一消息对象。
3
+ *
4
+ * - `{ key, args? }`:Minecraft 翻译键组件(如死亡消息 `death.attack.player`),
5
+ * 由客户端按语言本地化;`args` 为翻译参数(字符串/数字/嵌套 Message)
6
+ * - `{ text }`:纯文本(MiniMessage/legacy 解析)——所有实现**至少应支持 text 字段**
7
+ * - 两者同时存在时 `key` 优先
8
+ *
9
+ * 发送消息 API(`player.sendMessage`、`broadcast`、`sendActionBar` 等)与
10
+ * 事件字段(如 `playerDeath.deathMessage`)均接受该对象或纯字符串。
11
+ */
12
+ export interface Message {
13
+ /** Minecraft 翻译键(如 `death.attack.player`)。 */
14
+ key?: string;
15
+ /** 翻译参数(字符串/数字/嵌套 Message)。 */
16
+ args?: (string | number | Message)[];
17
+ /** 纯文本(MiniMessage 解析;key 缺失时使用)。 */
18
+ text?: string;
19
+ }
package/src/player.ts CHANGED
@@ -2,6 +2,7 @@ import { call, post } from './task.js';
2
2
  import type { TaskOptions } from './task.js';
3
3
  import { Location, LocationData } from './location.js';
4
4
  import type { ItemStack } from './item.js';
5
+ import type { Message } from './message.js';
5
6
 
6
7
  interface PlayerData {
7
8
  uuid: string;
@@ -116,8 +117,8 @@ export class Player {
116
117
  get totalExperience(): number { return call<number>('player.getTotalExperience', { uuid: this.uuid }); }
117
118
  getTotalExperience(options?: TaskOptions): Promise<number> { return post<number>('player.getTotalExperience', { uuid: this.uuid }, options); }
118
119
 
119
- sendMessage(msg: string, options?: TaskOptions): Promise<void> { return post('player.sendMessage', { uuid: this.uuid, message: msg }, options); }
120
- sendMessageSync(msg: string, options?: TaskOptions): void { call('player.sendMessage', { uuid: this.uuid, message: msg }, options); }
120
+ sendMessage(msg: string | Message, options?: TaskOptions): Promise<void> { return post('player.sendMessage', { uuid: this.uuid, message: msg }, options); }
121
+ sendMessageSync(msg: string | Message, options?: TaskOptions): void { call('player.sendMessage', { uuid: this.uuid, message: msg }, options); }
121
122
  kick(reason?: string, options?: TaskOptions): Promise<void> { return post('player.kick', { uuid: this.uuid, reason }, options); }
122
123
  kickSync(reason?: string, options?: TaskOptions): void { call('player.kick', { uuid: this.uuid, reason }, options); }
123
124
  sendTitle(title?: string, subtitle?: string, fadeIn?: number, stay?: number, fadeOut?: number, options?: TaskOptions): Promise<void> {
@@ -142,11 +143,14 @@ export class Player {
142
143
  }
143
144
  teleport(loc: Location, options?: TaskOptions): Promise<void> { return post('player.teleport', { uuid: this.uuid, ...loc.toObject() }, options); }
144
145
  teleportSync(loc: Location, options?: TaskOptions): void { call('player.teleport', { uuid: this.uuid, ...loc.toObject() }, options); }
145
- sendActionBar(message: string, options?: TaskOptions): Promise<void> { return post('player.sendActionBar', { uuid: this.uuid, message }, options); }
146
- sendActionBarSync(message: string, options?: TaskOptions): void { call('player.sendActionBar', { uuid: this.uuid, message }, options); }
147
- sendResourcePack(url: string, hash?: string, prompt?: string, force?: boolean, options?: TaskOptions): Promise<void> {
146
+ sendActionBar(message: string | Message, options?: TaskOptions): Promise<void> { return post('player.sendActionBar', { uuid: this.uuid, message }, options); }
147
+ sendActionBarSync(message: string | Message, options?: TaskOptions): void { call('player.sendActionBar', { uuid: this.uuid, message }, options); }
148
+ sendResourcePack(url: string, hash?: string, prompt?: string | Message, force?: boolean, options?: TaskOptions): Promise<void> {
148
149
  return post('player.sendResourcePack', { uuid: this.uuid, url, hash, prompt, force }, options);
149
150
  }
151
+ sendResourcePackSync(url: string, hash?: string, prompt?: string | Message, force?: boolean, options?: TaskOptions): void {
152
+ call('player.sendResourcePack', { uuid: this.uuid, url, hash, prompt, force }, options);
153
+ }
150
154
  getItemInMainHand(options?: TaskOptions): Promise<ItemStack | null> { return post<ItemStack | null>('player.getItemInMainHand', { uuid: this.uuid }, options); }
151
155
  getItemInMainHandSync(options?: TaskOptions): ItemStack | null { return call<ItemStack | null>('player.getItemInMainHand', { uuid: this.uuid }, options); }
152
156
  getItemInOffHand(options?: TaskOptions): Promise<ItemStack | null> { return post<ItemStack | null>('player.getItemInOffHand', { uuid: this.uuid }, options); }
package/src/server.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { call, post } from './task.js';
2
2
  import type { TaskOptions } from './task.js';
3
+ import type { Message } from './message.js';
3
4
 
4
- export function broadcast(msg: string, options?: TaskOptions): Promise<void> { return post('server.broadcast', { message: msg }, options); }
5
- export function broadcastSync(msg: string, options?: TaskOptions): void { call('server.broadcast', { message: msg }, options); }
5
+ export function broadcast(msg: string | Message, options?: TaskOptions): Promise<void> { return post('server.broadcast', { message: msg }, options); }
6
+ export function broadcastSync(msg: string | Message, options?: TaskOptions): void { call('server.broadcast', { message: msg }, options); }
6
7
  export function dispatchCommand(cmd: string, options?: TaskOptions): Promise<boolean> { return post<boolean>('command.dispatch', { command: cmd }, options); }
7
8
  export function dispatchCommandSync(cmd: string, options?: TaskOptions): boolean { return call<boolean>('command.dispatch', { command: cmd }, options); }
8
9
  export function setMotd(motd: string, options?: TaskOptions): Promise<void> { return post('server.setMotd', { motd }, options); }