UNPKG

@threadmc/minecraft-api

Version:

An advanced Minecraft API client for interacting with piston-meta, minecraft servers, and more

132 lines 5.4 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { Rest, fetchVersionManifest, fetchVersionDetails } from "./rest.js"; import { VersionType } from "./enums/VersionType.js"; import { Server } from "./server.js"; /** * Main API client for interacting with Minecraft version data, Mojang APIs, and Minecraft servers. * Provides high-level methods for fetching version info, server status, user profiles, and more. */ export class Client { /** * Create a new Client instance. */ constructor() { this.rest = new Rest(); this.server = new Server(); } /** * Fetch detailed information about a specific Minecraft version. * @param version The version ID (e.g., "1.20.4"). * @returns The version details as returned by the manifest. */ fetchVersion(version) { return __awaiter(this, void 0, void 0, function* () { return yield this.rest.fetchVersion(version); }); } /** * Fetch all Minecraft versions of a given type (release or snapshot). * @param type The version type (VersionType.RELEASE or VersionType.SNAPSHOT). * @returns An array of versions matching the type. */ fetchVersions(type) { return __awaiter(this, void 0, void 0, function* () { return yield this.rest.fetchVersions(type); }); } /** * Fetch the latest Minecraft version of a given type. * @param type The version type (VersionType.RELEASE or VersionType.SNAPSHOT). * @returns The latest version object. */ fetchLatestVersion(type) { return __awaiter(this, void 0, void 0, function* () { return yield this.rest.fetchLatestVersion(type); }); } /** * Get the status of a Minecraft server using the server list ping protocol. * @param host The server hostname or IP. * @param port The server port (default 25565). * @returns The server status response. */ getServerStatus(host_1) { return __awaiter(this, arguments, void 0, function* (host, port = 25565) { return yield this.server.getStatus(host, port); }); } /** * Ping a Minecraft server and return the latency in milliseconds. * @param host The server hostname or IP. * @param port The server port (default 25565). * @returns The latency in ms. */ pingServer(host_1) { return __awaiter(this, arguments, void 0, function* (host, port = 25565) { return yield this.server.ping(host, port); }); } /** * Fetch the asset index for a specific Minecraft version. * @param version The version ID. * @returns The asset index JSON. */ fetchAssetIndex(version) { return __awaiter(this, void 0, void 0, function* () { return yield this.rest.fetchAssetIndex(version); }); } /** * Download a Minecraft library JAR file as an ArrayBuffer. * @param libraryPath The path to the library (e.g., "com/mojang/brigadier/1.0.18/brigadier-1.0.18.jar"). * @returns The library file as an ArrayBuffer. */ fetchLibrary(libraryPath) { return __awaiter(this, void 0, void 0, function* () { return yield this.rest.fetchLibrary(libraryPath); }); } /** * Fetch a Mojang user profile by username. * @param username The Minecraft username. * @returns The user profile JSON. */ fetchUserProfile(username) { return __awaiter(this, void 0, void 0, function* () { return yield this.rest.fetchUserProfile(username); }); } /** * Fetch the name history for a given UUID. * @deprecated This endpoint has been removed on the 13th September 2022. * For more information, see: https://shorturl.at/31VrF * @param uuid The user's UUID (with or without dashes). * @returns The name history array. */ fetchNameHistory(uuid) { return __awaiter(this, void 0, void 0, function* () { // return await this.rest.fetchNameHistory(uuid); return Promise.reject(new Error("This endpoint has been removed on the 13th September 2022. For more information, see: https://shorturl.at/31VrF")); }); } /** * Fetch the skin and/or cape textures for a user by UUID. * @param uuid The user's UUID (with or without dashes). * @returns The textures object containing skin/cape URLs, or null if not found. */ fetchUserTextures(uuid) { return __awaiter(this, void 0, void 0, function* () { return yield this.rest.fetchUserTextures(uuid); }); } } export { VersionType, fetchVersionManifest, fetchVersionDetails, }; //# sourceMappingURL=client.js.map