-
-
Notifications
You must be signed in to change notification settings - Fork 987
/
Copy pathtablist.js
31 lines (26 loc) · 914 Bytes
/
tablist.js
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
module.exports = inject
const escapeValueNewlines = str => {
return str.replace(/(": *"(?:\\"|[^"])+")/g, (_, match) => match.replace(/\n/g, '\\n'))
}
function inject (bot) {
const ChatMessage = require('prismarine-chat')(bot.registry)
bot.tablist = {
header: new ChatMessage(''),
footer: new ChatMessage('')
}
bot._client.on('playerlist_header', (packet) => {
if (bot.supportFeature('chatPacketsUseNbtComponents')) { // 1.20.3+
bot.tablist.header = ChatMessage.fromNotch(packet.header)
bot.tablist.footer = ChatMessage.fromNotch(packet.footer)
} else {
if (packet.header) {
const header = escapeValueNewlines(packet.header)
bot.tablist.header = ChatMessage.fromNotch(header)
}
if (packet.footer) {
const footer = escapeValueNewlines(packet.footer)
bot.tablist.footer = ChatMessage.fromNotch(footer)
}
}
})
}