UNPKG

mc-server-management

Version:

A library for the Minecraft server management protocol added in 25w35a

1,034 lines (1,033 loc) 38.4 kB
import { EventEmitter } from "eventemitter3"; import { Client, IWSClientAdditionalOptions } from "rpc-websockets"; import { ClientOptions } from "ws"; //#region src/schemas/server/Difficulty.d.ts declare enum Difficulty { PEACEFUL = "peaceful", EASY = "easy", NORMAL = "normal", HARD = "hard", } //#endregion //#region src/schemas/server/GameMode.d.ts declare enum GameMode { SURVIVAL = "survival", CREATIVE = "creative", SPECTATOR = "spectator", ADVENTURE = "adventure", } //#endregion //#region src/server/ServerSettings.d.ts /** * An API wrapper for the settings of the Minecraft server. */ declare class ServerSettings { #private; /** * Get whether the server automatically saves the world periodically. * @returns {Promise<boolean>} True if the server automatically saves the world, false otherwise. */ getAutoSave(): Promise<boolean>; /** * Set whether the server automatically saves the world periodically. * @param value True to enable auto-saving, false to disable it. */ setAutoSave(value: boolean): Promise<void>; /** * Get the current difficulty level of the server. * @returns {Promise<Difficulty>} The current difficulty level. */ getDifficulty(): Promise<Difficulty>; /** * Set the difficulty level of the server. * @param value The difficulty level to set. */ setDifficulty(value: Difficulty): Promise<void>; /** * Get whether the server immediately kicks players when they are removed from the allowlist. * @returns {Promise<boolean>} If true, players are kicked when removed from the allowlist. */ getEnforceAllowList(): Promise<boolean>; /** * Set whether the server immediately kicks players when they are removed from the allowlist. * @param value True to enable enforcement, false to disable it. */ setEnforceAllowList(value: boolean): Promise<void>; /** * Get whether the server uses the allow list. * @returns {Promise<boolean>} True if the server uses the allow list, false otherwise. */ getUseAllowList(): Promise<boolean>; /** * Set whether the server uses the allow list. * @param value True to enable the allow list, false to disable it. */ setUseAllowList(value: boolean): Promise<void>; /** * Get the maximum number of players that can join the server. * @returns {Promise<number>} The maximum number of players. */ getMaxPlayers(): Promise<number>; /** * Set the maximum number of players that can join the server. * @param value The maximum number of players. */ setMaxPlayers(value: number): Promise<void>; /** * Get the number of seconds the server waits before pausing when no players are online. * A non-positive value means the server never pauses. * @returns {Promise<number>} The number of seconds before pausing when empty. */ getPauseWhenEmptySeconds(): Promise<number>; /** * Set the number of seconds the server waits before pausing when no players are online. * A non-positive value means the server never pauses. * @param value The number of seconds before pausing when empty. */ setPauseWhenEmptySeconds(value: number): Promise<void>; /** * Get the number of minutes a player can be idle before being kicked. * Value 0 means players are never kicked for idling. * @returns {Promise<number>} The number of minutes before kicking idle players. */ getPlayerIdleTimeout(): Promise<number>; /** * Set the number of minutes a player can be idle before being kicked. * Value 0 means players are never kicked for idling. * @param value The number of minutes before kicking idle players. */ setPlayerIdleTimeout(value: number): Promise<void>; /** * Get whether players are allowed to fly on the server. This only changes the flight detection, it does not * enable flight for players in survival mode without a hacked client. * @returns {Promise<boolean>} True if players are allowed to fly, false otherwise. */ getAllowFlight(): Promise<boolean>; /** * Set whether players are allowed to fly on the server. This only changes the flight detection, it does not * enable flight for players in survival mode without a hacked client. * @param value True to allow flying, false to disable it. */ setAllowFlight(value: boolean): Promise<void>; /** * Get the message of the day (MOTD) of the server. * @returns {Promise<string>} The MOTD of the server. */ getMOTD(): Promise<string>; /** * Set the message of the day (MOTD) of the server. * @param value The MOTD to set. */ setMOTD(value: string): Promise<void>; /** * Get the radius around the world spawn point that is protected from non-operator players. * @returns {Promise<number>} The spawn protection radius. */ getSpawnProtectionRadius(): Promise<number>; /** * Set the radius around the world spawn point that is protected from non-operator players. * @param value The spawn protection radius. */ setSpawnProtectionRadius(value: number): Promise<void>; /** * Get whether players are forced to use the server's game mode when they join. * @returns {Promise<boolean>} True if players are forced to use the server's game mode, false otherwise. */ getForceGameMode(): Promise<boolean>; /** * Set whether players are forced to use the server's game mode when they join. * @param value True to force the server's game mode, false to allow players to use their own. */ setForceGameMode(value: boolean): Promise<void>; /** * Get the default game mode for players when they join the server for the first time. If force game mode is * enabled the game mode will be applied to all players when they join, not just new ones. * @returns {Promise<GameMode>} The default game mode. */ getGameMode(): Promise<GameMode>; /** * Set the default game mode for players when they join the server for the first time. If force game mode is * enabled the game mode will be applied to all players when they join, not just new ones. * @param value The default game mode. */ setGameMode(value: GameMode): Promise<void>; /** * Get the view distance of the server, in chunks. * This is the distance in chunks that the server sends to players around them. * @returns {Promise<number>} The view distance in chunks. */ getViewDistance(): Promise<number>; /** * Set the view distance of the server, in chunks. * This is the distance in chunks that the server sends to players around them. * @param value The view distance in chunks. */ setViewDistance(value: number): Promise<void>; /** * Get the simulation distance of the server, in chunks. * This is the distance in chunks that the server simulates around each player. * @returns {Promise<number>} The simulation distance in chunks. */ getSimulationDistance(): Promise<number>; /** * Set the simulation distance of the server, in chunks. * This is the distance in chunks that the server simulates around each player. * @param value The simulation distance in chunks. */ setSimulationDistance(value: number): Promise<void>; /** * Get whether the server accepts players transferred from other servers. * @returns {Promise<boolean>} True if the server accepts transferred players, false otherwise. */ getAcceptTransfers(): Promise<boolean>; /** * Set whether the server accepts players transferred from other servers. * @param value True to accept transferred players, false to reject them. */ setAcceptTransfers(value: boolean): Promise<void>; /** * Get the interval in seconds between status heartbeats sent to server management clients. * A value of 0 means no heartbeats are sent. * @returns {Promise<number>} The status heartbeat interval in seconds. */ getStatusHeartbeatInterval(): Promise<number>; /** * Set the interval in seconds between status heartbeats sent to server management clients. * A value of 0 means no heartbeats are sent. * @param value The status heartbeat interval in seconds. */ setStatusHeartbeatInterval(value: number): Promise<void>; /** * Get the permission level granted to new operators. * Levels are from 1 to 4, with 4 being the highest. * @returns {Promise<number>} The operator user permission level. */ getOperatorUserPermissionLevel(): Promise<number>; /** * Set the permission level granted to new operators. * Levels are from 1 to 4, with 4 being the highest. * @param value The operator user permission level. */ setOperatorUserPermissionLevel(value: number): Promise<void>; /** * Get whether the server hides the list of online players from the server list. * @returns {Promise<boolean>} True if the server hides the list of online players, false otherwise. */ getHideOnlinePlayers(): Promise<boolean>; /** * Set whether the server hides the list of online players from the server list. * @param value True to hide the list of online players, false to show it. */ setHideOnlinePlayers(value: boolean): Promise<void>; /** * Get whether the server responds to status requests in the multiplayer server list. * @returns {Promise<boolean>} True if the server responds to status requests, false otherwise. */ getStatusReplies(): Promise<boolean>; /** * Set whether the server responds to status requests in the multiplayer server list. * @param value True to respond to status requests, false to ignore them. */ setStatusReplies(value: boolean): Promise<void>; /** * Get the range in chunks around each player in which entities are updated to the player. This is a percentage * value (100 => 100%) of the default value. Min: 10%, Max: 1000% * @returns {Promise<number>} The entity broadcast range percentage. */ getEntityBroadcastRange(): Promise<number>; /** * Set the range in chunks around each player in which entities are updated to the player. This is a percentage * value (100 => 100%) of the default value. Min: 10%, Max: 1000% * @param value The entity broadcast range percentage. */ setEntityBroadcastRange(value: number): Promise<void>; } //#endregion //#region src/server/Notifications.d.ts declare enum Notifications { SERVER_STARTED = "minecraft:notification/server/started", SERVER_STOPPING = "minecraft:notification/server/stopping", SERVER_SAVING = "minecraft:notification/server/saving", SERVER_SAVED = "minecraft:notification/server/saved", PLAYER_JOINED = "minecraft:notification/players/joined", PLAYER_LEFT = "minecraft:notification/players/left", OPERATOR_ADDED = "minecraft:notification/operators/added", OPERATOR_REMOVED = "minecraft:notification/operators/removed", ALLOWLIST_ADDED = "minecraft:notification/allowlist/added", ALLOWLIST_REMOVED = "minecraft:notification/allowlist/removed", IP_BAN_ADDED = "minecraft:notification/ip_bans/added", IP_BAN_REMOVED = "minecraft:notification/ip_bans/removed", BAN_ADDED = "minecraft:notification/bans/added", BAN_REMOVED = "minecraft:notification/bans/removed", GAME_RULE_UPDATED = "minecraft:notification/gamerules/updated", SERVER_STATUS = "minecraft:notification/server/status", } //#endregion //#region src/connection/ConnectionEventData.d.ts type ConnectionEventData = { 'open': []; 'close': [number, string]; 'error': [Error]; [Notifications.SERVER_STARTED]: unknown; [Notifications.SERVER_STOPPING]: unknown; [Notifications.SERVER_SAVING]: unknown; [Notifications.SERVER_SAVED]: unknown; [Notifications.PLAYER_JOINED]: unknown; [Notifications.PLAYER_LEFT]: unknown; [Notifications.OPERATOR_ADDED]: unknown; [Notifications.OPERATOR_REMOVED]: unknown; [Notifications.ALLOWLIST_ADDED]: unknown; [Notifications.ALLOWLIST_REMOVED]: unknown; [Notifications.IP_BAN_ADDED]: unknown; [Notifications.IP_BAN_REMOVED]: unknown; [Notifications.BAN_ADDED]: unknown; [Notifications.BAN_REMOVED]: unknown; [Notifications.GAME_RULE_UPDATED]: unknown; [Notifications.SERVER_STATUS]: unknown; }; //#endregion //#region src/connection/Connection.d.ts /** * Library independent connection interface. * Can be used to proxy calls to different libraries or through intermediate APIs. */ declare abstract class Connection extends EventEmitter<ConnectionEventData> { /** * Call a method on the server with the given parameters. * @param method The method name to call. * @param parameters The parameters to pass to the method. * @returns A promise that resolves to the result of the method call. */ protected abstract callRaw(method: string, parameters: object | Array<unknown>): Promise<unknown>; /** * Call a method on the server with the given parameters. If an error occurs, it throws an error. * @param method The method name to call. * @param parameters The parameters to pass to the method. * @returns A promise that resolves to the result of the method call. * @throws JsonRPCError if the server returns an error. */ call(method: string, parameters: object | Array<unknown>): Promise<unknown>; /** * Close the connection. */ abstract close(): void; } //#endregion //#region src/schemas/player/Player.d.ts /** * A player object or a player's username. */ type PlayerInput = string | Player; declare class Player { /** * Unique identifier of the player (UUID format). */ id?: string; /** * Username of the player. */ name?: string; /** * Creates a Player instance with the specified UUID. * @param id */ static withId(id: string): Player; /** * Creates a Player instance with the specified username. * @param name */ static withName(name: string): Player; /** * Sets the unique identifier of the player. * @param id */ setId(id?: string): this; /** * Sets the username of the player. * @param name */ setName(name?: string): this; } //#endregion //#region src/player-list/PlayerList.d.ts declare abstract class PlayerList<ItemType> { #private; /** * Get the items on the list. If the list is already fetched and force is false, the cached list is returned. * @param force Always request the list from the server, even if it was already fetched. */ get(force?: boolean): Promise<ItemType[]>; /** * Clear the list. * This method updates the cached with the resulting list from the server. Use `get()` to retrieve it. */ clear(): Promise<this>; /** * Call a method on the player list and return the raw response. * @param action Method to call (e.g., 'set', 'add', 'remove', 'clear'). * @param params Parameters to pass to the method. * @returns This PlayerList instance. * @protected */ protected call(action?: string, params?: unknown[]): Promise<unknown>; /** * Call a method on the player list. Updates the cached list with the resulting list from the server and returns this. * @param action Method to call (e.g., 'set', 'add', 'remove', 'clear'). * @param params Parameters to pass to the method. * @returns This PlayerList instance. * @protected */ protected callAndParse(action?: string, params?: unknown[]): Promise<this>; /** * Get the name of the player list for use in API calls. * E.g., 'minecraft:allowlist' or 'minecraft:ip_bans'. * @protected */ protected abstract getName(): string; /** * Parse the result from the server. * @param result * @protected */ protected abstract parseResult(result: unknown[]): ItemType[]; } //#endregion //#region src/util.d.ts type ItemOrArray<T> = T | T[]; //#endregion //#region src/player-list/AllowList.d.ts declare class AllowList extends PlayerList<Player> { /** * Overwrite the existing allowlist with a set of players. * This method updates the cached with the resulting list from the server. Use `get()` to retrieve it. * @param items list of strings (player names) or Player objects */ set(items: PlayerInput[]): Promise<this>; /** * Add players to the allowlist. * This method updates the cached with the resulting list from the server. Use `get()` to retrieve it. * @param items list of strings (player names) or Player objects */ add(items: ItemOrArray<PlayerInput>): Promise<this>; /** * Remove players from the allowlist. * This method updates the cached with the resulting list from the server. Use `get()` to retrieve it. * @param items list of strings (player names) or Player objects */ remove(items: ItemOrArray<PlayerInput>): Promise<this>; protected getName(): string; protected parseResult(result: unknown[]): Player[]; } //#endregion //#region src/schemas/player/ban/Ban.d.ts type BanExpiryInput = Date | string | null; /** * Base class for all ban related classes. */ declare class Ban { /** * Reason for the ban. */ reason: string | null; /** * Source of the ban (effectively a comment field). */ source: string | null; /** * Expiration date of the ban in ISO 8601 format. If omitted, the ban is permanent. * Use {@link setExpires} to set this field using a Date or bigint. */ expires: string | null; /** * @param reason reason for the ban * @param source source of the ban * @param expires expiration date of the ban as a Date or string in ISO 8601 format. If omitted, the ban is permanent. */ constructor(reason?: string | null, source?: string | null, expires?: BanExpiryInput); /** * Sets the reason for the ban. * @param reason */ setReason(reason?: string | null): this; /** * Sets the source of the ban. * @param source */ setSource(source?: string | null): this; /** * Sets the expiration date of the ban. * @param expires The expiration date as a Date or string in ISO 8601 format. */ setExpires(expires: BanExpiryInput): this; /** * Gets the expiration date of the ban as a Date object. * @returns The expiration date as a Date object, or null if the ban is permanent or the date is invalid. */ getExpiresAsDate(): Date | null; } //#endregion //#region src/schemas/player/ban/IncomingIPBan.d.ts /** * A IncomingIPBan object or an IP address or a connected Player. */ type IncomingIPBanInput = IncomingIPBan | string | Player; /** * Request to ban a player by their IP address. */ declare class IncomingIPBan extends Ban { /** * IP address to ban. */ ip: string | null; /** * Connected player who should be banned by their IP address. */ player: Player | null; /** * Creates a new IncomingIPBan instance with the specified IP address. * @param ip */ static withIp(ip: string): IncomingIPBan; /** * Creates a new IncomingIPBan instance for the specified player. * If the player is not currently connected to the server, they can't be banned by their IP address. * @param player */ static withConnectedPlayer(player: Player): IncomingIPBan; /** * Sets the IP address to ban. * @param ip */ setIp(ip?: string | null): this; /** * Sets the connected player who should be banned by their IP address. * @param player */ setPlayer(player?: Player | null): this; } //#endregion //#region src/schemas/player/ban/IPBan.d.ts type IPBanInput = IPBan | string; /** * Entry on the IP ban list */ declare class IPBan extends Ban { /** * Banned ip address. */ ip: string; /** * @param ip banned IP address * @param reason reason for the ban * @param source source of the ban * @param expires expiration date of the ban as a Date or string in ISO 8601 format. If omitted, the ban is permanent. */ constructor(ip: string, reason?: string | null, source?: string | null, expires?: BanExpiryInput); /** * Sets the banned IP address. * @param ip */ setIp(ip: string): this; } //#endregion //#region src/player-list/IPBanList.d.ts declare class IPBanList extends PlayerList<IPBan> { /** * Overwrite the existing list with a set of entries. * This method updates the cached with the resulting list from the server. Use `get()` to retrieve it. * @param items * @param reason Default reason if input is not an IPBan * @param source Default source if input is not an IPBan * @param expires Default expiry if input is not an IPBan */ set(items: IPBanInput[], reason?: string | null, source?: string | null, expires?: BanExpiryInput): Promise<this>; /** * Ban IP addresses. * This method updates the cached with the resulting list from the server. Use `get()` to retrieve it. * @param items list of ip addresses as strings, IncomingIPBan objects or Player objects of connected players * @param reason Default reason if input is not an IncomingIPBan * @param source Default source if input is not an IncomingIPBan * @param expires Default expiry if input is not an IncomingIPBan */ add(items: ItemOrArray<IncomingIPBanInput>, reason?: string | null, source?: string | null, expires?: BanExpiryInput): Promise<this>; /** * Unban IP addresses. * This method updates the cached with the resulting list from the server. Use `get()` to retrieve it. * @param ips list of IP addresses as strings */ remove(ips: ItemOrArray<string>): Promise<this>; protected getName(): string; protected parseResult(result: unknown[]): IPBan[]; } //#endregion //#region src/schemas/player/ban/UserBan.d.ts /** * Input type for UserBan. Can be either a UserBan instance or a PlayerInput. */ type UserBanInput = UserBan | PlayerInput; declare class UserBan extends Ban { /** * Player who should be banned. */ player: Player; /** * @param player the player to ban * @param reason reason for the ban * @param source source of the ban * @param expires expiration date of the ban as a Date or string in ISO 8601 format. If omitted, the ban is permanent. */ constructor(player: PlayerInput, reason?: string | null, source?: string | null, expires?: BanExpiryInput); /** * Sets the player to ban. * @param player */ setPlayer(player: Player): this; } //#endregion //#region src/player-list/BanList.d.ts declare class BanList extends PlayerList<UserBan> { /** * Overwrite the existing list with a set of entries. * This method updates the cached with the resulting list from the server. Use `get()` to retrieve it. * @param items list of strings (player names), Player objects or UserBan objects * @param reason Default reason if input is not a UserBan * @param source Default source if input is not a UserBan * @param expires Default expiry if input is not a UserBan */ set(items: UserBanInput[], reason?: string | null, source?: string | null, expires?: BanExpiryInput): Promise<this>; /** * Add items to the list. * This method updates the cached with the resulting list from the server. Use `get()` to retrieve it. * @param items list of strings (player names), Player objects or UserBan objects * @param reason Default reason if input is not a UserBan * @param source Default source if input is not a UserBan * @param expires Default expiry if input is not a UserBan */ add(items: ItemOrArray<UserBanInput>, reason?: string | null, source?: string | null, expires?: BanExpiryInput): Promise<this>; /** * Remove items from the list. * This method updates the cached with the resulting list from the server. Use `get()` to retrieve it. * @param items list of strings (player names) or Player objects */ remove(items: ItemOrArray<PlayerInput>): Promise<this>; protected getName(): string; protected parseResult(result: unknown[]): UserBan[]; /** * Convert input list or item to UserBan instances. * @param inputs input list or item * @param reason Default reason if input is not a UserBan * @param source Default source if input is not a UserBan * @param expires Default expiry if input is not a UserBan * @protected */ protected fromInputs(inputs: ItemOrArray<UserBanInput>, reason: string | null, source: string | null, expires: BanExpiryInput): UserBan[]; } //#endregion //#region src/schemas/message/Message.d.ts type MessageInput = Message | string; declare class Message { /** * Literal message to send (non-translatable). */ literal?: string; /** * Translatable message key (e.g. "chat.type.text") */ translatable?: string; /** * Parameters for the translated message (if any). */ translatableParams?: Array<string>; /** * Create a literal message. * @param literal */ static literal(literal: string): Message; /** * Create a translatable message with optional parameters. * @param translatable translatable message key * @param translatableParams optional parameters for the translated message */ static translatable(translatable: string, translatableParams?: Array<string>): Message; /** * Sets the literal message. * @param literal */ setLiteral(literal?: string): this; /** * Set the translatable message key. * @param translatable */ setTranslatable(translatable?: string): this; /** * Add parameters for the translated message. * @param params one or more parameters to add */ addTranslatableParam(params: string | string[]): this; /** * Set the parameters for the translated message. * @param translatableParams */ setTranslatableParams(translatableParams?: Array<string>): this; } //#endregion //#region src/schemas/player/KickPlayer.d.ts /** * Request to kick a player */ declare class KickPlayer { /** * Players to kick. */ player: Player; /** * Message displayed to the player when they are kicked. */ message?: Message; /** * @param player players to kick * @param message message displayed to the player when they are kicked */ constructor(player: Player, message?: Message); } //#endregion //#region src/schemas/player/Operator.d.ts /** * Input type for Operator. Can be either an Operator instance or a PlayerInput. */ type OperatorInput = Operator | PlayerInput; declare class Operator { /** * The player who is being made an operator. */ player: Player; /** * Which permissions level the operator has. */ permissionLevel?: number; /** * Whether the operator bypasses the player limit. */ bypassesPlayerLimit?: boolean; /** * @param player The player who is being made an operator. * @param permissionLevel Which permissions level the operator has. * @param bypassesPlayerLimit Whether the operator bypasses the player limit. */ constructor(player: PlayerInput, permissionLevel?: number, bypassesPlayerLimit?: boolean); /** * Sets the player who is being made an operator. * @param player */ setPlayer(player: Player): this; /** * Sets which permissions level the operator has. * @param permissionLevel */ setPermissionLevel(permissionLevel?: number): this; /** * Sets whether the operator bypasses the player limit. * @param bypassesPlayerLimit */ setBypassesPlayerLimit(bypassesPlayerLimit?: boolean): this; } //#endregion //#region src/player-list/OperatorList.d.ts declare class OperatorList extends PlayerList<Operator> { /** * Overwrite the existing operator list with a set of operators. * This method updates the cached with the resulting list from the server. Use `get()` to retrieve it. * @param items list of strings (player names), Player objects or Operator objects * @param permissionLevel Default permission level if the item is not an Operator object * @param bypassesPlayerLimit Default bypassesPlayerLimit if the item is not an Operator object */ set(items: OperatorInput[], permissionLevel?: number, bypassesPlayerLimit?: boolean): Promise<this>; /** * Add players to the operator list. * This method updates the cached with the resulting list from the server. Use `get()` to retrieve it. * @param items list of strings (player names), Player objects or Operator objects * @param permissionLevel Default permission level if the item is not an Operator object * @param bypassesPlayerLimit Default bypassesPlayerLimit if the item is not an Operator object */ add(items: ItemOrArray<OperatorInput>, permissionLevel?: number, bypassesPlayerLimit?: boolean): Promise<this>; /** * Remove players from the operator list. * This method updates the cached with the resulting list from the server. Use `get()` to retrieve it. * @param items list of strings (player names) or Player objects */ remove(items: ItemOrArray<PlayerInput>): Promise<this>; protected getName(): string; protected fromInputs(inputs: ItemOrArray<OperatorInput>, permissionLevel: number | undefined, bypassesPlayerLimit: boolean | undefined): Operator[]; protected parseResult(result: unknown[]): Operator[]; } //#endregion //#region src/schemas/gamerule/GameRuleType.d.ts declare enum GameRuleType { BOOLEAN = "boolean", INTEGER = "integer", } //#endregion //#region src/schemas/gamerule/GameRule.d.ts declare class GameRule<T> { /** * Key of the game rule (e.g., "doDaylightCycle", "maxEntityCramming"). */ key: string; /** * Value of the game rule. */ value: T; constructor(key: string, value: T); } //#endregion //#region src/schemas/gamerule/TypedGameRule.d.ts type GameRuleValue<T extends GameRuleType> = T extends GameRuleType.BOOLEAN ? boolean : number; declare class TypedGameRule<T extends GameRuleType> extends GameRule<GameRuleValue<T>> { /** * Type of the game rule. * @see GameRuleType */ type: T; /** * @param type Type of the game rule. * @param key Key of the game rule (e.g., "doDaylightCycle", "maxEntityCramming"). * @param value Value of the game rule. Must match the type of the game rule. */ constructor(type: T, key: string, value: GameRuleValue<T>); } //#endregion //#region src/schemas/server/Version.d.ts declare class Version { /** * Name of the version (e.g., "1.21.9") */ readonly name: string; /** * Protocol number of the version (e.g., 773 for Minecraft 1.21.9) */ readonly protocol: number; constructor(name: string, protocol: number); } //#endregion //#region src/schemas/server/ServerState.d.ts declare class ServerState { /** * List of players that are currently connected to the server. */ readonly players: Array<Player>; /** * Whether the server is fully started. */ readonly started: boolean; /** * Version of the server */ readonly version: Version; constructor(players: Array<Player>, started: boolean, version: Version); } //#endregion //#region src/server/EventData.d.ts type EventData = { 'error': [Error]; [Notifications.SERVER_STARTED]: []; [Notifications.SERVER_STOPPING]: []; [Notifications.SERVER_SAVING]: []; [Notifications.SERVER_SAVED]: []; [Notifications.PLAYER_JOINED]: [Player]; [Notifications.PLAYER_LEFT]: [Player]; [Notifications.OPERATOR_ADDED]: [Operator]; [Notifications.OPERATOR_REMOVED]: [Operator]; [Notifications.ALLOWLIST_ADDED]: [Player]; [Notifications.ALLOWLIST_REMOVED]: [Player]; [Notifications.IP_BAN_ADDED]: [IPBan]; [Notifications.IP_BAN_REMOVED]: [string]; [Notifications.BAN_ADDED]: [UserBan]; [Notifications.BAN_REMOVED]: [Player]; [Notifications.GAME_RULE_UPDATED]: [TypedGameRule<GameRuleType>]; [Notifications.SERVER_STATUS]: [ServerState]; }; //#endregion //#region src/server/MinecraftServer.d.ts /** * This is the main entrypoint for interacting with the Minecraft server management protocol. * It provides methods for retrieving server status, managing players, and accessing various server settings and lists. */ declare class MinecraftServer extends EventEmitter<EventData> { #private; /** * This is the main entrypoint for interacting with the server management protocol. * You probably want to use {@link WebSocketConnection.connect} to create a connection. * @param connection The connection to use for communicating with the server. */ constructor(connection: Connection); /** * Get the current status of the server. * @returns {Promise<ServerState>} The current status of the server. */ getStatus(force?: boolean): Promise<ServerState>; /** * @returns {Promise<Player[]>} Array of players currently connected to the server. */ getConnectedPlayers(force?: boolean): Promise<Player[]>; /** * Kicks one or more players from the server. To specify individual kick messages per user, use the KickPlayer class. * @param player The player or players to kick. Can be a PlayerInput, KickPlayer, or an array of either. * @param message optional default message when player is not an instance of KickPlayer. * @returns {Promise<Player[]>} A promise that resolves to an array of kicked players. */ kickPlayers(player: ItemOrArray<PlayerInput | KickPlayer>, message?: MessageInput | null): Promise<Player[]>; /** * Save the server state to disk. * @param flush Save chunks to disk immediately. * @returns {Promise<boolean>} True if any level was saved. */ save(flush?: boolean): Promise<void>; /** * Stop the server. * @returns {Promise<boolean>} Always true. */ stop(): Promise<boolean>; /** * Sends a system message to the server. * @param message The message content to send. * @param players An optional list of players to receive the message. If omitted, all players will receive the message. * @param overlay Whether to display the message as an overlay above the hotbar (true) or in the chat (false). Default is false. * @returns {Promise<boolean>} A promise that resolves to true if the message was sent successfully, false otherwise. */ sendSystemMessage(message: MessageInput, players?: ItemOrArray<PlayerInput> | null, overlay?: boolean): Promise<boolean>; /** * Get the current game rules of the server. * @param force Whether to force a refresh of the game rules from the server. * @returns {Promise<Map<string, TypedGameRule<GameRuleType>>>} A map of game rule keys to their corresponding game rule objects. */ getGameRules(force?: boolean): Promise<Map<string, TypedGameRule<GameRuleType>>>; /** * Update a game rule on the server. * @param key The key of the game rule to update. * @param value The new value for the game rule. Must be a string, boolean or number. * @returns {Promise<void>} A promise that resolves when the game rule has been updated. */ updateGameRule(key: string, value: number | boolean | string): Promise<TypedGameRule<GameRuleType>>; /** * @returns {PlayerList} API wrapper for the server's allowlist */ allowlist(): AllowList; /** * @returns {IPBanList} API wrapper for the server's IP ban list */ ipBanList(): IPBanList; /** * @returns {IPBanList} API wrapper for the server's player ban list */ banList(): BanList; /** * @returns {OperatorList} API wrapper for the server's operator list */ operatorList(): OperatorList; /** * @returns {ServerSettings} API wrapper for the server's settings */ settings(): ServerSettings; } //#endregion //#region src/connection/WebSocketConnection.d.ts declare class WebSocketConnection extends Connection { readonly client: Client; /** * Connect to a WebSocket server and return a WebSocketConnection instance. * @param url The WebSocket server URL. * @param token authorization token for the WebSocket connection. * @param options Additional options for the WebSocket client. */ static connect(url: string, token: string, options?: IWSClientAdditionalOptions & ClientOptions): Promise<WebSocketConnection>; /** * Manually create a WebSocket connection. Use {@link WebSocketConnection.connect} instead. * @param client */ constructor(client: Client); callRaw(method: string, parameters: object | Array<unknown>): Promise<unknown>; close(): void; } //#endregion //#region src/error/InvalidResponseError.d.ts declare abstract class InvalidResponseError extends Error { /** * The full response received from the server. */ readonly response: unknown; /** * The path in the response that was invalid. */ readonly path: string[]; protected constructor(message: string, response: unknown, path: string[]); } //#endregion //#region src/error/IncorrectTypeError.d.ts declare class IncorrectTypeError extends InvalidResponseError { /** * The expected type of the response. */ readonly expectedType: string; /** * The actual type of the response. */ readonly foundType: string; } //#endregion //#region src/error/JsonRPCError.d.ts /** * Enum of standard JSON-RPC error codes. * @see https://www.jsonrpc.org/specification#error_object */ declare enum JsonRPCErrorCode { /** * Invalid JSON was received by the server. * An error occurred on the server while parsing the JSON text. */ PARSE_ERROR = -32700, /** * The JSON sent is not a valid Request object. */ INVALID_REQUEST = -32600, /** * The method does not exist / is not available. */ METHOD_NOT_FOUND = -32601, /** * Invalid method parameter(s). */ INVALID_PARAMS = -32602, /** * Internal JSON-RPC error. */ INTERNAL_ERROR = -32603, /** * Server error - Reserved for implementation-defined server-errors. * Error codes from and including -32099 to -32000 are reserved for server errors. */ SERVER_ERROR_START = -32099, SERVER_ERROR_END = -32000, } declare class JsonRPCError extends Error { /** * JSON-RPC error code. * @see JsonRPCErrorCode */ readonly code: number; /** * Additional error data, if any. */ readonly data?: unknown; constructor(code: number, message: string, data?: unknown); } //#endregion //#region src/error/MissingPropertyError.d.ts declare class MissingPropertyError extends InvalidResponseError { /** * Name of the missing property. */ readonly property: string; } //#endregion export { AllowList, BanList, Connection, Difficulty, type EventData, GameMode, GameRuleType, IPBan, IPBanList, IncomingIPBan, IncorrectTypeError, InvalidResponseError, JsonRPCError, JsonRPCErrorCode, Message, MinecraftServer, MissingPropertyError, Notifications, Operator, OperatorList, Player, PlayerList, ServerSettings, ServerState, TypedGameRule, UserBan, Version, WebSocketConnection }; //# sourceMappingURL=index.d.mts.map