This commit is contained in:
parent
49a6e9b7b0
commit
1c1ea04cf0
@ -6,4 +6,9 @@ A simple, yet useful RESTful API for Minecraft utilizing Springboot.
|
|||||||
## NPM
|
## NPM
|
||||||
View this package on the [NPM Registry](https://www.npmjs.com/package/restfulmc-lib).
|
View this package on the [NPM Registry](https://www.npmjs.com/package/restfulmc-lib).
|
||||||
|
|
||||||
|
### Installation
|
||||||
|
```bash
|
||||||
|
npm install restfulmc-lib
|
||||||
|
```
|
||||||
|
|
||||||
![NPM Logo](https://avatars.githubusercontent.com/u/6078720?s=74)
|
![NPM Logo](https://avatars.githubusercontent.com/u/6078720?s=74)
|
4
Lib/src/index.d.ts
vendored
4
Lib/src/index.d.ts
vendored
@ -1 +1,5 @@
|
|||||||
|
export * from "./types/dns";
|
||||||
|
export * from "./types/generic";
|
||||||
|
export * from "./types/mojang";
|
||||||
export * from "./types/player";
|
export * from "./types/player";
|
||||||
|
export * from "./types/server";
|
||||||
|
@ -1 +1 @@
|
|||||||
export * from "./lib/restfulmc";
|
export * from "@/lib/restfulmc";
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import { MojangServerStatus } from "../types/mojang";
|
import { makeWebRequest } from "@/lib/webRequest";
|
||||||
import type { CachedPlayer } from "../types/player";
|
import { MojangServerStatus } from "@/types/mojang";
|
||||||
import { Platform } from "../types/server";
|
import type { CachedPlayer } from "@/types/player";
|
||||||
import { CachedBedrockMinecraftServer } from "../types/server/bedrock-server";
|
import { Platform } from "@/types/server";
|
||||||
import { CachedJavaMinecraftServer } from "../types/server/java-server";
|
import { CachedBedrockMinecraftServer } from "@/types/server/bedrock-server";
|
||||||
import { makeWebRequest } from "./webRequest";
|
import { CachedJavaMinecraftServer } from "@/types/server/java-server";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a player by their username or UUID.
|
* Get a player by their username or UUID.
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { ErrorResponse } from "../types/generic";
|
import { ErrorResponse } from "@/types/generic";
|
||||||
|
|
||||||
const ENDPOINT = "https://mc.rainnny.club"; // The API endpoint to use
|
const ENDPOINT = "https://mc.rainnny.club"; // The API endpoint to use
|
||||||
|
|
||||||
|
6
Lib/src/types/dns.d.ts
vendored
6
Lib/src/types/dns.d.ts
vendored
@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* An A record.
|
* An A record.
|
||||||
*/
|
*/
|
||||||
interface ARecord extends DNSRecord {
|
export interface ARecord extends DNSRecord {
|
||||||
/**
|
/**
|
||||||
* The address of this record, undefined if unresolved.
|
* The address of this record, undefined if unresolved.
|
||||||
*/
|
*/
|
||||||
@ -11,7 +11,7 @@ interface ARecord extends DNSRecord {
|
|||||||
/**
|
/**
|
||||||
* An SRV record.
|
* An SRV record.
|
||||||
*/
|
*/
|
||||||
interface SRVRecord extends DNSRecord {
|
export interface SRVRecord extends DNSRecord {
|
||||||
/**
|
/**
|
||||||
* The priority of this record.
|
* The priority of this record.
|
||||||
*/
|
*/
|
||||||
@ -36,7 +36,7 @@ interface SRVRecord extends DNSRecord {
|
|||||||
/**
|
/**
|
||||||
* A representation of a DNS record.
|
* A representation of a DNS record.
|
||||||
*/
|
*/
|
||||||
type DNSRecord = {
|
export type DNSRecord = {
|
||||||
/**
|
/**
|
||||||
* The type of this record.
|
* The type of this record.
|
||||||
*/
|
*/
|
||||||
|
12
Lib/src/types/player.d.ts
vendored
12
Lib/src/types/player.d.ts
vendored
@ -12,7 +12,7 @@ export interface CachedPlayer extends Player {
|
|||||||
/**
|
/**
|
||||||
* A Minecraft player.
|
* A Minecraft player.
|
||||||
*/
|
*/
|
||||||
type Player = {
|
export type Player = {
|
||||||
/**
|
/**
|
||||||
* The unique id of this player.
|
* The unique id of this player.
|
||||||
*/
|
*/
|
||||||
@ -57,7 +57,7 @@ type Player = {
|
|||||||
/**
|
/**
|
||||||
* A skin for a {@link Player}.
|
* A skin for a {@link Player}.
|
||||||
*/
|
*/
|
||||||
type Skin = {
|
export type Skin = {
|
||||||
/**
|
/**
|
||||||
* The texture URL of this skin.
|
* The texture URL of this skin.
|
||||||
*/
|
*/
|
||||||
@ -88,12 +88,12 @@ type Skin = {
|
|||||||
/**
|
/**
|
||||||
* Possible models for a skin.
|
* Possible models for a skin.
|
||||||
*/
|
*/
|
||||||
type SkinModel = "default" | "slim";
|
export type SkinModel = "default" | "slim";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A cape for a {@link Player}.
|
* A cape for a {@link Player}.
|
||||||
*/
|
*/
|
||||||
type Cape = {
|
export type Cape = {
|
||||||
/**
|
/**
|
||||||
* The texture URL of this cape.
|
* The texture URL of this cape.
|
||||||
*/
|
*/
|
||||||
@ -103,7 +103,7 @@ type Cape = {
|
|||||||
/**
|
/**
|
||||||
* A property of a Mojang profile.
|
* A property of a Mojang profile.
|
||||||
*/
|
*/
|
||||||
type ProfileProperty = {
|
export type ProfileProperty = {
|
||||||
/**
|
/**
|
||||||
* The name of this property.
|
* The name of this property.
|
||||||
*/
|
*/
|
||||||
@ -124,4 +124,4 @@ type ProfileProperty = {
|
|||||||
/**
|
/**
|
||||||
* Profile actions that can
|
* Profile actions that can
|
||||||
*/
|
*/
|
||||||
type ProfileAction = "FORCED_NAME_CHANGE" | "USING_BANNED_SKIN";
|
export type ProfileAction = "FORCED_NAME_CHANGE" | "USING_BANNED_SKIN";
|
||||||
|
12
Lib/src/types/server.d.ts
vendored
12
Lib/src/types/server.d.ts
vendored
@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* A model representing a Minecraft server.
|
* A model representing a Minecraft server.
|
||||||
*/
|
*/
|
||||||
type MinecraftServer = {
|
export type MinecraftServer = {
|
||||||
/**
|
/**
|
||||||
* The hostname of this server.
|
* The hostname of this server.
|
||||||
*/
|
*/
|
||||||
@ -36,7 +36,7 @@ type MinecraftServer = {
|
|||||||
/**
|
/**
|
||||||
* Player count data for a server.
|
* Player count data for a server.
|
||||||
*/
|
*/
|
||||||
type Players = {
|
export type Players = {
|
||||||
/**
|
/**
|
||||||
* The online players on this server.
|
* The online players on this server.
|
||||||
*/
|
*/
|
||||||
@ -56,7 +56,7 @@ type Players = {
|
|||||||
/**
|
/**
|
||||||
* A sample player.
|
* A sample player.
|
||||||
*/
|
*/
|
||||||
type PlayerSample = {
|
export type PlayerSample = {
|
||||||
/**
|
/**
|
||||||
* The ID of this player.
|
* The ID of this player.
|
||||||
*/
|
*/
|
||||||
@ -71,7 +71,7 @@ type PlayerSample = {
|
|||||||
/**
|
/**
|
||||||
* The name of a sample player.
|
* The name of a sample player.
|
||||||
*/
|
*/
|
||||||
type PlayerSampleName = {
|
export type PlayerSampleName = {
|
||||||
/**
|
/**
|
||||||
* The raw name.
|
* The raw name.
|
||||||
*/
|
*/
|
||||||
@ -91,7 +91,7 @@ type PlayerSampleName = {
|
|||||||
/**
|
/**
|
||||||
* The MOTD for a server.
|
* The MOTD for a server.
|
||||||
*/
|
*/
|
||||||
type MOTD = {
|
export type MOTD = {
|
||||||
/**
|
/**
|
||||||
* The raw MOTD lines.
|
* The raw MOTD lines.
|
||||||
*/
|
*/
|
||||||
@ -117,4 +117,4 @@ export type Platform = "java" | "bedrock";
|
|||||||
/**
|
/**
|
||||||
* Types of a DNS record.
|
* Types of a DNS record.
|
||||||
*/
|
*/
|
||||||
type RecordType = "A" | "SRV";
|
export type RecordType = "A" | "SRV";
|
||||||
|
10
Lib/src/types/server/bedrock-server.d.ts
vendored
10
Lib/src/types/server/bedrock-server.d.ts
vendored
@ -1,4 +1,4 @@
|
|||||||
import { MinecraftServer } from "../server";
|
import { MinecraftServer } from "@/types/server";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A cacheable {@link BedrockMinecraftServer}.
|
* A cacheable {@link BedrockMinecraftServer}.
|
||||||
@ -14,7 +14,7 @@ export interface CachedBedrockMinecraftServer extends BedrockMinecraftServer {
|
|||||||
/**
|
/**
|
||||||
* A Bedrock edition {@link MinecraftServer}.
|
* A Bedrock edition {@link MinecraftServer}.
|
||||||
*/
|
*/
|
||||||
interface BedrockMinecraftServer extends MinecraftServer {
|
export interface BedrockMinecraftServer extends MinecraftServer {
|
||||||
/**
|
/**
|
||||||
* The ID of this server.
|
* The ID of this server.
|
||||||
*/
|
*/
|
||||||
@ -39,12 +39,12 @@ interface BedrockMinecraftServer extends MinecraftServer {
|
|||||||
/**
|
/**
|
||||||
* The edition of a Bedrock server.
|
* The edition of a Bedrock server.
|
||||||
*/
|
*/
|
||||||
type Edition = "MCPE" | "MCEE";
|
export type Edition = "MCPE" | "MCEE";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Version information for a server.
|
* Version information for a server.
|
||||||
*/
|
*/
|
||||||
type Version = {
|
export type Version = {
|
||||||
/**
|
/**
|
||||||
* The protocol version of the server.
|
* The protocol version of the server.
|
||||||
*/
|
*/
|
||||||
@ -59,7 +59,7 @@ type Version = {
|
|||||||
/**
|
/**
|
||||||
* The gamemode of a server.
|
* The gamemode of a server.
|
||||||
*/
|
*/
|
||||||
type GameMode = {
|
export type GameMode = {
|
||||||
/**
|
/**
|
||||||
* The name of this gamemode.
|
* The name of this gamemode.
|
||||||
*/
|
*/
|
||||||
|
18
Lib/src/types/server/java-server.d.ts
vendored
18
Lib/src/types/server/java-server.d.ts
vendored
@ -1,4 +1,4 @@
|
|||||||
import { MinecraftServer } from "../server";
|
import { MinecraftServer } from "@/types/server";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A cacheable {@link JavaMinecraftServer}.
|
* A cacheable {@link JavaMinecraftServer}.
|
||||||
@ -14,7 +14,7 @@ export interface CachedJavaMinecraftServer extends JavaMinecraftServer {
|
|||||||
/**
|
/**
|
||||||
* A Java edition {@link MinecraftServer}.
|
* A Java edition {@link MinecraftServer}.
|
||||||
*/
|
*/
|
||||||
interface JavaMinecraftServer extends MinecraftServer {
|
export interface JavaMinecraftServer extends MinecraftServer {
|
||||||
/**
|
/**
|
||||||
* The version information of this server.
|
* The version information of this server.
|
||||||
*/
|
*/
|
||||||
@ -70,7 +70,7 @@ interface JavaMinecraftServer extends MinecraftServer {
|
|||||||
/**
|
/**
|
||||||
* Version information for a server.
|
* Version information for a server.
|
||||||
*/
|
*/
|
||||||
type Version = {
|
export type Version = {
|
||||||
/**
|
/**
|
||||||
* The version name of the server.
|
* The version name of the server.
|
||||||
*/
|
*/
|
||||||
@ -100,7 +100,7 @@ type Version = {
|
|||||||
/**
|
/**
|
||||||
* The favicon for a server.
|
* The favicon for a server.
|
||||||
*/
|
*/
|
||||||
type Favicon = {
|
export type Favicon = {
|
||||||
/**
|
/**
|
||||||
* The raw Base64 encoded favicon.
|
* The raw Base64 encoded favicon.
|
||||||
*/
|
*/
|
||||||
@ -118,7 +118,7 @@ type Favicon = {
|
|||||||
* This is for servers on 1.12 or below.
|
* This is for servers on 1.12 or below.
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
type ModInfo = {
|
export type ModInfo = {
|
||||||
/**
|
/**
|
||||||
* The type of modded server this is.
|
* The type of modded server this is.
|
||||||
*/
|
*/
|
||||||
@ -133,7 +133,7 @@ type ModInfo = {
|
|||||||
/**
|
/**
|
||||||
* A legacy Forge mod for a server.
|
* A legacy Forge mod for a server.
|
||||||
*/
|
*/
|
||||||
type LegacyForgeMod = {
|
export type LegacyForgeMod = {
|
||||||
/**
|
/**
|
||||||
* The name of this mod.
|
* The name of this mod.
|
||||||
*/
|
*/
|
||||||
@ -151,7 +151,7 @@ type LegacyForgeMod = {
|
|||||||
* This is for servers on 1.13 and above.
|
* This is for servers on 1.13 and above.
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
type ForgeData = {
|
export type ForgeData = {
|
||||||
/**
|
/**
|
||||||
* The list of channels on this server, empty if none.
|
* The list of channels on this server, empty if none.
|
||||||
*/
|
*/
|
||||||
@ -180,7 +180,7 @@ type ForgeData = {
|
|||||||
/**
|
/**
|
||||||
* A Forge channel for a server.
|
* A Forge channel for a server.
|
||||||
*/
|
*/
|
||||||
type ForgeChannel = {
|
export type ForgeChannel = {
|
||||||
/**
|
/**
|
||||||
* The name of this channel.
|
* The name of this channel.
|
||||||
*/
|
*/
|
||||||
@ -200,7 +200,7 @@ type ForgeChannel = {
|
|||||||
/**
|
/**
|
||||||
* A modern Forge mod for a server.
|
* A modern Forge mod for a server.
|
||||||
*/
|
*/
|
||||||
type ModernForgeMod = {
|
export type ModernForgeMod = {
|
||||||
/**
|
/**
|
||||||
* The name of this mod.
|
* The name of this mod.
|
||||||
*/
|
*/
|
||||||
|
@ -1,24 +1,35 @@
|
|||||||
// describe("player", () => {
|
import { describe, it } from "bun:test";
|
||||||
// it("Rainnny", async () => {
|
import { getMinecraftServer, getMojangServerStatus, getPlayer } from "../src";
|
||||||
// const player: CachedPlayer = await getPlayer("Rainnny");
|
import { ErrorResponse } from "../src/types/generic";
|
||||||
// console.log("player found", player.cached);
|
import { MojangServerStatus } from "../src/types/mojang";
|
||||||
// });
|
import { CachedPlayer } from "../src/types/player";
|
||||||
// });
|
import { CachedBedrockMinecraftServer } from "../src/types/server/bedrock-server";
|
||||||
|
import { CachedJavaMinecraftServer } from "../src/types/server/java-server";
|
||||||
|
|
||||||
// describe("server", () => {
|
describe("player", () => {
|
||||||
// it("java", async () => {
|
it("Rainnny", async () => {
|
||||||
// const server: JavaMinecraftServer | BedrockMinecraftServer =
|
try {
|
||||||
// await getMinecraftServer("java", "play.wildnetwork.net");
|
const player: CachedPlayer = await getPlayer("Rainnny");
|
||||||
|
console.log(`Hello ${player.username}, your UUID is ${player.uniqueId}!`);
|
||||||
|
} catch (err) {
|
||||||
|
if ((err as ErrorResponse).code == 404) {
|
||||||
|
console.error("Player with UUID or username not found.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// if ((server as BedrockMinecraftServer).id) {
|
describe("server", () => {
|
||||||
// }
|
it("java", async () => {
|
||||||
// console.log(server.ip);
|
const server: CachedJavaMinecraftServer | CachedBedrockMinecraftServer =
|
||||||
// });
|
await getMinecraftServer("java", "play.wildnetwork.net");
|
||||||
// });
|
console.log(server.ip);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// describe("mojang", () => {
|
describe("mojang", () => {
|
||||||
// it("status", async () => {
|
it("status", async () => {
|
||||||
// const status: MojangServerStatus = await getMojangServerStatus();
|
const status: MojangServerStatus = await getMojangServerStatus();
|
||||||
// console.log(status["https://sessionserver.mojang.com"]);
|
console.log(status["https://sessionserver.mojang.com"]);
|
||||||
// });
|
});
|
||||||
// });
|
});
|
||||||
|
@ -11,6 +11,11 @@
|
|||||||
"allowJs": true,
|
"allowJs": true,
|
||||||
"noEmit": true,
|
"noEmit": true,
|
||||||
"outDir": "dist",
|
"outDir": "dist",
|
||||||
"resolveJsonModule": true
|
"resolveJsonModule": true,
|
||||||
|
"paths": {
|
||||||
|
"@/*": ["./*"],
|
||||||
|
"@/lib/*": ["./src/lib/*"],
|
||||||
|
"@/types/*": ["./src/types/*"]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user