LookAtMySuitBot/js/node_modules/mineflayer/lib/plugins/tablist.js

27 lines
691 B
JavaScript
Raw Normal View History

2023-12-24 20:08:39 -05:00
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 (packet.header) {
const header = escapeValueNewlines(packet.header)
bot.tablist.header = new ChatMessage(JSON.parse(header))
}
if (packet.footer) {
const footer = escapeValueNewlines(packet.footer)
bot.tablist.footer = new ChatMessage(JSON.parse(footer))
}
})
}