minecraft-toolkit 0.1.4 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -7
- package/index.d.ts +16 -6
- package/index.js +7 -1
- package/package.json +18 -20
- package/src/errors.js +1 -2
- package/src/player/resolve.js +2 -3
- package/src/server/java/status.js +6 -5
- package/src/utils/network.js +8 -4
package/README.md
CHANGED
|
@@ -81,9 +81,10 @@ import {
|
|
|
81
81
|
|
|
82
82
|
isValidUsername("26bz"); // true
|
|
83
83
|
uuidWithDashes("069a79f444e94726a5befca90e38aaf5");
|
|
84
|
-
const
|
|
84
|
+
const profile = await fetchPlayerProfile("26bz");
|
|
85
|
+
const skinUrl = getSkinURL(profile);
|
|
85
86
|
const hash = extractTextureHash(skinUrl);
|
|
86
|
-
const model = getSkinModel(
|
|
87
|
+
const model = getSkinModel(profile); // "slim" | "default"
|
|
87
88
|
```
|
|
88
89
|
|
|
89
90
|
## Skin Metadata & Color Sampling
|
|
@@ -139,13 +140,13 @@ import {
|
|
|
139
140
|
fetchBedrockServerStatus,
|
|
140
141
|
} from "minecraft-toolkit";
|
|
141
142
|
|
|
142
|
-
const javaStatus = await fetchJavaServerStatus(
|
|
143
|
-
const bedrockStatus = await fetchBedrockServerStatus(
|
|
143
|
+
const javaStatus = await fetchJavaServerStatus("mc.hypixel.net", { port: 25565 });
|
|
144
|
+
const bedrockStatus = await fetchBedrockServerStatus("play.example.net", { port: 19132 });
|
|
144
145
|
|
|
145
146
|
// fetchServerStatus picks the right probe based on the `edition` field
|
|
146
|
-
const autoStatus = await fetchServerStatus(
|
|
147
|
+
const autoStatus = await fetchServerStatus("my.realm.net", { edition: "bedrock" });
|
|
147
148
|
|
|
148
|
-
console.log(javaStatus.players.online, bedrockStatus.motd
|
|
149
|
+
console.log(javaStatus.players.online, bedrockStatus.motd);
|
|
149
150
|
```
|
|
150
151
|
|
|
151
152
|
Both helpers normalize MOTD text, favicon/Base64 icons, latency, and version info. Errors surface as
|
|
@@ -179,7 +180,7 @@ import { sendVotifierVote } from "minecraft-toolkit";
|
|
|
179
180
|
const result = await sendVotifierVote({
|
|
180
181
|
host: "votifier.myserver.net",
|
|
181
182
|
port: 8192, // defaults to 8192 if omitted
|
|
182
|
-
publicKey: process.env.VOTIFIER_PUBLIC_KEY
|
|
183
|
+
publicKey: process.env.VOTIFIER_PUBLIC_KEY, // v1 servers
|
|
183
184
|
serviceName: "MyTopList",
|
|
184
185
|
username: "26bz",
|
|
185
186
|
address: "198.51.100.42",
|
package/index.d.ts
CHANGED
|
@@ -71,7 +71,7 @@ export function fetchSkinMetadata(
|
|
|
71
71
|
sampleRegion?: { x?: number; y?: number; width?: number; height?: number };
|
|
72
72
|
},
|
|
73
73
|
): Promise<SkinMetadataResult>;
|
|
74
|
-
export function
|
|
74
|
+
export function computeSkinDominantColor(
|
|
75
75
|
url: string,
|
|
76
76
|
region?: { x?: number; y?: number; width?: number; height?: number },
|
|
77
77
|
): Promise<string | null>;
|
|
@@ -136,6 +136,7 @@ export interface BedrockServerStatusOptions {
|
|
|
136
136
|
|
|
137
137
|
export interface ServerStatusOptions extends JavaServerStatusOptions {
|
|
138
138
|
edition?: ServerEdition;
|
|
139
|
+
/** @deprecated Use `edition` instead. */
|
|
139
140
|
type?: ServerEdition;
|
|
140
141
|
}
|
|
141
142
|
|
|
@@ -231,11 +232,20 @@ export interface VotifierVoteResult {
|
|
|
231
232
|
export function sendVotifierVote(options: VotifierVoteOptions): Promise<VotifierVoteResult>;
|
|
232
233
|
|
|
233
234
|
export interface PlayerHandlers {
|
|
234
|
-
profileHandler:
|
|
235
|
-
skinHandler:
|
|
236
|
-
summaryHandler:
|
|
237
|
-
uuidHandler:
|
|
238
|
-
resolverHandler:
|
|
235
|
+
profileHandler: import("h3").EventHandler;
|
|
236
|
+
skinHandler: import("h3").EventHandler;
|
|
237
|
+
summaryHandler: import("h3").EventHandler;
|
|
238
|
+
uuidHandler: import("h3").EventHandler;
|
|
239
|
+
resolverHandler: import("h3").EventHandler;
|
|
240
|
+
nameHistoryHandler: import("h3").EventHandler;
|
|
241
|
+
existsHandler: import("h3").EventHandler;
|
|
242
|
+
batchHandler: import("h3").EventHandler;
|
|
243
|
+
nameChangeInfoHandler: import("h3").EventHandler;
|
|
244
|
+
nameAvailabilityHandler: import("h3").EventHandler;
|
|
245
|
+
giftCodeValidationHandler: import("h3").EventHandler;
|
|
246
|
+
blockedServersHandler: import("h3").EventHandler;
|
|
247
|
+
serverStatusHandler: import("h3").EventHandler;
|
|
248
|
+
serverIconHandler: import("h3").EventHandler;
|
|
239
249
|
}
|
|
240
250
|
|
|
241
251
|
export function createPlayerHandlers(): PlayerHandlers;
|
package/index.js
CHANGED
|
@@ -10,7 +10,13 @@ export {
|
|
|
10
10
|
hasSkinChanged,
|
|
11
11
|
} from "./src/player/profile/index.js";
|
|
12
12
|
export { fetchSkinMetadata, computeSkinDominantColor } from "./src/player/skin.js";
|
|
13
|
-
export {
|
|
13
|
+
export {
|
|
14
|
+
isValidUsername,
|
|
15
|
+
isUUID,
|
|
16
|
+
normalizeUUID,
|
|
17
|
+
uuidWithDashes,
|
|
18
|
+
uuidWithoutDashes,
|
|
19
|
+
} from "./src/player/identity/index.js";
|
|
14
20
|
export { getSkinURL, getCapeURL, getSkinModel, extractTextureHash } from "./src/player/textures.js";
|
|
15
21
|
export { resolvePlayer } from "./src/player/resolve.js";
|
|
16
22
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "minecraft-toolkit",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Minecraft toolkit for Mojang player data, server status probes, and Votifier v1/v2 clients.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"minecraft",
|
|
@@ -47,28 +47,17 @@
|
|
|
47
47
|
"default": "./index.js"
|
|
48
48
|
}
|
|
49
49
|
},
|
|
50
|
-
"scripts": {
|
|
51
|
-
"test": "vitest",
|
|
52
|
-
"test:watch": "vitest watch",
|
|
53
|
-
"test:coverage": "vitest run --coverage",
|
|
54
|
-
"lint": "oxlint",
|
|
55
|
-
"lint:fix": "oxlint --fix",
|
|
56
|
-
"fmt": "oxfmt",
|
|
57
|
-
"fmt:check": "oxfmt --check",
|
|
58
|
-
"prepare": "husky install",
|
|
59
|
-
"docs:sync": "automd"
|
|
60
|
-
},
|
|
61
50
|
"dependencies": {
|
|
62
|
-
"h3": "2.0.1-rc.
|
|
51
|
+
"h3": "2.0.1-rc.20",
|
|
63
52
|
"pngjs": "^7.0.0"
|
|
64
53
|
},
|
|
65
54
|
"devDependencies": {
|
|
66
|
-
"automd": "^0.3
|
|
55
|
+
"automd": "^0.4.3",
|
|
67
56
|
"husky": "^9.1.7",
|
|
68
|
-
"lint-staged": "^16.
|
|
69
|
-
"oxfmt": "^0.
|
|
70
|
-
"oxlint": "^1.
|
|
71
|
-
"vitest": "^4.
|
|
57
|
+
"lint-staged": "^16.4.0",
|
|
58
|
+
"oxfmt": "^0.42.0",
|
|
59
|
+
"oxlint": "^1.57.0",
|
|
60
|
+
"vitest": "^4.1.2"
|
|
72
61
|
},
|
|
73
62
|
"lint-staged": {
|
|
74
63
|
"*.{js,jsx,ts,tsx,mjs,cjs}": "pnpm run lint"
|
|
@@ -76,5 +65,14 @@
|
|
|
76
65
|
"engines": {
|
|
77
66
|
"node": ">=18"
|
|
78
67
|
},
|
|
79
|
-
"
|
|
80
|
-
|
|
68
|
+
"scripts": {
|
|
69
|
+
"test": "vitest",
|
|
70
|
+
"test:watch": "vitest watch",
|
|
71
|
+
"test:coverage": "vitest run --coverage",
|
|
72
|
+
"lint": "oxlint",
|
|
73
|
+
"lint:fix": "oxlint --fix",
|
|
74
|
+
"fmt": "oxfmt",
|
|
75
|
+
"fmt:check": "oxfmt --check",
|
|
76
|
+
"docs:sync": "automd"
|
|
77
|
+
}
|
|
78
|
+
}
|
package/src/errors.js
CHANGED
package/src/player/resolve.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isUUID, normalizeUUID, uuidWithDashes } from "./identity/index.js";
|
|
2
|
-
import { fetchPlayerProfile,
|
|
2
|
+
import { fetchPlayerProfile, fetchUsernameByUUID } from "./profile/index.js";
|
|
3
3
|
|
|
4
4
|
export async function resolvePlayer(input) {
|
|
5
5
|
if (typeof input !== "string" || input.trim().length === 0) {
|
|
@@ -21,9 +21,8 @@ export async function resolvePlayer(input) {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
const profile = await fetchPlayerProfile(raw);
|
|
24
|
-
const { id } = await fetchPlayerUUID(raw);
|
|
25
24
|
return {
|
|
26
|
-
id: uuidWithDashes(id),
|
|
25
|
+
id: uuidWithDashes(profile.id),
|
|
27
26
|
name: profile.name,
|
|
28
27
|
skin: profile.skin ?? null,
|
|
29
28
|
cape: profile.cape ?? null,
|
|
@@ -218,17 +218,18 @@ function parseStatusPayload(payload) {
|
|
|
218
218
|
}
|
|
219
219
|
|
|
220
220
|
function buildJavaStatus(payload, host, port, latencyMs) {
|
|
221
|
+
const { version, players, description, favicon, ...rest } = payload;
|
|
221
222
|
return {
|
|
222
223
|
edition: "java",
|
|
223
224
|
online: true,
|
|
224
225
|
host,
|
|
225
226
|
port,
|
|
226
|
-
version:
|
|
227
|
-
players:
|
|
228
|
-
motd: stringifyDescription(
|
|
229
|
-
favicon:
|
|
227
|
+
version: version ?? null,
|
|
228
|
+
players: players ?? null,
|
|
229
|
+
motd: stringifyDescription(description) ?? null,
|
|
230
|
+
favicon: favicon ?? null,
|
|
230
231
|
latencyMs,
|
|
231
|
-
raw:
|
|
232
|
+
raw: rest,
|
|
232
233
|
};
|
|
233
234
|
}
|
|
234
235
|
|
package/src/utils/network.js
CHANGED
|
@@ -5,10 +5,14 @@ export function resolveAddress(address, overridePort, fallbackPort) {
|
|
|
5
5
|
return { host: address, port: validatePort(overridePort) };
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
// Only treat as "host:port" when there is exactly one colon.
|
|
9
|
+
const colonCount = (address.match(/:/g) ?? []).length;
|
|
10
|
+
if (colonCount === 1) {
|
|
11
|
+
const lastColon = address.lastIndexOf(":");
|
|
12
|
+
const potentialPort = address.slice(lastColon + 1);
|
|
13
|
+
if (potentialPort !== "") {
|
|
14
|
+
return { host: address.slice(0, lastColon), port: validatePort(potentialPort) };
|
|
15
|
+
}
|
|
12
16
|
}
|
|
13
17
|
|
|
14
18
|
return { host: address, port: fallbackPort };
|