import { API_ENDPOINT } from ".."; import WebRequest from "../common/WebRequest"; import { CachedMinecraftServer } from "../types/cache/cachedMinecraftServer"; import { BlockedStatus } from "../types/server/blockedStatus"; import { ServerPlatform } from "../types/server/platform"; const serverEndpoint = API_ENDPOINT + "/server/{platform}/{hostname}"; const serverIconEndpoint = API_ENDPOINT + "/server/icon/{hostname}"; const blockedServerEndpoint = API_ENDPOINT + "/server/blocked/{hostname}"; /** * Gets information about a Minecraft server. * * @param platform the platform of server * @param hostname the hostname of the server * @param port the port of the server * @returns the server information, or null if the server does not exist */ export function getServer(platform: ServerPlatform, hostname: string, port?: 25565): Promise { const ip = port ? `${hostname}:${port}` : hostname; return WebRequest.get( serverEndpoint.replace("{platform}", platform).replace("{hostname}", ip) ); } /** * Gets the icon of a Java Minecraft server. * * @param hostname the hostname of the server * @param port the port of the server * @returns the server icon, or null if the server does not have an icon */ export function getServerIcon(hostname: string, port?: 25565): Promise { const ip = port ? `${hostname}:${port}` : hostname; return WebRequest.get(serverIconEndpoint.replace("{hostname}", ip)); } /** * Gets the Mojang blocked status of a Minecraft server. * * @param hostname the hostname of the server * @returns true if the server is blocked, false otherwise */ export function getBlockedStatus(hostname: string): Promise { return WebRequest.get(blockedServerEndpoint.replace("{hostname}", hostname)); }