yeow-api 0.2.31 → 0.2.33

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.31",
3
+ "version": "0.2.33",
4
4
  "description": "Yeow API �?TypeScript OOP wrappers over the task protocol",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
package/src/assets.ts CHANGED
@@ -1,41 +1,48 @@
1
- function _sendAssets(payload) {
2
- const r = $send('assets', payload);
3
- if (!r) return undefined;
4
- if (r.err) throw new Error(r.err);
5
- return r;
1
+ function _sendAssets(payload: Record<string, unknown>): unknown {
2
+ const r = $send('assets', payload);
3
+ if (r == null) return undefined;
4
+ if ((r as any)?.err) throw new Error((r as any).err);
5
+ return r;
6
6
  }
7
7
 
8
- export function read(path) {
9
- return new Promise((resolve, reject) => {
10
- try { const r = _sendAssets({ t: 'read', p: { path } }); resolve(r.data); } catch(e) { reject(e); }
11
- });
8
+ export function read(path: string): Promise<string> {
9
+ return new Promise((resolve, reject) => {
10
+ try {
11
+ const r = _sendAssets({ t: 'read', p: { path } }) as { data: string };
12
+ resolve(r.data);
13
+ } catch (e) { reject(e); }
14
+ });
12
15
  }
13
- export function readSync(path) {
14
- return _sendAssets({ t: 'read', p: { path } }).data;
16
+ export function readSync(path: string): string {
17
+ return (_sendAssets({ t: 'read', p: { path } }) as { data: string }).data;
15
18
  }
16
19
 
17
- export function readBase64(path) {
18
- return new Promise((resolve, reject) => {
19
- try { const r = _sendAssets({ t: 'readBase64', p: { path } }); resolve(r.data); } catch(e) { reject(e); }
20
- });
20
+ export function readBase64(path: string): Promise<string> {
21
+ return new Promise((resolve, reject) => {
22
+ try {
23
+ const r = _sendAssets({ t: 'readBase64', p: { path } }) as { data: string };
24
+ resolve(r.data);
25
+ } catch (e) { reject(e); }
26
+ });
21
27
  }
22
- export function readBase64Sync(path) {
23
- return _sendAssets({ t: 'readBase64', p: { path } }).data;
28
+ export function readBase64Sync(path: string): string {
29
+ return (_sendAssets({ t: 'readBase64', p: { path } }) as { data: string }).data;
24
30
  }
25
31
 
26
- export function extract(path, dest) {
27
- return new Promise((resolve, reject) => {
28
- try {
29
- const p = { path };
30
- if (dest) p.dest = dest;
31
- const r = _sendAssets({ t: 'extract', p }); resolve(r.path);
32
- } catch(e) { reject(e); }
33
- });
32
+ export function extract(path: string, dest?: string): Promise<string> {
33
+ return new Promise((resolve, reject) => {
34
+ try {
35
+ const p: Record<string, unknown> = { path };
36
+ if (dest) p.dest = dest;
37
+ const r = _sendAssets({ t: 'extract', p }) as { path: string };
38
+ resolve(r.path);
39
+ } catch (e) { reject(e); }
40
+ });
34
41
  }
35
- export function extractSync(path, dest) {
36
- const p = { path };
37
- if (dest) p.dest = dest;
38
- return _sendAssets({ t: 'extract', p }).path;
42
+ export function extractSync(path: string, dest?: string): string {
43
+ const p: Record<string, unknown> = { path };
44
+ if (dest) p.dest = dest;
45
+ return (_sendAssets({ t: 'extract', p }) as { path: string }).path;
39
46
  }
40
47
 
41
48
  export const assets = { read, readSync, readBase64, readBase64Sync, extract, extractSync };
package/src/block.ts CHANGED
@@ -2,16 +2,18 @@ import { call } from './task.js';
2
2
  import { Location } from './location.js';
3
3
 
4
4
  export class Block {
5
- constructor(
6
- public readonly world: string,
7
- public readonly x: number,
8
- public readonly y: number,
9
- public readonly z: number,
10
- public readonly type: string
11
- ) {}
5
+ constructor(
6
+ public readonly world: string,
7
+ public readonly x: number,
8
+ public readonly y: number,
9
+ public readonly z: number,
10
+ public readonly type: string,
11
+ ) {}
12
12
 
13
- get location(): Location { return new Location(this.x, this.y, this.z, undefined, undefined, this.world); }
14
- isSolid(): boolean { return call('block.isSolid', { world: this.world, x: this.x, y: this.y, z: this.z }) as boolean; }
15
- isLiquid(): boolean { return call('block.isLiquid', { world: this.world, x: this.x, y: this.y, z: this.z }) as boolean; }
16
- isEmpty(): boolean { return call('block.isEmpty', { world: this.world, x: this.x, y: this.y, z: this.z }) as boolean; }
13
+ get location(): Location {
14
+ return new Location(this.x, this.y, this.z, undefined, undefined, this.world);
15
+ }
16
+ isSolid(): boolean { return call<boolean>('block.isSolid', { world: this.world, x: this.x, y: this.y, z: this.z }); }
17
+ isLiquid(): boolean { return call<boolean>('block.isLiquid', { world: this.world, x: this.x, y: this.y, z: this.z }); }
18
+ isEmpty(): boolean { return call<boolean>('block.isEmpty', { world: this.world, x: this.x, y: this.y, z: this.z }); }
17
19
  }
package/src/command.ts CHANGED
@@ -1,85 +1,104 @@
1
1
  import { call } from './task.js';
2
2
 
3
3
  export interface CommandSender {
4
- readonly name: string;
5
- readonly uuid: string;
6
- readonly isPlayer: boolean;
7
- sendMessage(msg: string): void;
4
+ readonly name: string;
5
+ readonly uuid: string;
6
+ readonly isPlayer: boolean;
7
+ sendMessage(msg: string): void;
8
8
  }
9
9
 
10
10
  export interface CommandPayload {
11
- readonly sender: CommandSender;
12
- readonly args: string[];
13
- readonly label: string;
11
+ readonly sender: CommandSender;
12
+ readonly args: string[];
13
+ readonly label: string;
14
14
  }
15
15
 
16
- type CompleterFn = (sender: CommandSender, args: string[]) => string[];
16
+ type CompleterFn = (sender: CommandSender, args: string[]) => string[] | Promise<string[]>;
17
17
  export interface ManualCompleter {
18
- manualRelease: true;
19
- handler: (sender: CommandSender, args: string[], release: (result: string[]) => void) => void;
18
+ manualRelease: true;
19
+ handler: (sender: CommandSender, args: string[], complete: (result: string[]) => void) => void;
20
20
  }
21
21
 
22
22
  export interface CommandOptions {
23
- description?: string;
24
- usage?: string;
25
- permission?: string;
26
- aliases?: string[];
27
- executor: (payload: CommandPayload) => void;
28
- completer?: CompleterFn | ManualCompleter;
23
+ description?: string;
24
+ usage?: string;
25
+ permission?: string;
26
+ aliases?: string[];
27
+ executor: (payload: CommandPayload) => void;
28
+ completer?: CompleterFn | ManualCompleter;
29
29
  }
30
30
 
31
31
  export function registerCommand(name: string, options: CommandOptions): boolean {
32
- const executor = options.executor;
33
- const completer = options.completer;
34
- const pluginName = (globalThis as any).__plugin?.name || 'unknown';
32
+ const executor = options.executor;
33
+ const completer = options.completer;
34
+ const pluginName = __plugin?.name || 'unknown';
35
35
 
36
- const cbId = (globalThis as any)._registerCallback((payload: CommandPayload) => {
37
- const sender = payload.sender;
38
- if (sender?.uuid && sender.isPlayer) {
39
- (sender as any).sendMessage = (msg: string) => {
40
- call('player.sendMessage', { uuid: sender.uuid, message: msg });
41
- };
42
- }
43
- executor(payload);
44
- }, { persistent: true });
36
+ const cbId = _registerCallback((payload: CommandPayload) => {
37
+ const sender = payload.sender;
38
+ if (sender?.uuid && sender.isPlayer) {
39
+ (sender as any).sendMessage = (msg: string) => {
40
+ call('player.sendMessage', { uuid: sender.uuid, message: msg });
41
+ };
42
+ }
43
+ executor(payload);
44
+ }, { persistent: true });
45
+
46
+ let compCbId = '';
47
+ if (completer) {
48
+ let manualRelease = false;
49
+ let completerFn: Function;
50
+ if (typeof completer === 'object' && (completer as any).manualRelease) {
51
+ manualRelease = true;
52
+ completerFn = (completer as any).handler;
53
+ } else {
54
+ completerFn = completer as CompleterFn;
55
+ }
45
56
 
46
- let compCbId = '';
47
- if (completer) {
48
- let manualRelease = false;
49
- let completerFn: Function;
50
- if (typeof completer === 'object' && (completer as any).manualRelease) {
51
- manualRelease = true;
52
- completerFn = (completer as any).handler;
57
+ compCbId = _registerCallback((data: any) => {
58
+ try {
59
+ if (manualRelease) {
60
+ const complete = (result: string[]) => {
61
+ $send('task', {
62
+ type: 'command.tabComplete',
63
+ params: { callbackId: compCbId, completions: result },
64
+ cb: '',
65
+ });
66
+ };
67
+ completerFn(data.sender, data.args, complete);
53
68
  } else {
54
- completerFn = completer as CompleterFn;
69
+ const result = completerFn(data.sender, data.args);
70
+ if (result && typeof result.then === 'function') {
71
+ $send('task', {
72
+ type: 'command.tabComplete',
73
+ params: { callbackId: compCbId, completions: [] },
74
+ cb: '',
75
+ });
76
+ } else {
77
+ $send('task', {
78
+ type: 'command.tabComplete',
79
+ params: { callbackId: compCbId, completions: result || [] },
80
+ cb: '',
81
+ });
82
+ }
55
83
  }
84
+ } catch (_e) {
85
+ $send('task', {
86
+ type: 'command.tabComplete',
87
+ params: { callbackId: compCbId, completions: [] },
88
+ cb: '',
89
+ });
90
+ }
91
+ }, { persistent: true });
92
+ }
56
93
 
57
- compCbId = (globalThis as any)._registerCallback((data: any, release: Function) => {
58
- try {
59
- if (manualRelease) {
60
- completerFn(data.sender, data.args, release);
61
- } else {
62
- const result = completerFn(data.sender, data.args);
63
- if (result && typeof result.then === 'function') {
64
- release([]); // async → release immediate, use ManualCompleter for async
65
- } else {
66
- release(result || []);
67
- }
68
- }
69
- } catch (e) {
70
- release([]);
71
- }
72
- }, { persistent: true });
73
- }
74
-
75
- return call('command.register', {
76
- pluginName,
77
- commandName: name,
78
- callbackId: String(cbId),
79
- completerCbId: compCbId,
80
- description: options.description,
81
- usage: options.usage,
82
- permission: options.permission,
83
- aliases: options.aliases,
84
- }) as boolean;
94
+ return call<boolean>('command.register', {
95
+ pluginName,
96
+ commandName: name,
97
+ callbackId: String(cbId),
98
+ completerCbId: compCbId,
99
+ description: options.description,
100
+ usage: options.usage,
101
+ permission: options.permission,
102
+ aliases: options.aliases,
103
+ });
85
104
  }
package/src/entity.ts CHANGED
@@ -1,36 +1,39 @@
1
1
  import { call, post } from './task.js';
2
- import { Location } from './location.js';
2
+ import { Location, LocationData } from './location.js';
3
3
 
4
4
  export class Entity {
5
- constructor(public readonly uuid: string) {}
5
+ constructor(public readonly uuid: string) {}
6
6
 
7
- get type(): string { return call('entity.getType', { uuid: this.uuid }) as string; }
8
- get name(): string { return call('entity.getName', { uuid: this.uuid }) as string; }
9
- get customName(): string | null { const r = call('entity.getCustomName', { uuid: this.uuid }); return r || null; }
10
- set customName(v: string | null) { call('entity.setCustomName', { uuid: this.uuid, value: v }); }
11
- setCustomNameVisible(v: boolean): Promise<void> { return post('entity.setCustomNameVisible', { uuid: this.uuid, value: v }) as Promise<void>; }
12
- get world(): string | null { return call('entity.getWorld', { uuid: this.uuid }) as string | null; }
13
- get location(): Location | null { const r = call('entity.getLocation', { uuid: this.uuid }); return r ? Location.from(r as any) : null; }
14
- get isGlowing(): boolean { return call('entity.isGlowing', { uuid: this.uuid }) as boolean; }
15
- set isGlowing(v: boolean) { call('entity.setGlowing', { uuid: this.uuid, value: v }); }
16
- get isInvulnerable(): boolean { return call('entity.isInvulnerable', { uuid: this.uuid }) as boolean; }
17
- set isInvulnerable(v: boolean) { call('entity.setInvulnerable', { uuid: this.uuid, value: v }); }
18
- get isSilent(): boolean { return call('entity.isSilent', { uuid: this.uuid }) as boolean; }
19
- set isSilent(v: boolean) { call('entity.setSilent', { uuid: this.uuid, value: v }); }
20
- get hasGravity(): boolean { return call('entity.hasGravity', { uuid: this.uuid }) as boolean; }
21
- set hasGravity(v: boolean) { call('entity.setGravity', { uuid: this.uuid, value: v }); }
22
- get passengers(): string[] { return call('entity.getPassengers', { uuid: this.uuid }) as string[]; }
23
- get vehicle(): string | null { return call('entity.getVehicle', { uuid: this.uuid }) as string | null; }
7
+ get type(): string { return call<string>('entity.getType', { uuid: this.uuid }); }
8
+ get name(): string { return call<string>('entity.getName', { uuid: this.uuid }); }
9
+ get customName(): string | null { return call<string | null>('entity.getCustomName', { uuid: this.uuid }); }
10
+ set customName(v: string | null) { call('entity.setCustomName', { uuid: this.uuid, value: v }); }
11
+ setCustomNameVisible(v: boolean): Promise<void> { return post('entity.setCustomNameVisible', { uuid: this.uuid, value: v }); }
12
+ get world(): string | null { return call<string | null>('entity.getWorld', { uuid: this.uuid }); }
13
+ get location(): Location | null {
14
+ const r = call<LocationData>('entity.getLocation', { uuid: this.uuid });
15
+ return r ? Location.from(r) : null;
16
+ }
17
+ get isGlowing(): boolean { return call<boolean>('entity.isGlowing', { uuid: this.uuid }); }
18
+ set isGlowing(v: boolean) { call('entity.setGlowing', { uuid: this.uuid, value: v }); }
19
+ get isInvulnerable(): boolean { return call<boolean>('entity.isInvulnerable', { uuid: this.uuid }); }
20
+ set isInvulnerable(v: boolean) { call('entity.setInvulnerable', { uuid: this.uuid, value: v }); }
21
+ get isSilent(): boolean { return call<boolean>('entity.isSilent', { uuid: this.uuid }); }
22
+ set isSilent(v: boolean) { call('entity.setSilent', { uuid: this.uuid, value: v }); }
23
+ get hasGravity(): boolean { return call<boolean>('entity.hasGravity', { uuid: this.uuid }); }
24
+ set hasGravity(v: boolean) { call('entity.setGravity', { uuid: this.uuid, value: v }); }
25
+ get passengers(): string[] { return call<string[]>('entity.getPassengers', { uuid: this.uuid }); }
26
+ get vehicle(): string | null { return call<string | null>('entity.getVehicle', { uuid: this.uuid }); }
24
27
 
25
- remove(): Promise<void> { return post('entity.remove', { uuid: this.uuid }) as Promise<void>; }
26
- removeSync(): void { call('entity.remove', { uuid: this.uuid }); }
27
- teleport(loc: Location): Promise<void> { return post('entity.teleport', { uuid: this.uuid, ...loc.toObject() }) as Promise<void>; }
28
- teleportSync(loc: Location): void { call('entity.teleport', { uuid: this.uuid, ...loc.toObject() }); }
28
+ remove(): Promise<void> { return post('entity.remove', { uuid: this.uuid }); }
29
+ removeSync(): void { call('entity.remove', { uuid: this.uuid }); }
30
+ teleport(loc: Location): Promise<void> { return post('entity.teleport', { uuid: this.uuid, ...loc.toObject() }); }
31
+ teleportSync(loc: Location): void { call('entity.teleport', { uuid: this.uuid, ...loc.toObject() }); }
29
32
  }
30
33
 
31
34
  export class LivingEntity extends Entity {
32
- get health(): number { return call('entity.getHealth', { uuid: this.uuid }) as number; }
33
- set health(v: number) { call('entity.setHealth', { uuid: this.uuid, value: v }); }
34
- get maxHealth(): number { return call('entity.getMaxHealth', { uuid: this.uuid }) as number; }
35
- get isDead(): boolean { return call('entity.isDead', { uuid: this.uuid }) as boolean; }
35
+ get health(): number { return call<number>('entity.getHealth', { uuid: this.uuid }); }
36
+ set health(v: number) { call('entity.setHealth', { uuid: this.uuid, value: v }); }
37
+ get maxHealth(): number { return call<number>('entity.getMaxHealth', { uuid: this.uuid }); }
38
+ get isDead(): boolean { return call<boolean>('entity.isDead', { uuid: this.uuid }); }
36
39
  }