generated from MinecraftJS/template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
listPackets.mjs
48 lines (40 loc) · 1.34 KB
/
listPackets.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { readdir, readFile, stat } from 'node:fs/promises';
import { join } from 'node:path';
const BASE_PATH = (state) => join('src', 'protocol', state);
const states = ['handshaking', 'login', 'play', 'status'];
async function list(boundTo) {
console.log(
`--- ${boundTo === 'client' ? 'Clientbound' : 'Serverbound'} Packets ---`
);
for (const state of states) {
const path = join(BASE_PATH(state), boundTo);
const dirStat = await stat(path).catch(() => false);
if (!dirStat || !dirStat.isDirectory()) continue;
const files = await readdir(path);
const packets = (
await Promise.all(
files
.filter((file) => file !== 'index.ts')
.map(async (file) => {
const content = await readFile(join(path, file));
return {
name: /class .* extends/g
.exec(content)[0]
.replace(/class | extends/g, ''),
id: /static id = .*;/g
.exec(content)[0]
.replace(/static id = |;/g, ''),
};
})
)
).sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
console.log(` - State: ${state}`);
for (const packet of packets) {
console.log(` ${packet.id} - ${packet.name}`);
}
console.log('');
}
}
await list('client');
console.log('');
await list('server');