UNPKG

minecraft-management-client

Version:

A lightweight client library for Frontend/Node.js environments that wraps the Minecraft Server Management Protocol introduced in 25w35a. With this library, you can manage a Minecraft server directly from JavaScript code

664 lines (631 loc) 23.2 kB
interface UntypedGameRule { key: string; value: string; } interface IncomingIpBan { reason: string; expires: string; ip: string; source: string; player: Player; } interface SystemMessage { receivingPlayers: Player[]; overlay: boolean; message: Message; } interface KickPlayer { players: Player[]; message: Message; } interface IpBan { reason: string; expires: string; ip: string; source: string; } interface TypedGameRule { type: 'integer' | 'boolean'; key: string; value: string; } interface UserBan { reason: string; expires: string; source: string; player: Player; } interface Message { translatable: string; translatableParams: string[]; literal: string; } interface Version { protocol: number; name: string; } interface ServerState { players: Player[]; started: boolean; version: Version; } interface Operator { permissionLevel: number; bypassesPlayerLimit: boolean; player: Player; } interface Player { id: string; name: string; } type schemas_IncomingIpBan = IncomingIpBan; type schemas_IpBan = IpBan; type schemas_KickPlayer = KickPlayer; type schemas_Message = Message; type schemas_Operator = Operator; type schemas_Player = Player; type schemas_ServerState = ServerState; type schemas_SystemMessage = SystemMessage; type schemas_TypedGameRule = TypedGameRule; type schemas_UntypedGameRule = UntypedGameRule; type schemas_UserBan = UserBan; type schemas_Version = Version; declare namespace schemas { export type { schemas_IncomingIpBan as IncomingIpBan, schemas_IpBan as IpBan, schemas_KickPlayer as KickPlayer, schemas_Message as Message, schemas_Operator as Operator, schemas_Player as Player, schemas_ServerState as ServerState, schemas_SystemMessage as SystemMessage, schemas_TypedGameRule as TypedGameRule, schemas_UntypedGameRule as UntypedGameRule, schemas_UserBan as UserBan, schemas_Version as Version }; } /** * allowlist */ /** * Get the allowlist */ declare function get$4(): Method<undefined, Player[]>; /** * Set the allowlist * @param players player list */ declare function set$3(players: Player[]): Method<Player[], Player[]>; /** * Add players to allowlist * @param players player list */ declare function add$3(players: Player[]): Method<Player[], Player[]>; /** * Remove players from allowlist * @param players player list */ declare function remove$3(players: Player[]): Method<Player[], Player[]>; /** * Clear all players in allowlist */ declare function clear$3(): Method<undefined, Player[]>; declare namespace index$8 { export { add$3 as add, clear$3 as clear, get$4 as get, remove$3 as remove, set$3 as set }; } /** * bans */ /** * Get the ban list */ declare function get$3(): Method<undefined, UserBan[]>; /** * Set the banlist * @param bans ban list */ declare function set$2(bans: UserBan[]): Method<UserBan[], UserBan[]>; /** * Add players to ban list * @param bans ban list */ declare function add$2(bans: UserBan[]): Method<UserBan[], UserBan[]>; /** * Remove players from ban list * @param bans ban list */ declare function remove$2(bans: UserBan[]): Method<UserBan[], UserBan[]>; /** * Clear all players in ban list */ declare function clear$2(): Method<undefined, UserBan[]>; declare namespace index$7 { export { add$2 as add, clear$2 as clear, get$3 as get, remove$2 as remove, set$2 as set }; } /** * ip_bans */ /** * Get the ip ban list */ declare function get$2(): Method<undefined, IpBan[]>; /** * Set the ip banlist * @param ipBans ip ban list */ declare function set$1(ipBans: IpBan[]): Method<IpBan[], IpBan[]>; /** * Add ip to ban list * @param ipBans ip ban list */ declare function add$1(ipBans: IpBan[]): Method<IpBan[], IpBan[]>; /** * Remove ip from ban list * @param ipBans ip ban list */ declare function remove$1(ipBans: IpBan[]): Method<IpBan[], IpBan[]>; /** * Clear all ips in ban list */ declare function clear$1(): Method<undefined, IpBan[]>; declare namespace index$6 { export { add$1 as add, clear$1 as clear, get$2 as get, remove$1 as remove, set$1 as set }; } /** * operators */ /** * Get all oped players */ declare function get$1(): Method<undefined, Operator[]>; /** * Set all oped players * @param ops op list */ declare function set(ops: Operator[]): Method<Operator[], Operator[]>; /** * Op players * @param ops op list */ declare function add(ops: Operator[]): Method<Operator[], Operator[]>; /** * Deop players * @param players player list */ declare function remove(players: Player[]): Method<Player[], Operator[]>; /** * Deop all players */ declare function clear(): Method<undefined, Operator[]>; declare const index$5_add: typeof add; declare const index$5_clear: typeof clear; declare const index$5_remove: typeof remove; declare const index$5_set: typeof set; declare namespace index$5 { export { index$5_add as add, index$5_clear as clear, get$1 as get, index$5_remove as remove, index$5_set as set }; } /** * players */ /** * Get all connected players */ declare function get(): Method<undefined, Player[]>; /** * Kick players * @param kickPlayer kick players */ declare function kick(kickPlayer: KickPlayer[]): Method<KickPlayer[], Player[]>; declare const index$4_get: typeof get; declare const index$4_kick: typeof kick; declare namespace index$4 { export { index$4_get as get, index$4_kick as kick }; } /** * server */ /** * Get server status */ declare function status(): Method<undefined, ServerState>; /** * Save server state * @param flush Whether to flush the state */ declare function save(flush: boolean): Method<{ flush: boolean; }, boolean>; /** * Stop server */ declare function stop(): Method<undefined, boolean>; /** * Send a system message * @param msg system message */ declare function systemMessage(msg: SystemMessage): Method<SystemMessage, boolean>; declare const index$3_save: typeof save; declare const index$3_status: typeof status; declare const index$3_stop: typeof stop; declare const index$3_systemMessage: typeof systemMessage; declare namespace index$3 { export { index$3_save as save, index$3_status as status, index$3_stop as stop, index$3_systemMessage as systemMessage }; } declare enum Difficulty { Peaceful = "peaceful", Easy = "easy", Normal = "normal", Hard = "hard" } declare enum GameMode { Survival = "survival", Creative = "creative", Adventure = "adventure", Spectator = "spectator" } type enums_Difficulty = Difficulty; declare const enums_Difficulty: typeof Difficulty; type enums_GameMode = GameMode; declare const enums_GameMode: typeof GameMode; declare namespace enums { export { enums_Difficulty as Difficulty, enums_GameMode as GameMode }; } /** * serversettings */ /** * Get whether automatic world saving is enabled on the server */ declare function getAutosave(): Method<undefined, boolean>; /** * Enable or disable automatic world saving on the server * @param enable enable or disable auto saving */ declare function setAutosave(enable: boolean): Method<{ enable: boolean; }, boolean>; /** * Get the current difficulty level of the server */ declare function getDifficulty(): Method<undefined, string>; /** * Set the difficulty level of the server * @param difficulty difficulty */ declare function setDifficulty(difficulty: Difficulty): Method<{ difficulty: Difficulty; }, boolean>; /** * Get whether allowlist enforcement is enabled (kicks players immediately when removed from allowlist) */ declare function getEnforceAllowlist(): Method<undefined, boolean>; /** * Enable or disable allowlist enforcement (when enabled, players are kicked immediately upon removal from allowlist) * @param enforce isEnforce */ declare function setEnforceAllowlist(enforce: boolean): Method<{ enforce: boolean; }, boolean>; /** * Get whether the allowlist is enabled on the server */ declare function getUseAllowlist(): Method<undefined, boolean>; /** * Enable or disable the allowlist on the server (controls whether only allowlisted players can join) * @param use isUse */ declare function setUseAllowlist(use: boolean): Method<{ use: boolean; }, boolean>; /** * Get the maximum number of players allowed to connect to the server */ declare function getMaxPlayers(): Method<undefined, number>; /** * Set the maximum number of players allowed to connect to the server * @param max max player num */ declare function setMaxPlayers(max: number): Method<{ max: number; }, boolean>; /** * Get the number of seconds before the game is automatically paused when no players are online */ declare function getPauseWhenEmptySeconds(): Method<undefined, number>; /** * Set the number of seconds before the game is automatically paused when no players are online * @param seconds pause duration in seconds */ declare function setPauseWhenEmptySeconds(seconds: number): Method<{ seconds: number; }, number>; /** * Get the number of seconds before idle players are automatically kicked from the server */ declare function getPlayerIdleTimeout(): Method<undefined, number>; /** * Set the number of seconds before idle players are automatically kicked from the server * @param seconds idle timeout duration in seconds */ declare function setPlayerIdleTimeout(seconds: number): Method<{ seconds: number; }, number>; /** * Get whether flight is allowed for players in Survival mode */ declare function getAllowFlight(): Method<undefined, boolean>; /** * Allow or disallow flight for players in Survival mode * @param allow whether to allow flight */ declare function setAllowFlight(allow: boolean): Method<{ allow: boolean; }, boolean>; /** * Get the server's message of displayed to players */ declare function getMotd(): Method<undefined, string>; /** * Set the server's message of the day displayed to players * @param message message */ declare function setMotd(message: string): Method<{ message: string; }, string>; /** * Get the spawn protection radius in blocks (only operators can edit within this area) */ declare function getSpawnProtectionRadius(): Method<undefined, number>; /** * Set the spawn protection radius in blocks (only operators can edit within this area) * @param radius radius */ declare function setSpawnProtectionRadius(radius: number): Method<{ radius: number; }, number>; /** * Get whether players are forced to use the server's default game mode */ declare function getForceGameMode(): Method<undefined, boolean>; /** * Enable or disable forcing players to use the server's default game mode * @param force whether to force the default game mode */ declare function setForceGameMode(force: boolean): Method<{ force: boolean; }, boolean>; /** * Get the server's default game mode */ declare function getGameMode(): Method<undefined, GameMode>; /** * Set the server's default game mode * @param mode the default game mode */ declare function setGameMode(mode: GameMode): Method<{ mode: GameMode; }, string>; /** * Get the server's view distance in chunks */ declare function getViewDistance(): Method<undefined, number>; /** * Set the server's view distance in chunks * @param distance the view distance in chunks */ declare function setViewDistance(distance: number): Method<{ distance: number; }, string>; /** * Get the server's simulation distance in chunks */ declare function getSimulationDistance(): Method<undefined, number>; /** * Set the server's simulation distance in chunks * @param distance the simulation distance in chunks */ declare function setSimulationDistance(distance: number): Method<{ distance: number; }, string>; /** * Get whether the server accepts player transfers from other servers */ declare function getAcceptTransfers(): Method<undefined, boolean>; /** * Enable or disable accepting player transfers from other servers * @param accept whether to accept player transfers */ declare function setAcceptTransfers(accept: boolean): Method<{ accept: boolean; }, boolean>; /** * Get the interval in seconds between server status heartbeats */ declare function getStatusHeartbeatInterval(): Method<undefined, number>; /** * Set the interval in seconds between server status heartbeats * @param seconds the interval in seconds * @returns whether the operation was successful */ declare function setStatusHeartbeatInterval(seconds: number): Method<{ seconds: number; }, boolean>; /** * Get the permission level required for operator commands */ declare function getOperatorUserPermissionLevel(): Method<undefined, number>; /** * Set the permission level required for operator commands * @param level the permission level */ declare function setOperatorUserPermissionLevel(level: number): Method<{ level: number; }, number>; /** * Get whether the server hides online player information from status queries */ declare function getHideOnlinePlayers(): Method<undefined, boolean>; /** * Enable or disable hiding online player information from status queries * @param hide whether to hide online player information */ declare function setHideOnlinePlayers(hide: boolean): Method<{ hide: boolean; }, boolean>; /** * Get whether the server responds to connection status requests */ declare function getStatusReplies(): Method<undefined, boolean>; /** * Enable or disable the server responding to connection status requests * @param enable whether to enable status replies */ declare function setStatusReplies(enable: boolean): Method<{ enable: boolean; }, boolean>; /** * Get the entity broadcast range as a percentage */ declare function getEntityBroadcastRange(): Method<undefined, number>; /** * Set the entity broadcast range as a percentage * @param range the entity broadcast range as a percentage */ declare function setEntityBroadcastRange(range: number): Method<{ range: number; }, number>; /** * Get the available game rule keys and their current values */ declare function getGameRules(): Method<undefined, TypedGameRule>; /** * Update game rule value * @param gamerule the game rule to update */ declare function setGameRules(gamerule: TypedGameRule): Method<{ gamerule: UntypedGameRule; }, boolean>; declare const index$2_getAcceptTransfers: typeof getAcceptTransfers; declare const index$2_getAllowFlight: typeof getAllowFlight; declare const index$2_getAutosave: typeof getAutosave; declare const index$2_getDifficulty: typeof getDifficulty; declare const index$2_getEnforceAllowlist: typeof getEnforceAllowlist; declare const index$2_getEntityBroadcastRange: typeof getEntityBroadcastRange; declare const index$2_getForceGameMode: typeof getForceGameMode; declare const index$2_getGameMode: typeof getGameMode; declare const index$2_getGameRules: typeof getGameRules; declare const index$2_getHideOnlinePlayers: typeof getHideOnlinePlayers; declare const index$2_getMaxPlayers: typeof getMaxPlayers; declare const index$2_getMotd: typeof getMotd; declare const index$2_getOperatorUserPermissionLevel: typeof getOperatorUserPermissionLevel; declare const index$2_getPauseWhenEmptySeconds: typeof getPauseWhenEmptySeconds; declare const index$2_getPlayerIdleTimeout: typeof getPlayerIdleTimeout; declare const index$2_getSimulationDistance: typeof getSimulationDistance; declare const index$2_getSpawnProtectionRadius: typeof getSpawnProtectionRadius; declare const index$2_getStatusHeartbeatInterval: typeof getStatusHeartbeatInterval; declare const index$2_getStatusReplies: typeof getStatusReplies; declare const index$2_getUseAllowlist: typeof getUseAllowlist; declare const index$2_getViewDistance: typeof getViewDistance; declare const index$2_setAcceptTransfers: typeof setAcceptTransfers; declare const index$2_setAllowFlight: typeof setAllowFlight; declare const index$2_setAutosave: typeof setAutosave; declare const index$2_setDifficulty: typeof setDifficulty; declare const index$2_setEnforceAllowlist: typeof setEnforceAllowlist; declare const index$2_setEntityBroadcastRange: typeof setEntityBroadcastRange; declare const index$2_setForceGameMode: typeof setForceGameMode; declare const index$2_setGameMode: typeof setGameMode; declare const index$2_setGameRules: typeof setGameRules; declare const index$2_setHideOnlinePlayers: typeof setHideOnlinePlayers; declare const index$2_setMaxPlayers: typeof setMaxPlayers; declare const index$2_setMotd: typeof setMotd; declare const index$2_setOperatorUserPermissionLevel: typeof setOperatorUserPermissionLevel; declare const index$2_setPauseWhenEmptySeconds: typeof setPauseWhenEmptySeconds; declare const index$2_setPlayerIdleTimeout: typeof setPlayerIdleTimeout; declare const index$2_setSimulationDistance: typeof setSimulationDistance; declare const index$2_setSpawnProtectionRadius: typeof setSpawnProtectionRadius; declare const index$2_setStatusHeartbeatInterval: typeof setStatusHeartbeatInterval; declare const index$2_setStatusReplies: typeof setStatusReplies; declare const index$2_setUseAllowlist: typeof setUseAllowlist; declare const index$2_setViewDistance: typeof setViewDistance; declare namespace index$2 { export { index$2_getAcceptTransfers as getAcceptTransfers, index$2_getAllowFlight as getAllowFlight, index$2_getAutosave as getAutosave, index$2_getDifficulty as getDifficulty, index$2_getEnforceAllowlist as getEnforceAllowlist, index$2_getEntityBroadcastRange as getEntityBroadcastRange, index$2_getForceGameMode as getForceGameMode, index$2_getGameMode as getGameMode, index$2_getGameRules as getGameRules, index$2_getHideOnlinePlayers as getHideOnlinePlayers, index$2_getMaxPlayers as getMaxPlayers, index$2_getMotd as getMotd, index$2_getOperatorUserPermissionLevel as getOperatorUserPermissionLevel, index$2_getPauseWhenEmptySeconds as getPauseWhenEmptySeconds, index$2_getPlayerIdleTimeout as getPlayerIdleTimeout, index$2_getSimulationDistance as getSimulationDistance, index$2_getSpawnProtectionRadius as getSpawnProtectionRadius, index$2_getStatusHeartbeatInterval as getStatusHeartbeatInterval, index$2_getStatusReplies as getStatusReplies, index$2_getUseAllowlist as getUseAllowlist, index$2_getViewDistance as getViewDistance, index$2_setAcceptTransfers as setAcceptTransfers, index$2_setAllowFlight as setAllowFlight, index$2_setAutosave as setAutosave, index$2_setDifficulty as setDifficulty, index$2_setEnforceAllowlist as setEnforceAllowlist, index$2_setEntityBroadcastRange as setEntityBroadcastRange, index$2_setForceGameMode as setForceGameMode, index$2_setGameMode as setGameMode, index$2_setGameRules as setGameRules, index$2_setHideOnlinePlayers as setHideOnlinePlayers, index$2_setMaxPlayers as setMaxPlayers, index$2_setMotd as setMotd, index$2_setOperatorUserPermissionLevel as setOperatorUserPermissionLevel, index$2_setPauseWhenEmptySeconds as setPauseWhenEmptySeconds, index$2_setPlayerIdleTimeout as setPlayerIdleTimeout, index$2_setSimulationDistance as setSimulationDistance, index$2_setSpawnProtectionRadius as setSpawnProtectionRadius, index$2_setStatusHeartbeatInterval as setStatusHeartbeatInterval, index$2_setStatusReplies as setStatusReplies, index$2_setUseAllowlist as setUseAllowlist, index$2_setViewDistance as setViewDistance }; } /** * 定义方法列表 */ interface IMethod<Params = any, Result = any> { method: string; params?: Params; } declare class Method<Params = any, Result = any> implements IMethod<Params, Result> { method: string; params?: Params; /** * create a method * @param method method name * @param params method parameters */ constructor(method: string, params?: Params); } type index$1_IMethod<Params = any, Result = any> = IMethod<Params, Result>; type index$1_Method<Params = any, Result = any> = Method<Params, Result>; declare const index$1_Method: typeof Method; declare namespace index$1 { export { index$8 as AllowList, index$7 as Bans, type index$1_IMethod as IMethod, index$6 as IpBans, index$1_Method as Method, index$5 as Operators, index$4 as Players, index$3 as Server, index$2 as ServerSettings }; } /** * notification */ /** * Notification */ interface Notification<Name extends string, Params = {}> { name: Name; params: Params; } /** * All notifications. */ type Notifications = Notification<"notification:server/started"> | Notification<"notification:server/stopping"> | Notification<"notification:server/saving"> | Notification<"notification:server/saved"> | Notification<"notification:players/joined", [player: Player]> | Notification<"notification:players/left", [player: Player]> | Notification<"notification:operators/added", [player: Operator]> | Notification<"notification:operators/removed", [player: Operator]> | Notification<"notification:allowlist/added", [player: Player]> | Notification<"notification:allowlist/removed", [player: Player]> | Notification<"notification:ip_bans/added", [player: IpBan]> | Notification<"notification:ip_bans/removed", [player: string]> | Notification<"notification:bans/added", [player: UserBan]> | Notification<"notification:bans/removed", [player: Player]> | Notification<"notification:gamerules/updated", [gamerule: TypedGameRule]> | Notification<"notification:server/status", [status: ServerState]>; /** * Notification parameters for a specific notification type. */ type NotificationParams<T extends Notifications['name']> = Extract<Notifications, { name: T; }>['params']; type index_Notification<Name extends string, Params = {}> = Notification<Name, Params>; type index_NotificationParams<T extends Notifications['name']> = NotificationParams<T>; type index_Notifications = Notifications; declare namespace index { export type { index_Notification as Notification, index_NotificationParams as NotificationParams, index_Notifications as Notifications }; } /** * Notification handler */ type NotificationHandler<T extends Notifications['name']> = (params: NotificationParams<T>) => void; type WSCallbackMap = { open: (ev: Event) => void; close: (ev: CloseEvent) => void; message: (ev: MessageEvent<any>) => void; error: (ev: Event) => void; }; /** * WebSocketClient */ declare class WSClient { private ws; private rpcId; private pending; private handlers; constructor(url: string); on<K extends keyof WSCallbackMap>(event: K, callback: WSCallbackMap[K]): void; off<K extends keyof WSCallbackMap>(event: K, callback: WSCallbackMap[K]): void; call(method: string, params?: any[]): Promise<any>; /** * RPC method call * @param method Method */ callMethod<P, R>(method: Method<P, R>): Promise<R>; /** * Register a notification handler * @param name Notification name * @param handler Notification handler */ onNotification<T extends Notifications['name']>(name: T, handler: NotificationHandler<T>): void; /** * Unregister a notification handler * @param name Notification name * @param handler Notification handler */ offNotification<T extends Notifications['name']>(name: T, handler: NotificationHandler<T>): void; } export { enums as Enums, index$1 as Method, index as Notification, schemas as Schemas, WSClient };