Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PrismarineJS
GitHub Repository: PrismarineJS/mineflayer
Path: blob/master/lib/plugins/tablist.js
1467 views
1
module.exports = inject
2
3
const escapeValueNewlines = str => {
4
return str.replace(/(": *"(?:\\"|[^"])+")/g, (_, match) => match.replace(/\n/g, '\\n'))
5
}
6
7
function inject (bot) {
8
const ChatMessage = require('prismarine-chat')(bot.registry)
9
10
bot.tablist = {
11
header: new ChatMessage(''),
12
footer: new ChatMessage('')
13
}
14
15
bot._client.on('playerlist_header', (packet) => {
16
if (bot.supportFeature('chatPacketsUseNbtComponents')) { // 1.20.3+
17
bot.tablist.header = ChatMessage.fromNotch(packet.header)
18
bot.tablist.footer = ChatMessage.fromNotch(packet.footer)
19
} else {
20
if (packet.header) {
21
const header = escapeValueNewlines(packet.header)
22
bot.tablist.header = ChatMessage.fromNotch(header)
23
}
24
25
if (packet.footer) {
26
const footer = escapeValueNewlines(packet.footer)
27
bot.tablist.footer = ChatMessage.fromNotch(footer)
28
}
29
}
30
})
31
}
32
33