yeow-api 0.2.39 → 0.2.41

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.39",
3
+ "version": "0.2.41",
4
4
  "description": "Yeow API �?TypeScript OOP wrappers over the task protocol",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -0,0 +1,26 @@
1
+ import { post } from './task.js';
2
+
3
+ export interface AdvancementProgress {
4
+ awardedCriteria: string[];
5
+ remainingCriteria: string[];
6
+ }
7
+
8
+ export function grant(uuid: string, key: string): Promise<boolean> {
9
+ return post<boolean>('advancement.grant', { uuid, key });
10
+ }
11
+
12
+ export function revoke(uuid: string, key: string): Promise<boolean> {
13
+ return post<boolean>('advancement.revoke', { uuid, key });
14
+ }
15
+
16
+ export function getProgress(uuid: string, key: string): Promise<AdvancementProgress | null> {
17
+ return post<AdvancementProgress | null>('advancement.getProgress', { uuid, key });
18
+ }
19
+
20
+ export function awardCriteria(uuid: string, key: string, criteria: string): Promise<boolean> {
21
+ return post<boolean>('advancement.awardCriteria', { uuid, key, criteria });
22
+ }
23
+
24
+ export function revokeCriteria(uuid: string, key: string, criteria: string): Promise<boolean> {
25
+ return post<boolean>('advancement.revokeCriteria', { uuid, key, criteria });
26
+ }
package/src/assets.ts CHANGED
@@ -5,39 +5,37 @@ function _sendAssets(payload: Record<string, unknown>): unknown {
5
5
  return r;
6
6
  }
7
7
 
8
- export function read(path: string): Promise<string> {
8
+ function _sendAssetsAsync(payload: Record<string, unknown>): Promise<unknown> {
9
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); }
10
+ const cbId = _registerCallback((result: unknown) => {
11
+ if ((result as any)?.err) reject(new Error((result as any).err));
12
+ else resolve(result);
13
+ });
14
+ $send('assets', { ...payload, cb: cbId });
14
15
  });
15
16
  }
17
+
18
+ export async function read(path: string): Promise<string> {
19
+ const r = await _sendAssetsAsync({ t: 'read', p: { path } }) as { data: string };
20
+ return r.data;
21
+ }
16
22
  export function readSync(path: string): string {
17
23
  return (_sendAssets({ t: 'read', p: { path } }) as { data: string }).data;
18
24
  }
19
25
 
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
- });
26
+ export async function readBase64(path: string): Promise<string> {
27
+ const r = await _sendAssetsAsync({ t: 'readBase64', p: { path } }) as { data: string };
28
+ return r.data;
27
29
  }
28
30
  export function readBase64Sync(path: string): string {
29
31
  return (_sendAssets({ t: 'readBase64', p: { path } }) as { data: string }).data;
30
32
  }
31
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
+ export async function extract(path: string, dest?: string): Promise<string> {
35
+ const p: Record<string, unknown> = { path };
36
+ if (dest) p.dest = dest;
37
+ const r = await _sendAssetsAsync({ t: 'extract', p }) as { path: string };
38
+ return r.path;
41
39
  }
42
40
  export function extractSync(path: string, dest?: string): string {
43
41
  const p: Record<string, unknown> = { path };
package/src/bossbar.ts ADDED
@@ -0,0 +1,59 @@
1
+ import { post } from './task.js';
2
+ import { BossBarHandle } from './instance-id.js';
3
+
4
+ export interface BossBarOptions {
5
+ color?: string;
6
+ style?: string;
7
+ progress?: number;
8
+ visible?: boolean;
9
+ }
10
+
11
+ export async function createBossBar(title: string, options?: BossBarOptions): Promise<BossBarHandle> {
12
+ const h = new BossBarHandle();
13
+ await post('bossbar.create', { id: h.toString(), title, ...options });
14
+ return h;
15
+ }
16
+
17
+ export function destroy(id: BossBarHandle): Promise<void> {
18
+ return post('bossbar.destroy', { id: id.toString() });
19
+ }
20
+
21
+ export function setTitle(id: BossBarHandle, title: string): Promise<void> {
22
+ return post('bossbar.setTitle', { id: id.toString(), title });
23
+ }
24
+
25
+ export function setProgress(id: BossBarHandle, progress: number): Promise<void> {
26
+ return post('bossbar.setProgress', { id: id.toString(), progress });
27
+ }
28
+
29
+ export function setColor(id: BossBarHandle, color: string): Promise<void> {
30
+ return post('bossbar.setColor', { id: id.toString(), color });
31
+ }
32
+
33
+ export function setStyle(id: BossBarHandle, style: string): Promise<void> {
34
+ return post('bossbar.setStyle', { id: id.toString(), style });
35
+ }
36
+
37
+ export function setVisible(id: BossBarHandle, visible: boolean): Promise<void> {
38
+ return post('bossbar.setVisible', { id: id.toString(), visible });
39
+ }
40
+
41
+ export function addPlayer(id: BossBarHandle, uuid: string): Promise<void> {
42
+ return post('bossbar.addPlayer', { id: id.toString(), uuid });
43
+ }
44
+
45
+ export function removePlayer(id: BossBarHandle, uuid: string): Promise<void> {
46
+ return post('bossbar.removePlayer', { id: id.toString(), uuid });
47
+ }
48
+
49
+ export function removeAll(id: BossBarHandle): Promise<void> {
50
+ return post('bossbar.removeAll', { id: id.toString() });
51
+ }
52
+
53
+ export function addFlag(id: BossBarHandle, flag: string): Promise<void> {
54
+ return post('bossbar.addFlag', { id: id.toString(), flag });
55
+ }
56
+
57
+ export function removeFlag(id: BossBarHandle, flag: string): Promise<void> {
58
+ return post('bossbar.removeFlag', { id: id.toString(), flag });
59
+ }
package/src/entity.ts CHANGED
@@ -2,33 +2,70 @@ import { call, post } from './task.js';
2
2
  import { Location, LocationData } from './location.js';
3
3
 
4
4
  export class Entity {
5
+ static get(uuid: string): Promise<Entity | null> {
6
+ return post<{ uuid: string }>('entity.get', { uuid }).then((d) => (d ? new Entity(d.uuid) : null));
7
+ }
8
+ static getSync(uuid: string): Entity | null {
9
+ const d = call<{ uuid: string }>('entity.get', { uuid });
10
+ return d ? new Entity(d.uuid) : null;
11
+ }
12
+
5
13
  constructor(public readonly uuid: string) {}
6
14
 
7
15
  get type(): string { return call<string>('entity.getType', { uuid: this.uuid }); }
16
+ getType(): Promise<string> { return post<string>('entity.getType', { uuid: this.uuid }); }
17
+
8
18
  get name(): string { return call<string>('entity.getName', { uuid: this.uuid }); }
19
+ getName(): Promise<string> { return post<string>('entity.getName', { uuid: this.uuid }); }
20
+
9
21
  get customName(): string | null { return call<string | null>('entity.getCustomName', { uuid: this.uuid }); }
10
22
  set customName(v: string | null) { call('entity.setCustomName', { uuid: this.uuid, value: v }); }
23
+ getCustomName(): Promise<string | null> { return post<string | null>('entity.getCustomName', { uuid: this.uuid }); }
24
+ setCustomName(v: string | null): Promise<void> { return post('entity.setCustomName', { uuid: this.uuid, value: v }); }
25
+
11
26
  setCustomNameVisible(v: boolean): Promise<void> {
12
27
  return post('entity.setCustomNameVisible', { uuid: this.uuid, value: v });
13
28
  }
14
29
  setCustomNameVisibleSync(v: boolean): void {
15
30
  call('entity.setCustomNameVisible', { uuid: this.uuid, value: v });
16
31
  }
32
+
17
33
  get world(): string | null { return call<string | null>('entity.getWorld', { uuid: this.uuid }); }
34
+ getWorld(): Promise<string | null> { return post<string | null>('entity.getWorld', { uuid: this.uuid }); }
35
+
18
36
  get location(): Location | null {
19
37
  const r = call<LocationData>('entity.getLocation', { uuid: this.uuid });
20
38
  return r ? Location.from(r) : null;
21
39
  }
40
+ getLocation(): Promise<Location | null> {
41
+ return post<LocationData>('entity.getLocation', { uuid: this.uuid }).then((r) => (r ? Location.from(r) : null));
42
+ }
43
+
22
44
  get isGlowing(): boolean { return call<boolean>('entity.isGlowing', { uuid: this.uuid }); }
23
45
  set isGlowing(v: boolean) { call('entity.setGlowing', { uuid: this.uuid, value: v }); }
46
+ isGlowingAsync(): Promise<boolean> { return post<boolean>('entity.isGlowing', { uuid: this.uuid }); }
47
+ setGlowing(v: boolean): Promise<void> { return post('entity.setGlowing', { uuid: this.uuid, value: v }); }
48
+
24
49
  get isInvulnerable(): boolean { return call<boolean>('entity.isInvulnerable', { uuid: this.uuid }); }
25
50
  set isInvulnerable(v: boolean) { call('entity.setInvulnerable', { uuid: this.uuid, value: v }); }
51
+ isInvulnerableAsync(): Promise<boolean> { return post<boolean>('entity.isInvulnerable', { uuid: this.uuid }); }
52
+ setInvulnerable(v: boolean): Promise<void> { return post('entity.setInvulnerable', { uuid: this.uuid, value: v }); }
53
+
26
54
  get isSilent(): boolean { return call<boolean>('entity.isSilent', { uuid: this.uuid }); }
27
55
  set isSilent(v: boolean) { call('entity.setSilent', { uuid: this.uuid, value: v }); }
56
+ isSilentAsync(): Promise<boolean> { return post<boolean>('entity.isSilent', { uuid: this.uuid }); }
57
+ setSilent(v: boolean): Promise<void> { return post('entity.setSilent', { uuid: this.uuid, value: v }); }
58
+
28
59
  get hasGravity(): boolean { return call<boolean>('entity.hasGravity', { uuid: this.uuid }); }
29
60
  set hasGravity(v: boolean) { call('entity.setGravity', { uuid: this.uuid, value: v }); }
61
+ hasGravityAsync(): Promise<boolean> { return post<boolean>('entity.hasGravity', { uuid: this.uuid }); }
62
+ setGravity(v: boolean): Promise<void> { return post('entity.setGravity', { uuid: this.uuid, value: v }); }
63
+
30
64
  get passengers(): string[] { return call<string[]>('entity.getPassengers', { uuid: this.uuid }); }
65
+ getPassengers(): Promise<string[]> { return post<string[]>('entity.getPassengers', { uuid: this.uuid }); }
66
+
31
67
  get vehicle(): string | null { return call<string | null>('entity.getVehicle', { uuid: this.uuid }); }
68
+ getVehicle(): Promise<string | null> { return post<string | null>('entity.getVehicle', { uuid: this.uuid }); }
32
69
 
33
70
  remove(): Promise<void> { return post('entity.remove', { uuid: this.uuid }); }
34
71
  removeSync(): void { call('entity.remove', { uuid: this.uuid }); }
@@ -39,6 +76,12 @@ export class Entity {
39
76
  export class LivingEntity extends Entity {
40
77
  get health(): number { return call<number>('entity.getHealth', { uuid: this.uuid }); }
41
78
  set health(v: number) { call('entity.setHealth', { uuid: this.uuid, value: v }); }
79
+ getHealth(): Promise<number> { return post<number>('entity.getHealth', { uuid: this.uuid }); }
80
+ setHealth(v: number): Promise<void> { return post('entity.setHealth', { uuid: this.uuid, value: v }); }
81
+
42
82
  get maxHealth(): number { return call<number>('entity.getMaxHealth', { uuid: this.uuid }); }
83
+ getMaxHealth(): Promise<number> { return post<number>('entity.getMaxHealth', { uuid: this.uuid }); }
84
+
43
85
  get isDead(): boolean { return call<boolean>('entity.isDead', { uuid: this.uuid }); }
86
+ isDeadAsync(): Promise<boolean> { return post<boolean>('entity.isDead', { uuid: this.uuid }); }
44
87
  }
package/src/event.ts CHANGED
@@ -192,6 +192,27 @@ export interface ServerCommandEvent {
192
192
  command: string;
193
193
  sender: string;
194
194
  }
195
+ export interface InventoryClickEvent {
196
+ player: Player;
197
+ slot: number;
198
+ hotbarKey: number;
199
+ action: string;
200
+ inventoryType: string;
201
+ isLeftClick: boolean;
202
+ isRightClick: boolean;
203
+ isShiftClick: boolean;
204
+ clickedItem: ItemData | null;
205
+ cursorItem: ItemData | null;
206
+ }
207
+ interface ItemData {
208
+ type: string;
209
+ amount: number;
210
+ }
211
+ export interface PlayerResourcePackStatusEvent {
212
+ player: Player;
213
+ status: string;
214
+ hash: string;
215
+ }
195
216
 
196
217
  type EventMap = {
197
218
  playerJoin: PlayerJoinEvent;
@@ -230,6 +251,8 @@ type EventMap = {
230
251
  serverCommand: ServerCommandEvent;
231
252
  playerTeleport: PlayerTeleportEvent;
232
253
  playerItemConsume: PlayerItemConsumeEvent;
254
+ inventoryClick: InventoryClickEvent;
255
+ playerResourcePackStatus: PlayerResourcePackStatusEvent;
233
256
  };
234
257
 
235
258
  type RawEvent = Record<string, unknown> & { _cancellable?: boolean };
package/src/fs.ts CHANGED
@@ -5,93 +5,89 @@ function _sendFs(payload: Record<string, unknown>): unknown {
5
5
  return r;
6
6
  }
7
7
 
8
- export function readFile(path: string): Promise<string> {
8
+ function _sendFsAsync(payload: Record<string, unknown>): Promise<unknown> {
9
9
  return new Promise((resolve, reject) => {
10
- try {
11
- const r = _sendFs({ t: 'readFile', p: { path } }) as { data: string };
12
- resolve(r.data);
13
- } catch (e) { reject(e); }
10
+ const cbId = _registerCallback((result: unknown) => {
11
+ if ((result as any)?.err) reject(new Error((result as any).err));
12
+ else resolve(result);
13
+ });
14
+ $send('fs', { ...payload, cb: cbId });
14
15
  });
15
16
  }
17
+
18
+ export async function readFile(path: string): Promise<string> {
19
+ const r = await _sendFsAsync({ t: 'readFile', p: { path } }) as { data: string };
20
+ return r.data;
21
+ }
16
22
  export function readFileSync(path: string): string {
17
23
  return (_sendFs({ t: 'readFile', p: { path } }) as { data: string }).data;
18
24
  }
19
25
 
20
- export function readFileBase64(path: string): Promise<string> {
21
- return new Promise((resolve, reject) => {
22
- try {
23
- const r = _sendFs({ t: 'readBase64', p: { path } }) as { data: string };
24
- resolve(r.data);
25
- } catch (e) { reject(e); }
26
- });
26
+ export async function readFileBase64(path: string): Promise<string> {
27
+ const r = await _sendFsAsync({ t: 'readBase64', p: { path } }) as { data: string };
28
+ return r.data;
27
29
  }
28
30
  export function readFileBase64Sync(path: string): string {
29
31
  return (_sendFs({ t: 'readBase64', p: { path } }) as { data: string }).data;
30
32
  }
31
33
 
32
- export function writeFile(path: string, data: string): Promise<void> {
33
- return new Promise((resolve, reject) => {
34
- try { _sendFs({ t: 'writeFile', p: { path, data } }); resolve(); }
35
- catch (e) { reject(e); }
36
- });
34
+ export async function writeFile(path: string, data: string): Promise<void> {
35
+ await _sendFsAsync({ t: 'writeFile', p: { path, data } });
37
36
  }
38
37
  export function writeFileSync(path: string, data: string): void {
39
38
  _sendFs({ t: 'writeFile', p: { path, data } });
40
39
  }
41
40
 
42
- export function writeFileBase64(path: string, data: string): Promise<void> {
43
- return new Promise((resolve, reject) => {
44
- try { _sendFs({ t: 'writeBase64', p: { path, data } }); resolve(); }
45
- catch (e) { reject(e); }
46
- });
41
+ export async function writeFileBase64(path: string, data: string): Promise<void> {
42
+ await _sendFsAsync({ t: 'writeBase64', p: { path, data } });
47
43
  }
48
44
  export function writeFileBase64Sync(path: string, data: string): void {
49
45
  _sendFs({ t: 'writeBase64', p: { path, data } });
50
46
  }
51
47
 
52
- export function exists(path: string): Promise<boolean> {
53
- return new Promise((resolve, reject) => {
54
- try {
55
- const r = _sendFs({ t: 'exists', p: { path } });
56
- resolve(r === true || String(r) === 'true');
57
- } catch (e) { reject(e); }
58
- });
48
+ export async function appendFile(path: string, data: string): Promise<void> {
49
+ await _sendFsAsync({ t: 'appendFile', p: { path, data } });
50
+ }
51
+ export function appendFileSync(path: string, data: string): void {
52
+ _sendFs({ t: 'appendFile', p: { path, data } });
53
+ }
54
+
55
+ export async function exists(path: string): Promise<boolean> {
56
+ const r = await _sendFsAsync({ t: 'exists', p: { path } });
57
+ return r === true || String(r) === 'true';
59
58
  }
60
59
  export function existsSync(path: string): boolean {
61
60
  const r = _sendFs({ t: 'exists', p: { path } });
62
61
  return r === true || String(r) === 'true';
63
62
  }
64
63
 
65
- export function deleteFile(path: string): Promise<boolean> {
66
- return new Promise((resolve, reject) => {
67
- try {
68
- const r = _sendFs({ t: 'delete', p: { path } });
69
- resolve(r === true || String(r) === 'true');
70
- } catch (e) { reject(e); }
71
- });
64
+ export async function isDirectory(path: string): Promise<boolean> {
65
+ const r = await _sendFsAsync({ t: 'isDirectory', p: { path } });
66
+ return r === true || String(r) === 'true';
67
+ }
68
+ export function isDirectorySync(path: string): boolean {
69
+ const r = _sendFs({ t: 'isDirectory', p: { path } });
70
+ return r === true || String(r) === 'true';
71
+ }
72
+
73
+ export async function deleteFile(path: string): Promise<boolean> {
74
+ const r = await _sendFsAsync({ t: 'delete', p: { path } });
75
+ return r === true || String(r) === 'true';
72
76
  }
73
77
  export function deleteFileSync(path: string): boolean {
74
78
  const r = _sendFs({ t: 'delete', p: { path } });
75
79
  return r === true || String(r) === 'true';
76
80
  }
77
81
 
78
- export function mkdir(path: string): Promise<void> {
79
- return new Promise((resolve, reject) => {
80
- try { _sendFs({ t: 'mkdir', p: { path } }); resolve(); }
81
- catch (e) { reject(e); }
82
- });
82
+ export async function mkdir(path: string): Promise<void> {
83
+ await _sendFsAsync({ t: 'mkdir', p: { path } });
83
84
  }
84
85
  export function mkdirSync(path: string): void {
85
86
  _sendFs({ t: 'mkdir', p: { path } });
86
87
  }
87
88
 
88
- export function list(path: string): Promise<string[]> {
89
- return new Promise((resolve, reject) => {
90
- try {
91
- const r = _sendFs({ t: 'list', p: { path } });
92
- resolve(r as string[]);
93
- } catch (e) { reject(e); }
94
- });
89
+ export async function list(path: string): Promise<string[]> {
90
+ return await _sendFsAsync({ t: 'list', p: { path } }) as string[];
95
91
  }
96
92
  export function listSync(path: string): string[] {
97
93
  return _sendFs({ t: 'list', p: { path } }) as string[];
@@ -100,5 +96,7 @@ export function listSync(path: string): string[] {
100
96
  export const fs = {
101
97
  readFile, readFileSync, readFileBase64, readFileBase64Sync,
102
98
  writeFile, writeFileSync, writeFileBase64, writeFileBase64Sync,
103
- exists, existsSync, deleteFile, deleteFileSync, mkdir, mkdirSync, list, listSync,
99
+ appendFile, appendFileSync,
100
+ exists, existsSync, isDirectory, isDirectorySync,
101
+ deleteFile, deleteFileSync, mkdir, mkdirSync, list, listSync,
104
102
  };
package/src/gui.ts ADDED
@@ -0,0 +1,33 @@
1
+ import { post } from './task.js';
2
+ import { GUIHandle } from './instance-id.js';
3
+ import type { ItemStack } from './item.js';
4
+
5
+ export async function createGUI(size: number, title: string): Promise<GUIHandle> {
6
+ const h = new GUIHandle();
7
+ await post('gui.create', { id: h.toString(), size, title });
8
+ return h;
9
+ }
10
+
11
+ export function destroy(id: GUIHandle): Promise<void> {
12
+ return post('gui.destroy', { id: id.toString() });
13
+ }
14
+
15
+ export function open(id: GUIHandle, uuid: string): Promise<void> {
16
+ return post('gui.open', { id: id.toString(), uuid });
17
+ }
18
+
19
+ export function close(id: GUIHandle): Promise<void> {
20
+ return post('gui.close', { id: id.toString() });
21
+ }
22
+
23
+ export function setItem(id: GUIHandle, slot: number, item: ItemStack): Promise<void> {
24
+ return post('gui.setItem', { id: id.toString(), slot, item });
25
+ }
26
+
27
+ export function fill(id: GUIHandle, item: ItemStack): Promise<void> {
28
+ return post('gui.fill', { id: id.toString(), item });
29
+ }
30
+
31
+ export function clear(id: GUIHandle): Promise<void> {
32
+ return post('gui.clear', { id: id.toString() });
33
+ }
package/src/index.ts CHANGED
@@ -20,8 +20,9 @@ export type {
20
20
  EntityRegainHealthEvent, EntityTargetEvent,
21
21
  ProjectileLaunchEvent, ProjectileHitEvent,
22
22
  BlockBreakEvent, BlockPlaceEvent, BlockFadeEvent, BlockGrowEvent, BlockSpreadEvent, BlockExplodeEvent,
23
- InventoryOpenEvent, InventoryCloseEvent,
23
+ InventoryOpenEvent, InventoryCloseEvent, InventoryClickEvent,
24
24
  ServerPingEvent, ServerCommandEvent,
25
+ PlayerResourcePackStatusEvent,
25
26
  } from './event.js';
26
27
  export { onInit, onLoad, onUnload } from './lifecycle.js';
27
28
  export {
@@ -33,7 +34,9 @@ export {
33
34
  fs,
34
35
  readFile, readFileSync, readFileBase64, readFileBase64Sync,
35
36
  writeFile, writeFileSync, writeFileBase64, writeFileBase64Sync,
36
- exists, existsSync, deleteFile, deleteFileSync, mkdir, mkdirSync, list, listSync,
37
+ appendFile, appendFileSync,
38
+ exists, existsSync, isDirectory, isDirectorySync,
39
+ deleteFile, deleteFileSync, mkdir, mkdirSync, list, listSync,
37
40
  } from './fs.js';
38
41
  export { assets, read as assetsRead, readSync as assetsReadSync,
39
42
  readBase64 as assetsReadBase64, readBase64Sync as assetsReadBase64Sync,
@@ -41,3 +44,37 @@ export { assets, read as assetsRead, readSync as assetsReadSync,
41
44
  export { path } from './path.js';
42
45
  export { listen, respond, close, request } from './http.js';
43
46
  export { logError } from './log-error.js';
47
+ export { InstanceId, GUIHandle, BossBarHandle, InventoryHandle } from './instance-id.js';
48
+ export type { ItemStack } from './item.js';
49
+ export type { PotionEffect } from './potion.js';
50
+ export { addPotionEffect, removePotionEffect, clearPotionEffects, getActivePotionEffects } from './potion.js';
51
+ export { playSound, stopSound, stopAllSounds } from './sound.js';
52
+ export type { ParticleOptions } from './particle.js';
53
+ export { spawnParticle } from './particle.js';
54
+ export { get as pdcGet, set as pdcSet, has as pdcHas, remove as pdcRemove, keys as pdcKeys,
55
+ getBlock as pdcGetBlock, setBlock as pdcSetBlock, hasBlock as pdcHasBlock, removeBlock as pdcRemoveBlock } from './pdc.js';
56
+ export { createBossBar, destroy as destroyBossBar,
57
+ setTitle as setBossBarTitle, setProgress as setBossBarProgress,
58
+ setColor as setBossBarColor, setStyle as setBossBarStyle,
59
+ setVisible as setBossBarVisible, addPlayer as addBossBarPlayer,
60
+ removePlayer as removeBossBarPlayer, removeAll as removeAllBossBarPlayers,
61
+ addFlag as addBossBarFlag, removeFlag as removeBossBarFlag } from './bossbar.js';
62
+ export type { BossBarOptions } from './bossbar.js';
63
+ export { createGUI, destroy as destroyGUI, open as openGUI,
64
+ close as closeGUI, setItem as setGUIItem, fill as fillGUI, clear as clearGUI } from './gui.js';
65
+ export type { AdvancementProgress } from './advancement.js';
66
+ export { grant as grantAdvancement, revoke as revokeAdvancement,
67
+ getProgress as getAdvancementProgress, awardCriteria, revokeCriteria } from './advancement.js';
68
+ export { add as addRecipe, remove as removeRecipe, getForItem as getRecipesForItem } from './recipe.js';
69
+ export type {
70
+ ObjectiveInfo, TeamInfo,
71
+ } from './scoreboard.js';
72
+ export { createObjective, deleteObjective, getObjectives,
73
+ setObjectiveDisplay, getScore, setScore, resetScore,
74
+ createTeam, deleteTeam, getTeam, getTeams,
75
+ setTeamDisplayName, setTeamPrefix, setTeamSuffix, setTeamColor,
76
+ setTeamFriendlyFire, setTeamSeeInvisible, setTeamOption,
77
+ teamAddEntry, teamRemoveEntry, teamGetEntries,
78
+ setPlayerBoard } from './scoreboard.js';
79
+ export { getMaterials, getBlocks, getItems } from './material.js';
80
+ export type { MaterialInfo } from './material.js';
@@ -0,0 +1,30 @@
1
+ let _seq = 0;
2
+ const _gcQueue: string[] = [];
3
+ const _gcReg = typeof FinalizationRegistry !== 'undefined'
4
+ ? new FinalizationRegistry<string>((raw: string) => { _gcQueue.push(raw); })
5
+ : null;
6
+ (globalThis as any).__yeowGcQueue = _gcQueue;
7
+
8
+ export class InstanceId {
9
+ readonly _raw: string;
10
+ readonly _managed: boolean;
11
+
12
+ constructor(prefix: string) {
13
+ this._raw = prefix + '_' + (++_seq);
14
+ this._managed = true;
15
+ _gcReg?.register(this, this._raw);
16
+ }
17
+
18
+ static adopt(raw: string): InstanceId {
19
+ const id = Object.create(InstanceId.prototype) as InstanceId;
20
+ (id as any)._raw = raw;
21
+ (id as any)._managed = false;
22
+ return id;
23
+ }
24
+
25
+ toString(): string { return this._raw; }
26
+ }
27
+
28
+ export class GUIHandle extends InstanceId { constructor() { super('gui'); } }
29
+ export class BossBarHandle extends InstanceId { constructor() { super('boss'); } }
30
+ export class InventoryHandle extends InstanceId { constructor() { super('inv'); } }
package/src/item.ts ADDED
@@ -0,0 +1,13 @@
1
+ export interface ItemStack {
2
+ type: string;
3
+ amount: number;
4
+ meta?: {
5
+ displayName?: string;
6
+ lore?: string[];
7
+ customModelData?: number;
8
+ unbreakable?: boolean;
9
+ hideTooltip?: boolean;
10
+ enchantments?: Record<string, number>;
11
+ itemFlags?: string[];
12
+ };
13
+ }
@@ -0,0 +1,19 @@
1
+ import { post } from './task.js';
2
+
3
+ export interface MaterialInfo {
4
+ key: string;
5
+ isBlock: boolean;
6
+ isItem: boolean;
7
+ }
8
+
9
+ export function getMaterials(): Promise<MaterialInfo[]> {
10
+ return post<MaterialInfo[]>('server.getMaterials', {});
11
+ }
12
+
13
+ export function getBlocks(): Promise<string[]> {
14
+ return post<string[]>('server.getBlocks', {});
15
+ }
16
+
17
+ export function getItems(): Promise<string[]> {
18
+ return post<string[]>('server.getItems', {});
19
+ }
@@ -0,0 +1,38 @@
1
+ import { post } from './task.js';
2
+ import type { ItemStack } from './item.js';
3
+
4
+ export interface ParticleOptions {
5
+ particle: string;
6
+ x: number;
7
+ y: number;
8
+ z: number;
9
+ world: string;
10
+ count?: number;
11
+ offsetX?: number;
12
+ offsetY?: number;
13
+ offsetZ?: number;
14
+ speed?: number;
15
+ force?: boolean;
16
+ color?: { r: number; g: number; b: number; size?: number };
17
+ blockType?: string;
18
+ item?: ItemStack;
19
+ }
20
+
21
+ export function spawnParticle(options: ParticleOptions): Promise<void> {
22
+ return post('world.spawnParticle', {
23
+ world: options.world,
24
+ particle: options.particle,
25
+ x: options.x,
26
+ y: options.y,
27
+ z: options.z,
28
+ count: options.count,
29
+ offsetX: options.offsetX,
30
+ offsetY: options.offsetY,
31
+ offsetZ: options.offsetZ,
32
+ speed: options.speed,
33
+ force: options.force,
34
+ color: options.color,
35
+ blockType: options.blockType,
36
+ item: options.item,
37
+ });
38
+ }
package/src/pdc.ts ADDED
@@ -0,0 +1,37 @@
1
+ import { post } from './task.js';
2
+
3
+ export function get(uuid: string, key: string): Promise<string | null> {
4
+ return post<string | null>('pdc.get', { uuid, key });
5
+ }
6
+
7
+ export function set(uuid: string, key: string, value: string): Promise<boolean> {
8
+ return post<boolean>('pdc.set', { uuid, key, value });
9
+ }
10
+
11
+ export function has(uuid: string, key: string): Promise<boolean> {
12
+ return post<boolean>('pdc.has', { uuid, key });
13
+ }
14
+
15
+ export function remove(uuid: string, key: string): Promise<boolean> {
16
+ return post<boolean>('pdc.remove', { uuid, key });
17
+ }
18
+
19
+ export function keys(uuid: string): Promise<string[]> {
20
+ return post<string[]>('pdc.keys', { uuid });
21
+ }
22
+
23
+ export function getBlock(world: string, x: number, y: number, z: number, key: string): Promise<string | null> {
24
+ return post<string | null>('pdc.get', { world, x, y, z, key });
25
+ }
26
+
27
+ export function setBlock(world: string, x: number, y: number, z: number, key: string, value: string): Promise<boolean> {
28
+ return post<boolean>('pdc.set', { world, x, y, z, key, value });
29
+ }
30
+
31
+ export function hasBlock(world: string, x: number, y: number, z: number, key: string): Promise<boolean> {
32
+ return post<boolean>('pdc.has', { world, x, y, z, key });
33
+ }
34
+
35
+ export function removeBlock(world: string, x: number, y: number, z: number, key: string): Promise<boolean> {
36
+ return post<boolean>('pdc.remove', { world, x, y, z, key });
37
+ }
package/src/player.ts CHANGED
@@ -24,18 +24,79 @@ export class Player {
24
24
  constructor(public readonly uuid: string, private _name?: string) {}
25
25
 
26
26
  get name(): string { return this._name ?? ''; }
27
+
27
28
  get ping(): number { return call<number>('player.getPing', { uuid: this.uuid }); }
29
+ getPing(): Promise<number> { return post<number>('player.getPing', { uuid: this.uuid }); }
30
+
28
31
  get gamemode(): string { return call<string>('player.getGamemode', { uuid: this.uuid }); }
29
32
  set gamemode(v: string) { call('player.setGamemode', { uuid: this.uuid, value: v }); }
33
+ getGamemode(): Promise<string> { return post<string>('player.getGamemode', { uuid: this.uuid }); }
34
+ setGamemode(v: string): Promise<void> { return post('player.setGamemode', { uuid: this.uuid, value: v }); }
35
+
36
+ get health(): number { return call<number>('player.getHealth', { uuid: this.uuid }); }
37
+ set health(v: number) { call('player.setHealth', { uuid: this.uuid, value: v }); }
38
+ getHealth(): Promise<number> { return post<number>('player.getHealth', { uuid: this.uuid }); }
39
+ setHealth(v: number): Promise<void> { return post('player.setHealth', { uuid: this.uuid, value: v }); }
40
+
41
+ get food(): number { return call<number>('player.getFood', { uuid: this.uuid }); }
42
+ set food(v: number) { call('player.setFood', { uuid: this.uuid, value: v }); }
43
+ getFood(): Promise<number> { return post<number>('player.getFood', { uuid: this.uuid }); }
44
+ setFood(v: number): Promise<void> { return post('player.setFood', { uuid: this.uuid, value: v }); }
45
+
46
+ get exp(): number { return call<number>('player.getExp', { uuid: this.uuid }); }
47
+ set exp(v: number) { call('player.setExp', { uuid: this.uuid, value: v }); }
48
+ getExp(): Promise<number> { return post<number>('player.getExp', { uuid: this.uuid }); }
49
+ setExp(v: number): Promise<void> { return post('player.setExp', { uuid: this.uuid, value: v }); }
50
+
51
+ get level(): number { return call<number>('player.getLevel', { uuid: this.uuid }); }
52
+ set level(v: number) { call('player.setLevel', { uuid: this.uuid, value: v }); }
53
+ getLevel(): Promise<number> { return post<number>('player.getLevel', { uuid: this.uuid }); }
54
+ setLevel(v: number): Promise<void> { return post('player.setLevel', { uuid: this.uuid, value: v }); }
55
+
56
+ get isOp(): boolean { return call<boolean>('player.isOp', { uuid: this.uuid }); }
57
+ isOpAsync(): Promise<boolean> { return post<boolean>('player.isOp', { uuid: this.uuid }); }
58
+
59
+ get isFlying(): boolean { return call<boolean>('player.isFlying', { uuid: this.uuid }); }
60
+ set isFlying(v: boolean) { call('player.setFlying', { uuid: this.uuid, value: v }); }
61
+ isFlyingAsync(): Promise<boolean> { return post<boolean>('player.isFlying', { uuid: this.uuid }); }
62
+ setFlying(v: boolean): Promise<void> { return post('player.setFlying', { uuid: this.uuid, value: v }); }
63
+
64
+ get allowFlight(): boolean { return call<boolean>('player.getAllowFlight', { uuid: this.uuid }); }
65
+ set allowFlight(v: boolean) { call('player.setAllowFlight', { uuid: this.uuid, value: v }); }
66
+ getAllowFlight(): Promise<boolean> { return post<boolean>('player.getAllowFlight', { uuid: this.uuid }); }
67
+ setAllowFlight(v: boolean): Promise<void> { return post('player.setAllowFlight', { uuid: this.uuid, value: v }); }
68
+
69
+ get walkSpeed(): number { return call<number>('player.getWalkSpeed', { uuid: this.uuid }); }
70
+ set walkSpeed(v: number) { call('player.setWalkSpeed', { uuid: this.uuid, value: v }); }
71
+ getWalkSpeed(): Promise<number> { return post<number>('player.getWalkSpeed', { uuid: this.uuid }); }
72
+ setWalkSpeed(v: number): Promise<void> { return post('player.setWalkSpeed', { uuid: this.uuid, value: v }); }
73
+
74
+ get flySpeed(): number { return call<number>('player.getFlySpeed', { uuid: this.uuid }); }
75
+ set flySpeed(v: number) { call('player.setFlySpeed', { uuid: this.uuid, value: v }); }
76
+ getFlySpeed(): Promise<number> { return post<number>('player.getFlySpeed', { uuid: this.uuid }); }
77
+ setFlySpeed(v: number): Promise<void> { return post('player.setFlySpeed', { uuid: this.uuid, value: v }); }
78
+
30
79
  get world(): string { return call<string>('player.getWorld', { uuid: this.uuid }); }
80
+ getWorld(): Promise<string> { return post<string>('player.getWorld', { uuid: this.uuid }); }
81
+
31
82
  get location(): Location | null {
32
83
  const r = call<LocationData>('player.getLocation', { uuid: this.uuid });
33
84
  return r ? Location.from(r) : null;
34
85
  }
86
+ getLocation(): Promise<Location | null> {
87
+ return post<LocationData>('player.getLocation', { uuid: this.uuid }).then((r) => (r ? Location.from(r) : null));
88
+ }
89
+
35
90
  get displayName(): string { return call<string>('player.getDisplayName', { uuid: this.uuid }); }
36
91
  set displayName(v: string | null) { call('player.setDisplayName', { uuid: this.uuid, value: v }); }
92
+ getDisplayName(): Promise<string> { return post<string>('player.getDisplayName', { uuid: this.uuid }); }
93
+ setDisplayName(v: string | null): Promise<void> { return post('player.setDisplayName', { uuid: this.uuid, value: v }); }
94
+
37
95
  get saturation(): number { return call<number>('player.getSaturation', { uuid: this.uuid }); }
96
+ getSaturation(): Promise<number> { return post<number>('player.getSaturation', { uuid: this.uuid }); }
97
+
38
98
  get totalExperience(): number { return call<number>('player.getTotalExperience', { uuid: this.uuid }); }
99
+ getTotalExperience(): Promise<number> { return post<number>('player.getTotalExperience', { uuid: this.uuid }); }
39
100
 
40
101
  sendMessage(msg: string): Promise<void> { return post('player.sendMessage', { uuid: this.uuid, message: msg }); }
41
102
  sendMessageSync(msg: string): void { call('player.sendMessage', { uuid: this.uuid, message: msg }); }
@@ -63,4 +124,9 @@ export class Player {
63
124
  }
64
125
  teleport(loc: Location): Promise<void> { return post('player.teleport', { uuid: this.uuid, ...loc.toObject() }); }
65
126
  teleportSync(loc: Location): void { call('player.teleport', { uuid: this.uuid, ...loc.toObject() }); }
127
+ sendActionBar(message: string): Promise<void> { return post('player.sendActionBar', { uuid: this.uuid, message }); }
128
+ sendActionBarSync(message: string): void { call('player.sendActionBar', { uuid: this.uuid, message }); }
129
+ sendResourcePack(url: string, hash?: string, prompt?: string, force?: boolean): Promise<void> {
130
+ return post('player.sendResourcePack', { uuid: this.uuid, url, hash, prompt, force });
131
+ }
66
132
  }
package/src/potion.ts ADDED
@@ -0,0 +1,23 @@
1
+ import { post } from './task.js';
2
+
3
+ export interface PotionEffect {
4
+ type: string;
5
+ duration: number;
6
+ amplifier: number;
7
+ ambient?: boolean;
8
+ particles?: boolean;
9
+ icon?: boolean;
10
+ }
11
+
12
+ export function addPotionEffect(uuid: string, effect: PotionEffect): Promise<void> {
13
+ return post('entity.addPotionEffect', { uuid, ...effect });
14
+ }
15
+ export function removePotionEffect(uuid: string, type: string): Promise<void> {
16
+ return post('entity.removePotionEffect', { uuid, type });
17
+ }
18
+ export function clearPotionEffects(uuid: string): Promise<void> {
19
+ return post('entity.clearPotionEffects', { uuid });
20
+ }
21
+ export function getActivePotionEffects(uuid: string): Promise<PotionEffect[]> {
22
+ return post<PotionEffect[]>('entity.getActivePotionEffects', { uuid });
23
+ }
package/src/recipe.ts ADDED
@@ -0,0 +1,66 @@
1
+ import { post } from './task.js';
2
+ import type { ItemStack } from './item.js';
3
+
4
+ type RecipeDefinition = ShapedRecipe | ShapelessRecipe | FurnaceRecipe | BlastRecipe | SmokerRecipe | CampfireRecipe;
5
+
6
+ interface ShapedRecipe {
7
+ type: 'shaped';
8
+ key: string;
9
+ result: ItemStack;
10
+ shape: string[];
11
+ ingredients: Record<string, string>;
12
+ group?: string;
13
+ }
14
+
15
+ interface ShapelessRecipe {
16
+ type: 'shapeless';
17
+ key: string;
18
+ result: ItemStack;
19
+ ingredients: (string | ItemStack)[];
20
+ group?: string;
21
+ }
22
+
23
+ interface FurnaceRecipe {
24
+ type: 'furnace';
25
+ key: string;
26
+ input: string;
27
+ result: ItemStack;
28
+ experience?: number;
29
+ cookingTime?: number;
30
+ }
31
+ interface BlastRecipe {
32
+ type: 'blast';
33
+ key: string;
34
+ input: string;
35
+ result: ItemStack;
36
+ experience?: number;
37
+ cookingTime?: number;
38
+ }
39
+ interface SmokerRecipe {
40
+ type: 'smoker';
41
+ key: string;
42
+ input: string;
43
+ result: ItemStack;
44
+ experience?: number;
45
+ cookingTime?: number;
46
+ }
47
+ interface CampfireRecipe {
48
+ type: 'campfire';
49
+ key: string;
50
+ input: string;
51
+ result: ItemStack;
52
+ experience?: number;
53
+ cookingTime?: number;
54
+ }
55
+
56
+ export function add(recipe: RecipeDefinition): Promise<boolean> {
57
+ return post<boolean>('recipe.add', recipe as unknown as Record<string, unknown>);
58
+ }
59
+
60
+ export function remove(key: string): Promise<void> {
61
+ return post('recipe.remove', { key });
62
+ }
63
+
64
+ export function getForItem(item: ItemStack): Promise<string[]> {
65
+ return post<string[]>('recipe.getForItem', { item });
66
+ }
@@ -0,0 +1,115 @@
1
+ import { post } from './task.js';
2
+
3
+ export interface ObjectiveInfo {
4
+ name: string;
5
+ criteria: string;
6
+ displaySlot: string | null;
7
+ }
8
+
9
+ export interface TeamInfo {
10
+ name: string;
11
+ displayName: string;
12
+ prefix: string;
13
+ suffix: string;
14
+ color: string;
15
+ allowFriendlyFire: boolean;
16
+ canSeeFriendlyInvisibles: boolean;
17
+ entries: string[];
18
+ options: {
19
+ nameTagVisibility: string;
20
+ deathMessageVisibility: string;
21
+ collisionRule: string;
22
+ };
23
+ }
24
+
25
+ // ── Objectives ──
26
+
27
+ export function createObjective(name: string, criteria: string, displayName: string): Promise<ObjectiveInfo> {
28
+ return post<ObjectiveInfo>('scoreboard.createObjective', { name, criteria, displayName });
29
+ }
30
+
31
+ export function deleteObjective(name: string): Promise<void> {
32
+ return post('scoreboard.deleteObjective', { name });
33
+ }
34
+
35
+ export function getObjectives(): Promise<ObjectiveInfo[]> {
36
+ return post<ObjectiveInfo[]>('scoreboard.getObjectives', {});
37
+ }
38
+
39
+ export function setObjectiveDisplay(name: string, slot: string | null): Promise<boolean> {
40
+ return post<boolean>('scoreboard.setObjectiveDisplay', { name, slot });
41
+ }
42
+
43
+ export function getScore(objective: string, entry: string): Promise<number | null> {
44
+ return post<number | null>('scoreboard.getScore', { objective, entry });
45
+ }
46
+
47
+ export function setScore(objective: string, entry: string, value: number): Promise<void> {
48
+ return post('scoreboard.setScore', { objective, entry, value });
49
+ }
50
+
51
+ export function resetScore(objective: string, entry: string): Promise<void> {
52
+ return post('scoreboard.resetScore', { objective, entry });
53
+ }
54
+
55
+ // ── Teams ──
56
+
57
+ export function createTeam(name: string): Promise<void> {
58
+ return post('scoreboard.createTeam', { name });
59
+ }
60
+
61
+ export function deleteTeam(name: string): Promise<void> {
62
+ return post('scoreboard.deleteTeam', { name });
63
+ }
64
+
65
+ export function getTeam(name: string): Promise<TeamInfo | null> {
66
+ return post<TeamInfo | null>('scoreboard.getTeam', { name });
67
+ }
68
+
69
+ export function getTeams(): Promise<TeamInfo[]> {
70
+ return post<TeamInfo[]>('scoreboard.getTeams', {});
71
+ }
72
+
73
+ export function setTeamDisplayName(name: string, displayName: string): Promise<void> {
74
+ return post('scoreboard.setTeamDisplayName', { name, displayName });
75
+ }
76
+
77
+ export function setTeamPrefix(name: string, prefix: string): Promise<void> {
78
+ return post('scoreboard.setTeamPrefix', { name, prefix });
79
+ }
80
+
81
+ export function setTeamSuffix(name: string, suffix: string): Promise<void> {
82
+ return post('scoreboard.setTeamSuffix', { name, suffix });
83
+ }
84
+
85
+ export function setTeamColor(name: string, color: string): Promise<void> {
86
+ return post('scoreboard.setTeamColor', { name, color });
87
+ }
88
+
89
+ export function setTeamFriendlyFire(name: string, allow: boolean): Promise<void> {
90
+ return post('scoreboard.setTeamFriendlyFire', { name, allow });
91
+ }
92
+
93
+ export function setTeamSeeInvisible(name: string, canSee: boolean): Promise<void> {
94
+ return post('scoreboard.setTeamSeeInvisible', { name, canSee });
95
+ }
96
+
97
+ export function setTeamOption(name: string, option: string, value: string): Promise<void> {
98
+ return post('scoreboard.setTeamOption', { name, option, value });
99
+ }
100
+
101
+ export function teamAddEntry(name: string, entry: string): Promise<void> {
102
+ return post('scoreboard.teamAddEntry', { name, entry });
103
+ }
104
+
105
+ export function teamRemoveEntry(name: string, entry: string): Promise<void> {
106
+ return post('scoreboard.teamRemoveEntry', { name, entry });
107
+ }
108
+
109
+ export function teamGetEntries(name: string): Promise<string[]> {
110
+ return post<string[]>('scoreboard.teamGetEntries', { name });
111
+ }
112
+
113
+ export function setPlayerBoard(uuid: string): Promise<void> {
114
+ return post('scoreboard.setPlayerBoard', { uuid });
115
+ }
package/src/sound.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { post } from './task.js';
2
+
3
+ export function playSound(world: string, sound: string, x: number, y: number, z: number, volume?: number, pitch?: number): Promise<void> {
4
+ return post('world.playSound', { world, sound, x, y, z, volume, pitch });
5
+ }
6
+
7
+ export function stopSound(uuid: string, sound: string): Promise<void> {
8
+ return post('player.stopSound', { uuid, sound });
9
+ }
10
+
11
+ export function stopAllSounds(uuid: string): Promise<void> {
12
+ return post('player.stopAllSounds', { uuid });
13
+ }
package/src/world.ts CHANGED
@@ -117,4 +117,16 @@ export class World {
117
117
  createExplosionSync(x: number, y: number, z: number, power?: number, fire?: boolean, breaks?: boolean): void {
118
118
  call('world.createExplosion', { world: this.name, x, y, z, power, setFire: fire, breakBlocks: breaks });
119
119
  }
120
+ spawnEntity(type: string, x: number, y: number, z: number): Promise<string | null> {
121
+ return post<string | null>('world.spawnEntity', { world: this.name, type, x, y, z });
122
+ }
123
+ spawnEntitySync(type: string, x: number, y: number, z: number): string | null {
124
+ return call<string | null>('world.spawnEntity', { world: this.name, type, x, y, z });
125
+ }
126
+ playSound(sound: string, x: number, y: number, z: number, volume?: number, pitch?: number): Promise<void> {
127
+ return post('world.playSound', { world: this.name, sound, x, y, z, volume, pitch });
128
+ }
129
+ playSoundSync(sound: string, x: number, y: number, z: number, volume?: number, pitch?: number): void {
130
+ call('world.playSound', { world: this.name, sound, x, y, z, volume, pitch });
131
+ }
120
132
  }