yeow-api 0.2.106 → 0.2.107
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/core.ts +91 -0
- package/src/http.ts +18 -2
- package/src/index.ts +14 -90
- package/src/server.ts +4 -0
package/package.json
CHANGED
package/src/core.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/// <reference path="global.d.ts" />
|
|
2
|
+
|
|
3
|
+
export { call } from './task.js';
|
|
4
|
+
export { Location } from './location.js';
|
|
5
|
+
export { Player } from './player.js';
|
|
6
|
+
export { World } from './world.js';
|
|
7
|
+
export { Chunk, ChunkSnapshot, ChunkTopSnapshot } from './chunk.js';
|
|
8
|
+
export type { ChunkData } from './chunk.js';
|
|
9
|
+
export { Entity, LivingEntity } from './entity.js';
|
|
10
|
+
export type { BoundingBox } from './entity.js';
|
|
11
|
+
export { Block } from './block.js';
|
|
12
|
+
export { Inventory } from './inventory.js';
|
|
13
|
+
export { registerCommand } from './command.js';
|
|
14
|
+
export type { CommandOptions, CommandPayload, CommandSender, ManualCompleter } from './command.js';
|
|
15
|
+
export { eventOn, eventOff } from './event.js';
|
|
16
|
+
export type {
|
|
17
|
+
PlayerJoinEvent, PlayerQuitEvent, PlayerChatEvent, PlayerMoveEvent,
|
|
18
|
+
PlayerInteractEvent, PlayerCommandEvent, PlayerDeathEvent, PlayerRespawnEvent,
|
|
19
|
+
PlayerTeleportEvent, PlayerItemConsumeEvent,
|
|
20
|
+
PlayerAdvancementDoneEvent, PlayerToggleSneakEvent, PlayerToggleFlightEvent,
|
|
21
|
+
PlayerDropItemEvent, PlayerPickupItemEvent, PlayerBucketFillEvent, PlayerBucketEmptyEvent,
|
|
22
|
+
PlayerExpChangeEvent, PlayerLevelChangeEvent, PlayerGameModeChangeEvent, FoodLevelChangeEvent,
|
|
23
|
+
EntityDamageEvent, EntityDeathEvent, EntitySpawnEvent, EntityExplodeEvent,
|
|
24
|
+
EntityRegainHealthEvent, EntityTargetEvent,
|
|
25
|
+
ProjectileLaunchEvent, ProjectileHitEvent,
|
|
26
|
+
BlockBreakEvent, BlockPlaceEvent, BlockFadeEvent, BlockGrowEvent, BlockSpreadEvent, BlockExplodeEvent,
|
|
27
|
+
InventoryOpenEvent, InventoryCloseEvent, InventoryClickEvent,
|
|
28
|
+
ServerPingEvent, ServerCommandEvent,
|
|
29
|
+
PlayerResourcePackStatusEvent,
|
|
30
|
+
} from './event.js';
|
|
31
|
+
export { onInit, onLoad, onUnload } from './lifecycle.js';
|
|
32
|
+
export {
|
|
33
|
+
broadcast, broadcastSync, dispatchCommand, dispatchCommandSync,
|
|
34
|
+
setMotd, setMotdSync, setIcon, setIconSync,
|
|
35
|
+
getMotd, getMotdSync, getVersion, getVersionSync,
|
|
36
|
+
getTps, getTpsSync, getMaxPlayers, getMaxPlayersSync,
|
|
37
|
+
} from './server.js';
|
|
38
|
+
export type { TpsInfo } from './server.js';
|
|
39
|
+
export {
|
|
40
|
+
fs,
|
|
41
|
+
readFile, readFileSync, readFileBase64, readFileBase64Sync,
|
|
42
|
+
writeFile, writeFileSync, writeFileBase64, writeFileBase64Sync,
|
|
43
|
+
appendFile, appendFileSync,
|
|
44
|
+
exists, existsSync, isDirectory, isDirectorySync,
|
|
45
|
+
deleteFile, deleteFileSync, mkdir, mkdirSync, list, listSync,
|
|
46
|
+
} from './fs.js';
|
|
47
|
+
export { assets, read as assetsRead, readSync as assetsReadSync,
|
|
48
|
+
readBase64 as assetsReadBase64, readBase64Sync as assetsReadBase64Sync,
|
|
49
|
+
extract as assetsExtract, extractSync as assetsExtractSync,
|
|
50
|
+
extractDir as assetsExtractDir, extractDirSync as assetsExtractDirSync } from './assets.js';
|
|
51
|
+
export { path } from './path.js';
|
|
52
|
+
export { listen, respond, close, request, requestSync } from './http.js';
|
|
53
|
+
export { logError } from './log-error.js';
|
|
54
|
+
export { InstanceId, GUIHandle, BossBarHandle, InventoryHandle } from './instance-id.js';
|
|
55
|
+
export type { ItemStack } from './item.js';
|
|
56
|
+
export type { PotionEffect } from './potion.js';
|
|
57
|
+
export { addPotionEffect, removePotionEffect, clearPotionEffects, getActivePotionEffects } from './potion.js';
|
|
58
|
+
export { playSound, stopSound, stopAllSounds } from './sound.js';
|
|
59
|
+
export type { ParticleOptions } from './particle.js';
|
|
60
|
+
export { spawnParticle } from './particle.js';
|
|
61
|
+
export { get as pdcGet, set as pdcSet, has as pdcHas, remove as pdcRemove, keys as pdcKeys,
|
|
62
|
+
getBlock as pdcGetBlock, setBlock as pdcSetBlock, hasBlock as pdcHasBlock, removeBlock as pdcRemoveBlock } from './pdc.js';
|
|
63
|
+
export { createBossBar, destroy as destroyBossBar,
|
|
64
|
+
setTitle as setBossBarTitle, setProgress as setBossBarProgress,
|
|
65
|
+
setColor as setBossBarColor, setStyle as setBossBarStyle,
|
|
66
|
+
setVisible as setBossBarVisible, addPlayer as addBossBarPlayer,
|
|
67
|
+
removePlayer as removeBossBarPlayer, removeAll as removeAllBossBarPlayers,
|
|
68
|
+
addFlag as addBossBarFlag, removeFlag as removeBossBarFlag } from './bossbar.js';
|
|
69
|
+
export type { BossBarOptions } from './bossbar.js';
|
|
70
|
+
export { createGUI, destroy as destroyGUI, open as openGUI,
|
|
71
|
+
close as closeGUI, setItem as setGUIItem, fill as fillGUI, clear as clearGUI } from './gui.js';
|
|
72
|
+
export type { AdvancementProgress } from './advancement.js';
|
|
73
|
+
export { grant as grantAdvancement, revoke as revokeAdvancement,
|
|
74
|
+
getProgress as getAdvancementProgress, awardCriteria, revokeCriteria } from './advancement.js';
|
|
75
|
+
export { add as addRecipe, remove as removeRecipe, getForItem as getRecipesForItem } from './recipe.js';
|
|
76
|
+
export type {
|
|
77
|
+
ObjectiveInfo, TeamInfo,
|
|
78
|
+
} from './scoreboard.js';
|
|
79
|
+
export { createBoard as createScoreboard, deleteBoard as deleteScoreboard,
|
|
80
|
+
createObjective, deleteObjective, getObjectives,
|
|
81
|
+
setObjectiveDisplay, getScore, setScore, resetScore,
|
|
82
|
+
createTeam, deleteTeam, getTeam, getTeams,
|
|
83
|
+
setTeamDisplayName, setTeamPrefix, setTeamSuffix, setTeamColor,
|
|
84
|
+
setTeamFriendlyFire, setTeamSeeInvisible, setTeamOption,
|
|
85
|
+
teamAddEntry, teamRemoveEntry, teamGetEntries,
|
|
86
|
+
setPlayerBoard } from './scoreboard.js';
|
|
87
|
+
export { getMaterials, getBlocks, getItems } from './material.js';
|
|
88
|
+
export type { MaterialInfo } from './material.js';
|
|
89
|
+
export { registerService, registerNativeService, request as serviceRequest, subscribe as serviceSubscribe, publish as servicePublish } from './service.js';
|
|
90
|
+
export type { ServiceResult, NativeServiceResult } from './service.js';
|
|
91
|
+
export { log, Logger } from './log.js';
|
package/src/http.ts
CHANGED
|
@@ -48,11 +48,27 @@ _registerCallback(() => {
|
|
|
48
48
|
_servers.clear();
|
|
49
49
|
}, { persistent: true });
|
|
50
50
|
|
|
51
|
+
/**
|
|
52
|
+
* 异步 HTTP 请求(不阻塞 JS 线程)——底层走 `http:requestAsync` 通道。
|
|
53
|
+
* 推荐用于事件处理器与高频场景。需要同步阻塞返回的用 `requestSync`。
|
|
54
|
+
*/
|
|
51
55
|
export function request(url: string, opts: Record<string, unknown> = {}): Promise<HttpResult> {
|
|
52
56
|
return new Promise((resolve, reject) => {
|
|
57
|
+
const cbId = _registerCallback((result: unknown) => {
|
|
58
|
+
if ((result as any)?.err) reject(new Error((result as any).err));
|
|
59
|
+
else resolve(result as HttpResult);
|
|
60
|
+
});
|
|
53
61
|
try {
|
|
54
|
-
|
|
55
|
-
resolve(result);
|
|
62
|
+
_sendHttp({ t: 'requestAsync', p: { url, ...opts, cb: String(cbId) } });
|
|
56
63
|
} catch (e) { reject(e); }
|
|
57
64
|
});
|
|
58
65
|
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 同步 HTTP 请求(**阻塞 JS 线程**直到响应返回)——底层走 `http:request` 通道。
|
|
69
|
+
* 阻塞期间 JS 线程无法处理事件/命令/回调(可能触发 event.timeout 告警);
|
|
70
|
+
* 仅适合低频、非事件上下文。事件处理器或高频场景请用 `request`(异步)或全局 `fetch`。
|
|
71
|
+
*/
|
|
72
|
+
export function requestSync(url: string, opts: Record<string, unknown> = {}): HttpResult {
|
|
73
|
+
return _sendHttp({ t: 'request', p: { url, ...opts } });
|
|
74
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,91 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Yeow API 入口。
|
|
3
|
+
*
|
|
4
|
+
* 全部具名导出来自 `core.ts`(与历史导出面完全一致);默认导出 `Yeow` 为
|
|
5
|
+
* 聚合全部具名导出的**大对象**——不推荐使用:默认导入会破坏 tree-shaking,
|
|
6
|
+
* 显著增大插件体积,仅适用于简化动态执行含任意逻辑的代码。请按需命名导入。
|
|
7
|
+
*/
|
|
8
|
+
export * from './core.js';
|
|
2
9
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export { Entity, LivingEntity } from './entity.js';
|
|
10
|
-
export type { BoundingBox } from './entity.js';
|
|
11
|
-
export { Block } from './block.js';
|
|
12
|
-
export { Inventory } from './inventory.js';
|
|
13
|
-
export { registerCommand } from './command.js';
|
|
14
|
-
export type { CommandOptions, CommandPayload, CommandSender, ManualCompleter } from './command.js';
|
|
15
|
-
export { eventOn, eventOff } from './event.js';
|
|
16
|
-
export type {
|
|
17
|
-
PlayerJoinEvent, PlayerQuitEvent, PlayerChatEvent, PlayerMoveEvent,
|
|
18
|
-
PlayerInteractEvent, PlayerCommandEvent, PlayerDeathEvent, PlayerRespawnEvent,
|
|
19
|
-
PlayerTeleportEvent, PlayerItemConsumeEvent,
|
|
20
|
-
PlayerAdvancementDoneEvent, PlayerToggleSneakEvent, PlayerToggleFlightEvent,
|
|
21
|
-
PlayerDropItemEvent, PlayerPickupItemEvent, PlayerBucketFillEvent, PlayerBucketEmptyEvent,
|
|
22
|
-
PlayerExpChangeEvent, PlayerLevelChangeEvent, PlayerGameModeChangeEvent, FoodLevelChangeEvent,
|
|
23
|
-
EntityDamageEvent, EntityDeathEvent, EntitySpawnEvent, EntityExplodeEvent,
|
|
24
|
-
EntityRegainHealthEvent, EntityTargetEvent,
|
|
25
|
-
ProjectileLaunchEvent, ProjectileHitEvent,
|
|
26
|
-
BlockBreakEvent, BlockPlaceEvent, BlockFadeEvent, BlockGrowEvent, BlockSpreadEvent, BlockExplodeEvent,
|
|
27
|
-
InventoryOpenEvent, InventoryCloseEvent, InventoryClickEvent,
|
|
28
|
-
ServerPingEvent, ServerCommandEvent,
|
|
29
|
-
PlayerResourcePackStatusEvent,
|
|
30
|
-
} from './event.js';
|
|
31
|
-
export { onInit, onLoad, onUnload } from './lifecycle.js';
|
|
32
|
-
export {
|
|
33
|
-
broadcast, broadcastSync, dispatchCommand, dispatchCommandSync,
|
|
34
|
-
setMotd, setMotdSync, setIcon, setIconSync,
|
|
35
|
-
getMotd, getMotdSync, getVersion, getVersionSync,
|
|
36
|
-
getTps, getTpsSync,
|
|
37
|
-
} from './server.js';
|
|
38
|
-
export type { TpsInfo } from './server.js';
|
|
39
|
-
export {
|
|
40
|
-
fs,
|
|
41
|
-
readFile, readFileSync, readFileBase64, readFileBase64Sync,
|
|
42
|
-
writeFile, writeFileSync, writeFileBase64, writeFileBase64Sync,
|
|
43
|
-
appendFile, appendFileSync,
|
|
44
|
-
exists, existsSync, isDirectory, isDirectorySync,
|
|
45
|
-
deleteFile, deleteFileSync, mkdir, mkdirSync, list, listSync,
|
|
46
|
-
} from './fs.js';
|
|
47
|
-
export { assets, read as assetsRead, readSync as assetsReadSync,
|
|
48
|
-
readBase64 as assetsReadBase64, readBase64Sync as assetsReadBase64Sync,
|
|
49
|
-
extract as assetsExtract, extractSync as assetsExtractSync,
|
|
50
|
-
extractDir as assetsExtractDir, extractDirSync as assetsExtractDirSync } from './assets.js';
|
|
51
|
-
export { path } from './path.js';
|
|
52
|
-
export { listen, respond, close, request } from './http.js';
|
|
53
|
-
export { logError } from './log-error.js';
|
|
54
|
-
export { InstanceId, GUIHandle, BossBarHandle, InventoryHandle } from './instance-id.js';
|
|
55
|
-
export type { ItemStack } from './item.js';
|
|
56
|
-
export type { PotionEffect } from './potion.js';
|
|
57
|
-
export { addPotionEffect, removePotionEffect, clearPotionEffects, getActivePotionEffects } from './potion.js';
|
|
58
|
-
export { playSound, stopSound, stopAllSounds } from './sound.js';
|
|
59
|
-
export type { ParticleOptions } from './particle.js';
|
|
60
|
-
export { spawnParticle } from './particle.js';
|
|
61
|
-
export { get as pdcGet, set as pdcSet, has as pdcHas, remove as pdcRemove, keys as pdcKeys,
|
|
62
|
-
getBlock as pdcGetBlock, setBlock as pdcSetBlock, hasBlock as pdcHasBlock, removeBlock as pdcRemoveBlock } from './pdc.js';
|
|
63
|
-
export { createBossBar, destroy as destroyBossBar,
|
|
64
|
-
setTitle as setBossBarTitle, setProgress as setBossBarProgress,
|
|
65
|
-
setColor as setBossBarColor, setStyle as setBossBarStyle,
|
|
66
|
-
setVisible as setBossBarVisible, addPlayer as addBossBarPlayer,
|
|
67
|
-
removePlayer as removeBossBarPlayer, removeAll as removeAllBossBarPlayers,
|
|
68
|
-
addFlag as addBossBarFlag, removeFlag as removeBossBarFlag } from './bossbar.js';
|
|
69
|
-
export type { BossBarOptions } from './bossbar.js';
|
|
70
|
-
export { createGUI, destroy as destroyGUI, open as openGUI,
|
|
71
|
-
close as closeGUI, setItem as setGUIItem, fill as fillGUI, clear as clearGUI } from './gui.js';
|
|
72
|
-
export type { AdvancementProgress } from './advancement.js';
|
|
73
|
-
export { grant as grantAdvancement, revoke as revokeAdvancement,
|
|
74
|
-
getProgress as getAdvancementProgress, awardCriteria, revokeCriteria } from './advancement.js';
|
|
75
|
-
export { add as addRecipe, remove as removeRecipe, getForItem as getRecipesForItem } from './recipe.js';
|
|
76
|
-
export type {
|
|
77
|
-
ObjectiveInfo, TeamInfo,
|
|
78
|
-
} from './scoreboard.js';
|
|
79
|
-
export { createBoard as createScoreboard, deleteBoard as deleteScoreboard,
|
|
80
|
-
createObjective, deleteObjective, getObjectives,
|
|
81
|
-
setObjectiveDisplay, getScore, setScore, resetScore,
|
|
82
|
-
createTeam, deleteTeam, getTeam, getTeams,
|
|
83
|
-
setTeamDisplayName, setTeamPrefix, setTeamSuffix, setTeamColor,
|
|
84
|
-
setTeamFriendlyFire, setTeamSeeInvisible, setTeamOption,
|
|
85
|
-
teamAddEntry, teamRemoveEntry, teamGetEntries,
|
|
86
|
-
setPlayerBoard } from './scoreboard.js';
|
|
87
|
-
export { getMaterials, getBlocks, getItems } from './material.js';
|
|
88
|
-
export type { MaterialInfo } from './material.js';
|
|
89
|
-
export { registerService, registerNativeService, request as serviceRequest, subscribe as serviceSubscribe, publish as servicePublish } from './service.js';
|
|
90
|
-
export type { ServiceResult, NativeServiceResult } from './service.js';
|
|
91
|
-
export { log, Logger } from './log.js';
|
|
10
|
+
import * as api from './core.js';
|
|
11
|
+
|
|
12
|
+
const Yeow = { ...api };
|
|
13
|
+
|
|
14
|
+
export default Yeow;
|
|
15
|
+
export { Yeow };
|
package/src/server.ts
CHANGED
|
@@ -28,3 +28,7 @@ export interface TpsInfo {
|
|
|
28
28
|
*/
|
|
29
29
|
export function getTps(options?: TaskOptions): Promise<TpsInfo> { return post<TpsInfo>('server.getTps', {}, options); }
|
|
30
30
|
export function getTpsSync(options?: TaskOptions): TpsInfo { return call<TpsInfo>('server.getTps', {}, options); }
|
|
31
|
+
|
|
32
|
+
/** 服务器最大玩家数。 */
|
|
33
|
+
export function getMaxPlayers(options?: TaskOptions): Promise<number> { return post<number>('server.getMaxPlayers', {}, options); }
|
|
34
|
+
export function getMaxPlayersSync(options?: TaskOptions): number { return call<number>('server.getMaxPlayers', {}, options); }
|