yeow-api 0.2.35 → 0.2.36
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/block.ts +7 -4
- package/src/entity.ts +6 -1
- package/src/event.ts +1 -1
- package/src/fs.ts +19 -1
- package/src/index.ts +14 -3
- package/src/inventory.ts +4 -1
- package/src/player.ts +14 -3
- package/src/server.ts +4 -2
- package/src/world.ts +53 -11
package/package.json
CHANGED
package/src/block.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 Block {
|
|
@@ -13,7 +13,10 @@ export class Block {
|
|
|
13
13
|
get location(): Location {
|
|
14
14
|
return new Location(this.x, this.y, this.z, undefined, undefined, this.world);
|
|
15
15
|
}
|
|
16
|
-
isSolid(): boolean { return
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
isSolid(): Promise<boolean> { return post<boolean>('block.isSolid', { world: this.world, x: this.x, y: this.y, z: this.z }); }
|
|
17
|
+
isSolidSync(): boolean { return call<boolean>('block.isSolid', { world: this.world, x: this.x, y: this.y, z: this.z }); }
|
|
18
|
+
isLiquid(): Promise<boolean> { return post<boolean>('block.isLiquid', { world: this.world, x: this.x, y: this.y, z: this.z }); }
|
|
19
|
+
isLiquidSync(): boolean { return call<boolean>('block.isLiquid', { world: this.world, x: this.x, y: this.y, z: this.z }); }
|
|
20
|
+
isEmpty(): Promise<boolean> { return post<boolean>('block.isEmpty', { world: this.world, x: this.x, y: this.y, z: this.z }); }
|
|
21
|
+
isEmptySync(): boolean { return call<boolean>('block.isEmpty', { world: this.world, x: this.x, y: this.y, z: this.z }); }
|
|
19
22
|
}
|
package/src/entity.ts
CHANGED
|
@@ -8,7 +8,12 @@ export class Entity {
|
|
|
8
8
|
get name(): string { return call<string>('entity.getName', { uuid: this.uuid }); }
|
|
9
9
|
get customName(): string | null { return call<string | null>('entity.getCustomName', { uuid: this.uuid }); }
|
|
10
10
|
set customName(v: string | null) { call('entity.setCustomName', { uuid: this.uuid, value: v }); }
|
|
11
|
-
setCustomNameVisible(v: boolean): Promise<void> {
|
|
11
|
+
setCustomNameVisible(v: boolean): Promise<void> {
|
|
12
|
+
return post('entity.setCustomNameVisible', { uuid: this.uuid, value: v });
|
|
13
|
+
}
|
|
14
|
+
setCustomNameVisibleSync(v: boolean): void {
|
|
15
|
+
call('entity.setCustomNameVisible', { uuid: this.uuid, value: v });
|
|
16
|
+
}
|
|
12
17
|
get world(): string | null { return call<string | null>('entity.getWorld', { uuid: this.uuid }); }
|
|
13
18
|
get location(): Location | null {
|
|
14
19
|
const r = call<LocationData>('entity.getLocation', { uuid: this.uuid });
|
package/src/event.ts
CHANGED
|
@@ -258,7 +258,7 @@ function adaptEvent<K extends keyof EventMap>(type: K, data: RawEvent): EventMap
|
|
|
258
258
|
'blockPlace', 'inventoryOpen', 'inventoryClose',
|
|
259
259
|
] as K[];
|
|
260
260
|
if (hasPlayer.includes(type) && data.player) {
|
|
261
|
-
wrap.player = Player.
|
|
261
|
+
wrap.player = Player.getSync(data.player as string);
|
|
262
262
|
}
|
|
263
263
|
if (data.from) wrap.from = loc(data.from as Record<string, unknown>);
|
|
264
264
|
if (data.to) wrap.to = loc(data.to as Record<string, unknown>);
|
package/src/fs.ts
CHANGED
|
@@ -49,6 +49,14 @@ export function writeFileBase64Sync(path: string, data: string): void {
|
|
|
49
49
|
_sendFs({ t: 'writeBase64', p: { path, data } });
|
|
50
50
|
}
|
|
51
51
|
|
|
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
|
+
});
|
|
59
|
+
}
|
|
52
60
|
export function existsSync(path: string): boolean {
|
|
53
61
|
const r = _sendFs({ t: 'exists', p: { path } });
|
|
54
62
|
return r === true || String(r) === 'true';
|
|
@@ -62,6 +70,10 @@ export function deleteFile(path: string): Promise<boolean> {
|
|
|
62
70
|
} catch (e) { reject(e); }
|
|
63
71
|
});
|
|
64
72
|
}
|
|
73
|
+
export function deleteFileSync(path: string): boolean {
|
|
74
|
+
const r = _sendFs({ t: 'delete', p: { path } });
|
|
75
|
+
return r === true || String(r) === 'true';
|
|
76
|
+
}
|
|
65
77
|
|
|
66
78
|
export function mkdir(path: string): Promise<void> {
|
|
67
79
|
return new Promise((resolve, reject) => {
|
|
@@ -69,6 +81,9 @@ export function mkdir(path: string): Promise<void> {
|
|
|
69
81
|
catch (e) { reject(e); }
|
|
70
82
|
});
|
|
71
83
|
}
|
|
84
|
+
export function mkdirSync(path: string): void {
|
|
85
|
+
_sendFs({ t: 'mkdir', p: { path } });
|
|
86
|
+
}
|
|
72
87
|
|
|
73
88
|
export function list(path: string): Promise<string[]> {
|
|
74
89
|
return new Promise((resolve, reject) => {
|
|
@@ -78,9 +93,12 @@ export function list(path: string): Promise<string[]> {
|
|
|
78
93
|
} catch (e) { reject(e); }
|
|
79
94
|
});
|
|
80
95
|
}
|
|
96
|
+
export function listSync(path: string): string[] {
|
|
97
|
+
return _sendFs({ t: 'list', p: { path } }) as string[];
|
|
98
|
+
}
|
|
81
99
|
|
|
82
100
|
export const fs = {
|
|
83
101
|
readFile, readFileSync, readFileBase64, readFileBase64Sync,
|
|
84
102
|
writeFile, writeFileSync, writeFileBase64, writeFileBase64Sync,
|
|
85
|
-
existsSync, deleteFile, mkdir, list,
|
|
103
|
+
exists, existsSync, deleteFile, deleteFileSync, mkdir, mkdirSync, list, listSync,
|
|
86
104
|
};
|
package/src/index.ts
CHANGED
|
@@ -24,9 +24,20 @@ export type {
|
|
|
24
24
|
ServerPingEvent, ServerCommandEvent,
|
|
25
25
|
} from './event.js';
|
|
26
26
|
export { onInit, onLoad, onUnload } from './lifecycle.js';
|
|
27
|
-
export {
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
export {
|
|
28
|
+
broadcast, broadcastSync, dispatchCommand, dispatchCommandSync,
|
|
29
|
+
setMotd, setMotdSync, setIcon, setIconSync,
|
|
30
|
+
getMotd, getMotdSync, getVersion, getVersionSync,
|
|
31
|
+
} from './server.js';
|
|
32
|
+
export {
|
|
33
|
+
fs,
|
|
34
|
+
readFile, readFileSync, readFileBase64, readFileBase64Sync,
|
|
35
|
+
writeFile, writeFileSync, writeFileBase64, writeFileBase64Sync,
|
|
36
|
+
exists, existsSync, deleteFile, deleteFileSync, mkdir, mkdirSync, list, listSync,
|
|
37
|
+
} from './fs.js';
|
|
38
|
+
export { assets, read as assetsRead, readSync as assetsReadSync,
|
|
39
|
+
readBase64 as assetsReadBase64, readBase64Sync as assetsReadBase64Sync,
|
|
40
|
+
extract as assetsExtract, extractSync as assetsExtractSync } from './assets.js';
|
|
30
41
|
export { path } from './path.js';
|
|
31
42
|
export { listen, respond, close, request, requestSync } from './http.js';
|
|
32
43
|
export { logError } from './log-error.js';
|
package/src/inventory.ts
CHANGED
|
@@ -8,7 +8,10 @@ interface ItemData {
|
|
|
8
8
|
export class Inventory {
|
|
9
9
|
constructor(private readonly uuid: string) {}
|
|
10
10
|
|
|
11
|
-
getItem(slot: number): ItemData | null {
|
|
11
|
+
getItem(slot: number): Promise<ItemData | null> {
|
|
12
|
+
return post<ItemData | null>('inventory.getItem', { uuid: this.uuid, slot });
|
|
13
|
+
}
|
|
14
|
+
getItemSync(slot: number): ItemData | null {
|
|
12
15
|
return call<ItemData | null>('inventory.getItem', { uuid: this.uuid, slot });
|
|
13
16
|
}
|
|
14
17
|
setItem(slot: number, itemType: string, amount?: number): Promise<void> {
|
package/src/player.ts
CHANGED
|
@@ -7,11 +7,17 @@ interface PlayerData {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export class Player {
|
|
10
|
-
static get(identifier: string): Player | null {
|
|
10
|
+
static get(identifier: string): Promise<Player | null> {
|
|
11
|
+
return post<PlayerData>('player.get', { identifier }).then((d) => (d ? new Player(d.uuid, d.name) : null));
|
|
12
|
+
}
|
|
13
|
+
static getSync(identifier: string): Player | null {
|
|
11
14
|
const d = call<PlayerData>('player.get', { identifier });
|
|
12
15
|
return d ? new Player(d.uuid, d.name) : null;
|
|
13
16
|
}
|
|
14
|
-
static getAll(): Player[] {
|
|
17
|
+
static getAll(): Promise<Player[]> {
|
|
18
|
+
return post<PlayerData[]>('player.getAll', {}).then((list) => list.map((r) => new Player(r.uuid, r.name)));
|
|
19
|
+
}
|
|
20
|
+
static getAllSync(): Player[] {
|
|
15
21
|
return call<PlayerData[]>('player.getAll', {}).map((r) => new Player(r.uuid, r.name));
|
|
16
22
|
}
|
|
17
23
|
|
|
@@ -49,7 +55,12 @@ export class Player {
|
|
|
49
55
|
}
|
|
50
56
|
giveExp(amount: number): Promise<void> { return post('player.giveExp', { uuid: this.uuid, amount }); }
|
|
51
57
|
giveExpSync(amount: number): void { call('player.giveExp', { uuid: this.uuid, amount }); }
|
|
52
|
-
hasPermission(node: string):
|
|
58
|
+
hasPermission(node: string): Promise<boolean> {
|
|
59
|
+
return post<boolean>('player.hasPermission', { uuid: this.uuid, permission: node });
|
|
60
|
+
}
|
|
61
|
+
hasPermissionSync(node: string): boolean {
|
|
62
|
+
return call<boolean>('player.hasPermission', { uuid: this.uuid, permission: node });
|
|
63
|
+
}
|
|
53
64
|
teleport(loc: Location): Promise<void> { return post('player.teleport', { uuid: this.uuid, ...loc.toObject() }); }
|
|
54
65
|
teleportSync(loc: Location): void { call('player.teleport', { uuid: this.uuid, ...loc.toObject() }); }
|
|
55
66
|
}
|
package/src/server.ts
CHANGED
|
@@ -8,5 +8,7 @@ export function setMotd(motd: string): Promise<void> { return post('server.setMo
|
|
|
8
8
|
export function setMotdSync(motd: string): void { call('server.setMotd', { motd }); }
|
|
9
9
|
export function setIcon(base64: string): Promise<void> { return post('server.setIcon', { icon: base64 }); }
|
|
10
10
|
export function setIconSync(base64: string): void { call('server.setIcon', { icon: base64 }); }
|
|
11
|
-
export function getMotd(): string { return
|
|
12
|
-
export function
|
|
11
|
+
export function getMotd(): Promise<string> { return post<string>('server.getMotd', {}); }
|
|
12
|
+
export function getMotdSync(): string { return call<string>('server.getMotd', {}); }
|
|
13
|
+
export function getVersion(): Promise<string> { return post<string>('server.getVersion', {}); }
|
|
14
|
+
export function getVersionSync(): string { return call<string>('server.getVersion', {}); }
|
package/src/world.ts
CHANGED
|
@@ -7,11 +7,17 @@ interface WorldData {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export class World {
|
|
10
|
-
static get(name: string): World | null {
|
|
10
|
+
static get(name: string): Promise<World | null> {
|
|
11
|
+
return post<WorldData>('world.get', { name }).then((d) => (d ? new World(d.name) : null));
|
|
12
|
+
}
|
|
13
|
+
static getSync(name: string): World | null {
|
|
11
14
|
const d = call<WorldData>('world.get', { name });
|
|
12
15
|
return d ? new World(d.name) : null;
|
|
13
16
|
}
|
|
14
|
-
static getAll(): World[] {
|
|
17
|
+
static getAll(): Promise<World[]> {
|
|
18
|
+
return post<WorldData[]>('world.getAll', {}).then((list) => list.map((r) => new World(r.name)));
|
|
19
|
+
}
|
|
20
|
+
static getAllSync(): World[] {
|
|
15
21
|
return call<WorldData[]>('world.getAll', {}).map((r) => new World(r.name));
|
|
16
22
|
}
|
|
17
23
|
|
|
@@ -31,12 +37,35 @@ export class World {
|
|
|
31
37
|
}
|
|
32
38
|
set spawnLocation(v: Location) { call('world.setSpawnLocation', { world: this.name, ...v.toObject() }); }
|
|
33
39
|
|
|
34
|
-
getHighestBlockY(x: number, z: number):
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
getHighestBlockY(x: number, z: number): Promise<number> {
|
|
41
|
+
return post<number>('world.getHighestBlockY', { world: this.name, x, z });
|
|
42
|
+
}
|
|
43
|
+
getHighestBlockYSync(x: number, z: number): number {
|
|
44
|
+
return call<number>('world.getHighestBlockY', { world: this.name, x, z });
|
|
45
|
+
}
|
|
46
|
+
getGameRule(rule: string): Promise<string | null> {
|
|
47
|
+
return post<string | null>('world.getGameRule', { world: this.name, rule });
|
|
48
|
+
}
|
|
49
|
+
getGameRuleSync(rule: string): string | null {
|
|
50
|
+
return call<string | null>('world.getGameRule', { world: this.name, rule });
|
|
51
|
+
}
|
|
52
|
+
setGameRule(rule: string, value: string): Promise<boolean> {
|
|
53
|
+
return post('world.setGameRule', { world: this.name, rule, value });
|
|
54
|
+
}
|
|
55
|
+
setGameRuleSync(rule: string, value: string): boolean {
|
|
56
|
+
return call<boolean>('world.setGameRule', { world: this.name, rule, value });
|
|
57
|
+
}
|
|
58
|
+
getBiome(x: number, y: number, z: number): Promise<string> {
|
|
59
|
+
return post<string>('world.getBiome', { world: this.name, x, y, z });
|
|
60
|
+
}
|
|
61
|
+
getBiomeSync(x: number, y: number, z: number): string {
|
|
62
|
+
return call<string>('world.getBiome', { world: this.name, x, y, z });
|
|
63
|
+
}
|
|
64
|
+
getBlock(x: number, y: number, z: number): Promise<Block | null> {
|
|
65
|
+
return post<{ x: number; y: number; z: number; type: string }>('world.getBlock', { world: this.name, x, y, z })
|
|
66
|
+
.then((r) => (r ? new Block(this.name, r.x, r.y, r.z, r.type) : null));
|
|
67
|
+
}
|
|
68
|
+
getBlockSync(x: number, y: number, z: number): Block | null {
|
|
40
69
|
const r = call<{ x: number; y: number; z: number; type: string }>('world.getBlock', { world: this.name, x, y, z });
|
|
41
70
|
return r ? new Block(this.name, r.x, r.y, r.z, r.type) : null;
|
|
42
71
|
}
|
|
@@ -46,9 +75,22 @@ export class World {
|
|
|
46
75
|
setBlockSync(x: number, y: number, z: number, blockType: string): void {
|
|
47
76
|
call('world.setBlock', { world: this.name, x, y, z, blockType });
|
|
48
77
|
}
|
|
49
|
-
getEntities():
|
|
50
|
-
|
|
51
|
-
|
|
78
|
+
getEntities(): Promise<string[]> {
|
|
79
|
+
return post<string[]>('world.getEntities', { world: this.name });
|
|
80
|
+
}
|
|
81
|
+
getEntitiesSync(): string[] {
|
|
82
|
+
return call<string[]>('world.getEntities', { world: this.name });
|
|
83
|
+
}
|
|
84
|
+
getPlayers(): Promise<string[]> {
|
|
85
|
+
return post<string[]>('world.getPlayers', { world: this.name });
|
|
86
|
+
}
|
|
87
|
+
getPlayersSync(): string[] {
|
|
88
|
+
return call<string[]>('world.getPlayers', { world: this.name });
|
|
89
|
+
}
|
|
90
|
+
getNearbyEntities(x: number, y: number, z: number, radius: number): Promise<string[]> {
|
|
91
|
+
return post<string[]>('world.getNearbyEntities', { world: this.name, x, y, z, radius });
|
|
92
|
+
}
|
|
93
|
+
getNearbyEntitiesSync(x: number, y: number, z: number, radius: number): string[] {
|
|
52
94
|
return call<string[]>('world.getNearbyEntities', { world: this.name, x, y, z, radius });
|
|
53
95
|
}
|
|
54
96
|
dropItem(x: number, y: number, z: number, itemType: string, amount?: number): Promise<void> {
|