yeow-api 0.2.11 → 0.2.13
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 +1 -1
- package/src/entity.ts +5 -5
- package/src/event.ts +9 -30
- package/src/index.ts +1 -1
- package/src/inventory.ts +5 -5
- package/src/player.ts +27 -3
- package/src/server.ts +9 -2
- package/src/world.ts +11 -5
package/package.json
CHANGED
package/src/entity.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { call } from './task.js';
|
|
1
|
+
import { call, post } from './task.js';
|
|
2
2
|
import { Location } from './location.js';
|
|
3
3
|
|
|
4
4
|
export class Entity {
|
|
@@ -6,9 +6,9 @@ export class Entity {
|
|
|
6
6
|
|
|
7
7
|
get type(): string { return call('entity.getType', { uuid: this.uuid }) as string; }
|
|
8
8
|
get name(): string { return call('entity.getName', { uuid: this.uuid }) as string; }
|
|
9
|
-
get customName(): string | null {
|
|
9
|
+
get customName(): string | null { const r = call('entity.getCustomName', { uuid: this.uuid }); return r || null; }
|
|
10
10
|
set customName(v: string | null) { call('entity.setCustomName', { uuid: this.uuid, value: v }); }
|
|
11
|
-
setCustomNameVisible(v: boolean): Promise<void> { return
|
|
11
|
+
setCustomNameVisible(v: boolean): Promise<void> { return post('entity.setCustomNameVisible', { uuid: this.uuid, value: v }) as Promise<void>; }
|
|
12
12
|
get world(): string | null { return call('entity.getWorld', { uuid: this.uuid }) as string | null; }
|
|
13
13
|
get location(): Location | null { const r = call('entity.getLocation', { uuid: this.uuid }); return r ? Location.from(r as any) : null; }
|
|
14
14
|
get isGlowing(): boolean { return call('entity.isGlowing', { uuid: this.uuid }) as boolean; }
|
|
@@ -22,9 +22,9 @@ export class Entity {
|
|
|
22
22
|
get passengers(): string[] { return call('entity.getPassengers', { uuid: this.uuid }) as string[]; }
|
|
23
23
|
get vehicle(): string | null { return call('entity.getVehicle', { uuid: this.uuid }) as string | null; }
|
|
24
24
|
|
|
25
|
-
remove(): Promise<void> { return
|
|
25
|
+
remove(): Promise<void> { return post('entity.remove', { uuid: this.uuid }) as Promise<void>; }
|
|
26
26
|
removeSync(): void { call('entity.remove', { uuid: this.uuid }); }
|
|
27
|
-
teleport(loc: Location): Promise<void> { return
|
|
27
|
+
teleport(loc: Location): Promise<void> { return post('entity.teleport', { uuid: this.uuid, ...loc.toObject() }) as Promise<void>; }
|
|
28
28
|
teleportSync(loc: Location): void { call('entity.teleport', { uuid: this.uuid, ...loc.toObject() }); }
|
|
29
29
|
}
|
|
30
30
|
|
package/src/event.ts
CHANGED
|
@@ -206,14 +206,7 @@ function adaptEvent(type: string, data: any): any {
|
|
|
206
206
|
case 'playerDropItem': case 'playerPickupItem': case 'playerBucketFill': case 'playerBucketEmpty':
|
|
207
207
|
case 'playerExpChange': case 'playerLevelChange': case 'playerGameModeChange': case 'foodLevelChange':
|
|
208
208
|
case 'blockBreak': case 'blockPlace': case 'inventoryOpen': case 'inventoryClose':
|
|
209
|
-
if (data.player)
|
|
210
|
-
try {
|
|
211
|
-
wrap.player = Player.get(data.player);
|
|
212
|
-
console.log('[ev] Player.get(' + data.player + ') = ' + (wrap.player ? 'Player' : 'null'));
|
|
213
|
-
} catch (e: any) {
|
|
214
|
-
console.log('[ev] Player.get err: ' + (e?.message || e) + ' stack=' + (e?.stack || ''));
|
|
215
|
-
}
|
|
216
|
-
}
|
|
209
|
+
if (data.player) wrap.player = Player.get(data.player);
|
|
217
210
|
break;
|
|
218
211
|
}
|
|
219
212
|
if (data.from) wrap.from = _loc(data.from);
|
|
@@ -225,7 +218,7 @@ function adaptEvent(type: string, data: any): any {
|
|
|
225
218
|
// ── EventOn/EventOff ───────────────────────────────────────────────
|
|
226
219
|
|
|
227
220
|
export function eventOn<K extends keyof EventMap>(eventType: K, handler: (e: EventMap[K]) => void): () => void {
|
|
228
|
-
const wrapper = (data: any) => handler(
|
|
221
|
+
const wrapper = (data: any) => handler(data as EventMap[K]);
|
|
229
222
|
(wrapper as any)._raw = handler;
|
|
230
223
|
|
|
231
224
|
if (!(globalThis as any).__yeowEventHandlers) (globalThis as any).__yeowEventHandlers = {};
|
|
@@ -260,38 +253,24 @@ export function eventOff(eventType: string, handler: Function): void {
|
|
|
260
253
|
const handlers = (globalThis as any).__yeowEventHandlers?.[eventType];
|
|
261
254
|
if (!handlers?.length) return {};
|
|
262
255
|
|
|
263
|
-
console.log('[ev] type=' + eventType + ' data=' + JSON.stringify(data).slice(0,200));
|
|
264
|
-
|
|
265
256
|
const cancellable = data?._cancellable;
|
|
266
257
|
const mods: Record<string, any> = {};
|
|
267
258
|
|
|
268
|
-
|
|
269
|
-
try {
|
|
270
|
-
wrapped = adaptEvent(eventType, data);
|
|
271
|
-
} catch (e: any) {
|
|
272
|
-
console.log('[ev] adaptEvent err: ' + (e?.message || e) + ' stack=' + (e?.stack || ''));
|
|
273
|
-
return mods;
|
|
274
|
-
}
|
|
259
|
+
const wrapped = adaptEvent(eventType, data);
|
|
275
260
|
|
|
276
261
|
const localMods: Record<string, any> = {};
|
|
277
262
|
if (cancellable) {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
});
|
|
284
|
-
} catch (e: any) {
|
|
285
|
-
console.log('[ev] defineProperty err: ' + (e?.message || e));
|
|
286
|
-
}
|
|
263
|
+
Object.defineProperty(wrapped, 'cancelled', {
|
|
264
|
+
get: () => localMods.cancelled || false,
|
|
265
|
+
set: (v: boolean) => { localMods.cancelled = v; },
|
|
266
|
+
enumerable: true,
|
|
267
|
+
});
|
|
287
268
|
}
|
|
288
269
|
|
|
289
270
|
for (const handler of handlers) {
|
|
290
271
|
try {
|
|
291
272
|
handler(wrapped);
|
|
292
|
-
} catch (e: any) {
|
|
293
|
-
console.log('[ev] handler err: msg=' + (e?.message || '') + ' name=' + (e?.name || '') + ' stack=' + (e?.stack || '').slice(0,300));
|
|
294
|
-
}
|
|
273
|
+
} catch (e: any) { console.error('event:', e?.message || e); }
|
|
295
274
|
}
|
|
296
275
|
if (cancellable && localMods.cancelled) mods.cancelled = true;
|
|
297
276
|
return mods;
|
package/src/index.ts
CHANGED
|
@@ -15,7 +15,7 @@ export type {
|
|
|
15
15
|
ServerPingEvent,
|
|
16
16
|
} from './event.js';
|
|
17
17
|
export { onInit, onLoad } from './lifecycle.js';
|
|
18
|
-
export { broadcast, getMotd, getVersion } from './server.js';
|
|
18
|
+
export { broadcast, broadcastSync, dispatchCommand, dispatchCommandSync, setMotd, setMotdSync, setIcon, setIconSync, getMotd, getVersion } from './server.js';
|
|
19
19
|
export { fs, readFile, readFileSync, readFileBase64, readFileBase64Sync, writeFile, writeFileSync, writeFileBase64, writeFileBase64Sync, existsSync, deleteFile, mkdir, list } from './fs.js';
|
|
20
20
|
export { assets, read as assetsRead, readSync as assetsReadSync, readBase64 as assetsReadBase64, readBase64Sync as assetsReadBase64Sync, extract as assetsExtract, extractSync as assetsExtractSync } from './assets.js';
|
|
21
21
|
export { listen, respond, close, request, requestSync } from './http.js';
|
package/src/inventory.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { call } from './task.js';
|
|
1
|
+
import { call, post } from './task.js';
|
|
2
2
|
|
|
3
3
|
export class Inventory {
|
|
4
4
|
constructor(private readonly uuid: string) {}
|
|
@@ -7,25 +7,25 @@ export class Inventory {
|
|
|
7
7
|
return call('inventory.getItem', { uuid: this.uuid, slot }) as any;
|
|
8
8
|
}
|
|
9
9
|
setItem(slot: number, itemType: string, amount?: number): Promise<void> {
|
|
10
|
-
return
|
|
10
|
+
return post('inventory.setItem', { uuid: this.uuid, slot, itemType, amount }) as Promise<void>;
|
|
11
11
|
}
|
|
12
12
|
setItemSync(slot: number, itemType: string, amount?: number): void {
|
|
13
13
|
call('inventory.setItem', { uuid: this.uuid, slot, itemType, amount });
|
|
14
14
|
}
|
|
15
15
|
addItem(itemType: string, amount?: number): Promise<void> {
|
|
16
|
-
return
|
|
16
|
+
return post('inventory.addItem', { uuid: this.uuid, itemType, amount }) as Promise<void>;
|
|
17
17
|
}
|
|
18
18
|
addItemSync(itemType: string, amount?: number): void {
|
|
19
19
|
call('inventory.addItem', { uuid: this.uuid, itemType, amount });
|
|
20
20
|
}
|
|
21
21
|
removeItem(itemType: string, amount?: number): Promise<void> {
|
|
22
|
-
return
|
|
22
|
+
return post('inventory.removeItem', { uuid: this.uuid, itemType, amount }) as Promise<void>;
|
|
23
23
|
}
|
|
24
24
|
removeItemSync(itemType: string, amount?: number): void {
|
|
25
25
|
call('inventory.removeItem', { uuid: this.uuid, itemType, amount });
|
|
26
26
|
}
|
|
27
27
|
clear(slot?: number): Promise<void> {
|
|
28
|
-
return
|
|
28
|
+
return post('inventory.clear', { uuid: this.uuid, slot }) as Promise<void>;
|
|
29
29
|
}
|
|
30
30
|
clearSync(slot?: number): void {
|
|
31
31
|
call('inventory.clear', { uuid: this.uuid, slot });
|
package/src/player.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { call } from './task.js';
|
|
1
|
+
import { call, post } from './task.js';
|
|
2
2
|
import { Location } from './location.js';
|
|
3
3
|
|
|
4
4
|
export class Player {
|
|
@@ -16,7 +16,31 @@ export class Player {
|
|
|
16
16
|
get ping(): number { return call('player.getPing', { uuid: this.uuid }) as number; }
|
|
17
17
|
get gamemode(): string { return call('player.getGamemode', { uuid: this.uuid }) as string; }
|
|
18
18
|
set gamemode(v: string) { call('player.setGamemode', { uuid: this.uuid, value: v }); }
|
|
19
|
+
get world(): string { return call('player.getWorld', { uuid: this.uuid }) as string; }
|
|
20
|
+
get location(): Location | null { const r = call('player.getLocation', { uuid: this.uuid }); return r ? Location.from(r as any) : null; }
|
|
21
|
+
get displayName(): string { return call('player.getDisplayName', { uuid: this.uuid }) as string; }
|
|
22
|
+
set displayName(v: string | null) { call('player.setDisplayName', { uuid: this.uuid, value: v }); }
|
|
19
23
|
|
|
20
|
-
|
|
21
|
-
|
|
24
|
+
// Methods (async by default)
|
|
25
|
+
sendMessage(msg: string): Promise<void> { return post('player.sendMessage', { uuid: this.uuid, message: msg }) as Promise<void>; }
|
|
26
|
+
sendMessageSync(msg: string): void { call('player.sendMessage', { uuid: this.uuid, message: msg }); }
|
|
27
|
+
kick(reason?: string): Promise<void> { return post('player.kick', { uuid: this.uuid, reason }) as Promise<void>; }
|
|
28
|
+
kickSync(reason?: string): void { call('player.kick', { uuid: this.uuid, reason }); }
|
|
29
|
+
sendTitle(title?: string, subtitle?: string, fadeIn?: number, stay?: number, fadeOut?: number): Promise<void> {
|
|
30
|
+
return post('player.sendTitle', { uuid: this.uuid, title, subtitle, fadeIn, stay, fadeOut }) as Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
sendTitleSync(title?: string, subtitle?: string, fadeIn?: number, stay?: number, fadeOut?: number): void {
|
|
33
|
+
call('player.sendTitle', { uuid: this.uuid, title, subtitle, fadeIn, stay, fadeOut });
|
|
34
|
+
}
|
|
35
|
+
playSound(sound: string, volume?: number, pitch?: number): Promise<void> {
|
|
36
|
+
return post('player.playSound', { uuid: this.uuid, sound, volume, pitch }) as Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
playSoundSync(sound: string, volume?: number, pitch?: number): void {
|
|
39
|
+
call('player.playSound', { uuid: this.uuid, sound, volume, pitch });
|
|
40
|
+
}
|
|
41
|
+
giveExp(amount: number): Promise<void> { return post('player.giveExp', { uuid: this.uuid, amount }) as Promise<void>; }
|
|
42
|
+
giveExpSync(amount: number): void { call('player.giveExp', { uuid: this.uuid, amount }); }
|
|
43
|
+
hasPermission(node: string): boolean { return call('player.hasPermission', { uuid: this.uuid, permission: node }) as boolean; }
|
|
44
|
+
teleport(loc: Location): Promise<void> { return post('player.teleport', { uuid: this.uuid, ...loc.toObject() }) as Promise<void>; }
|
|
45
|
+
teleportSync(loc: Location): void { call('player.teleport', { uuid: this.uuid, ...loc.toObject() }); }
|
|
22
46
|
}
|
package/src/server.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import { call } from './task.js';
|
|
1
|
+
import { call, post } from './task.js';
|
|
2
2
|
|
|
3
|
-
export function broadcast(msg: string): void {
|
|
3
|
+
export function broadcast(msg: string): Promise<void> { return post('server.broadcast', { message: msg }) as Promise<void>; }
|
|
4
|
+
export function broadcastSync(msg: string): void { call('server.broadcast', { message: msg }); }
|
|
5
|
+
export function dispatchCommand(cmd: string): Promise<boolean> { return post('command.dispatch', { command: cmd }) as Promise<boolean>; }
|
|
6
|
+
export function dispatchCommandSync(cmd: string): boolean { return call('command.dispatch', { command: cmd }) as boolean; }
|
|
7
|
+
export function setMotd(motd: string): Promise<void> { return post('server.setMotd', { motd }) as Promise<void>; }
|
|
8
|
+
export function setMotdSync(motd: string): void { call('server.setMotd', { motd }); }
|
|
9
|
+
export function setIcon(base64: string): Promise<void> { return post('server.setIcon', { icon: base64 }) as Promise<void>; }
|
|
10
|
+
export function setIconSync(base64: string): void { call('server.setIcon', { icon: base64 }); }
|
|
4
11
|
export function getMotd(): string { return call('server.getMotd', {}) as string; }
|
|
5
12
|
export function getVersion(): string { return call('server.getVersion', {}) as string; }
|
package/src/world.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { call } from './task.js';
|
|
1
|
+
import { call, post } from './task.js';
|
|
2
2
|
import { Location } from './location.js';
|
|
3
3
|
|
|
4
4
|
export class World {
|
|
@@ -19,15 +19,21 @@ export class World {
|
|
|
19
19
|
set spawnLocation(v: Location) { call('world.setSpawnLocation', { world: this.name, ...v.toObject() }); }
|
|
20
20
|
|
|
21
21
|
getGameRule(rule: string): string | null { return call('world.getGameRule', { world: this.name, rule }) as string | null; }
|
|
22
|
+
setGameRule(rule: string, value: string): Promise<boolean> { return post('world.setGameRule', { world: this.name, rule, value }) as Promise<boolean>; }
|
|
22
23
|
setGameRuleSync(rule: string, value: string): boolean { return call('world.setGameRule', { world: this.name, rule, value }) as boolean; }
|
|
23
24
|
getBiome(x: number, y: number, z: number): string { return call('world.getBiome', { world: this.name, x, y, z }) as string; }
|
|
24
|
-
getBlock(x: number, y: number, z: number): any {
|
|
25
|
-
|
|
25
|
+
getBlock(x: number, y: number, z: number): any { return call('world.getBlock', { world: this.name, x, y, z }); }
|
|
26
|
+
setBlock(x: number, y: number, z: number, blockType: string): Promise<void> { return post('world.setBlock', { world: this.name, x, y, z, blockType }) as Promise<void>; }
|
|
27
|
+
setBlockSync(x: number, y: number, z: number, blockType: string) { call('world.setBlock', { world: this.name, x, y, z, blockType }); }
|
|
26
28
|
getEntities(): string[] { return call('world.getEntities', { world: this.name }) as string[]; }
|
|
27
29
|
getPlayers(): string[] { return call('world.getPlayers', { world: this.name }) as string[]; }
|
|
28
|
-
getNearbyEntities(x: number, y: number, z: number,
|
|
29
|
-
|
|
30
|
+
getNearbyEntities(x: number, y: number, z: number, radius: number): string[] { return call('world.getNearbyEntities', { world: this.name, x, y, z, radius }) as string[]; }
|
|
31
|
+
dropItem(x: number, y: number, z: number, itemType: string, amount?: number): Promise<void> { return post('world.dropItem', { world: this.name, x, y, z, itemType, amount }) as Promise<void>; }
|
|
32
|
+
dropItemSync(x: number, y: number, z: number, itemType: string, amount?: number) { call('world.dropItem', { world: this.name, x, y, z, itemType, amount }); }
|
|
33
|
+
strikeLightning(x: number, y: number, z: number): Promise<void> { return post('world.strikeLightning', { world: this.name, x, y, z }) as Promise<void>; }
|
|
30
34
|
strikeLightningSync(x: number, y: number, z: number) { call('world.strikeLightning', { world: this.name, x, y, z }); }
|
|
35
|
+
strikeLightningEffect(x: number, y: number, z: number): Promise<void> { return post('world.strikeLightningEffect', { world: this.name, x, y, z }) as Promise<void>; }
|
|
31
36
|
strikeLightningEffectSync(x: number, y: number, z: number) { call('world.strikeLightningEffect', { world: this.name, x, y, z }); }
|
|
37
|
+
createExplosion(x: number, y: number, z: number, power?: number, fire?: boolean, breaks?: boolean): Promise<void> { return post('world.createExplosion', { world: this.name, x, y, z, power, setFire: fire, breakBlocks: breaks }) as Promise<void>; }
|
|
32
38
|
createExplosionSync(x: number, y: number, z: number, power?: number, fire?: boolean, breaks?: boolean) { call('world.createExplosion', { world: this.name, x, y, z, power, setFire: fire, breakBlocks: breaks }); }
|
|
33
39
|
}
|