cleanup
Some checks failed
Publish Package / build (push) Has been cancelled

This commit is contained in:
Lee
2024-04-15 08:56:26 +01:00
parent 3342f696af
commit b9d79659c8
12 changed files with 150 additions and 219 deletions

14
src/lib/mojang.ts Normal file
View File

@ -0,0 +1,14 @@
import { API_ENDPOINT } from "..";
import WebRequest from "../common/WebRequest";
import { CachedEndpointStatus } from "../types/cache/cachedEndpointStatus";
const endpointStatusEndpoint = API_ENDPOINT + "/mojang/status";
/**
* Gets the Mojang API status.
*
* @returns the Mojang API status
*/
export function getMojangEndpointStatus(): Promise<CachedEndpointStatus> {
return WebRequest.get(endpointStatusEndpoint);
}

39
src/lib/player.ts Normal file
View File

@ -0,0 +1,39 @@
import { API_ENDPOINT } from "..";
import WebRequest from "../common/WebRequest";
import { CachedPlayer } from "../types/cache/cachedPlayer";
import { CachedUsernameToUuid } from "../types/cache/cachedUsernameToUuid";
const playerEndpoint = API_ENDPOINT + "/player/{id}";
const playerUsernameToUuidEndpoint = API_ENDPOINT + "/player/uuid/{id}";
const playerSkinPartEndpoint = API_ENDPOINT + "/player/{part}/{id}";
/**
* Gets information about a Minecraft player.
*
* @param id the id of the player
* @returns the player information, or null if the player does not exist
*/
export function getPlayer(id: string): Promise<CachedPlayer> {
return WebRequest.get<CachedPlayer>(playerEndpoint.replace("{id}", id));
}
/**
* Gets the UUID of a Minecraft player.
*
* @param id the id of the player
* @returns the player's UUID, or null if the player does not exist
*/
export function getPlayerUuid(id: string): Promise<CachedUsernameToUuid> {
return WebRequest.get<CachedUsernameToUuid>(playerUsernameToUuidEndpoint.replace("{id}", id));
}
/**
* Gets a part of a Minecraft player's skin.
*
* @param part the part of the skin
* @param id the id of the player
* @returns the player's skin part, or null if the player does not exist
*/
export function getPlayerSkinPart(part: string, id: string): Promise<Buffer> {
return WebRequest.get<Buffer>(playerSkinPartEndpoint.replace("{part}", part).replace("{id}", id));
}

46
src/lib/server.ts Normal file
View File

@ -0,0 +1,46 @@
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<CachedMinecraftServer> {
const ip = port ? `${hostname}:${port}` : hostname;
return WebRequest.get<CachedMinecraftServer>(
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<Buffer> {
const ip = port ? `${hostname}:${port}` : hostname;
return WebRequest.get<Buffer>(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<BlockedStatus> {
return WebRequest.get<BlockedStatus>(blockedServerEndpoint.replace("{hostname}", hostname));
}