import { WebRequest } from "@/lib/web-request"; import { MojangServerStatusResponse } from "@/types/mojang/server-status-response"; import { CachedPlayer } from "@/types/player/player"; import { SkinPart } from "@/types/player/skin-part"; import { CachedBedrockMinecraftServer } from "@/types/server/bedrock/server"; import { CachedJavaMinecraftServer } from "@/types/server/java-server"; import { ServerPlatform } from "@/types/server/platform"; /** * Get a player by their username or UUID. * * @param query the query to search for the player by * @returns the promised player */ export const getPlayer = (query: string): Promise => new WebRequest(`/player/${query}`).execute(); /** * Get the part of a skin texture for * a player by their username or UUID. * * @param part the part of the player's skin to get * @param query the query to search for the player by * @param extension the skin part image extension * @param size the size of the skin part image * @returns the promised skin part texture */ export const getSkinPart = ( part: SkinPart, query: string, extension: "png" | "jpg" = "png", size: number = 128 ): Promise => new WebRequest( `/player/${part}/${query}.${extension}?size=${size}` ).execute(); /** * Get a Minecraft server by its platform and hostname. * * @param platform the platform of the server * @param hostname the hostname of the server * @returns the promised server */ export const getMinecraftServer = ( platform: ServerPlatform, hostname: string ): Promise => platform === ServerPlatform.JAVA ? new WebRequest( `/server/${platform}/${hostname}` ).execute() : new WebRequest( `/server/${platform}/${hostname}` ).execute(); /** * Check if the server with the * given hostname is blocked by Mojang. * * @param hostname the server hostname to check * @returns the promised blocked status */ export const isMojangBlocked = (hostname: string): Promise => new WebRequest(`/server/blocked/${hostname}`) .execute<{ blocked: boolean; }>() .then((res) => res.blocked); /** * Get the icon of the Java Minecraft * server with the given hostname. * * @param hostname the hostname of the server * @returns the primised server icon */ export const getJavaServerFavicon = (hostname: string): Promise => new WebRequest(`/server/icon/${hostname}`).execute(); /** * Get the status of Mojang servers. * * @returns the promised status */ export const getMojangServerStatus = (): Promise => new WebRequest("/mojang/status").execute();