dougbot/bridge/lib/mineflayer/lib/plugins/boss_bar.js
roberts 8f616598fd Fix chat, brain stability, MariaDB reconnect, suppress warnings
- Listen on raw 'text' packet for Bedrock chat (pattern-based chat event
  doesn't fire reliably on Bedrock)
- Brain: add safety reset for stuck pending_status flag
- MariaDB: add retry-on-disconnect for all query methods
- Suppress harmless punycode deprecation warning from Node.js
- Add mineflayer-bedrock lib packages (mineflayer, prismarine-chunk,
  prismarine-registry) for movement support
- Exclude minecraft-data from git (278MB, installed via npm)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 12:33:17 -05:00

63 lines
1.8 KiB
JavaScript

module.exports = inject
function inject (bot, { version }) {
const BossBar = require('../bossbar')(bot.registry)
const bars = {}
function extractTitle (title) {
if (!title) return ''
if (typeof title === 'string') return title
// Return the original object for BossBar to handle
return title
}
function handleBossBarPacket (packet) {
if (packet.action === 0) {
bars[packet.entityUUID] = new BossBar(
packet.entityUUID,
extractTitle(packet.title),
packet.health,
packet.dividers,
packet.color,
packet.flags
)
bot.emit('bossBarCreated', bars[packet.entityUUID])
} else if (packet.action === 1) {
bot.emit('bossBarDeleted', bars[packet.entityUUID])
delete bars[packet.entityUUID]
} else {
if (!(packet.entityUUID in bars)) {
return
}
if (packet.action === 2 && packet.health !== undefined) {
bars[packet.entityUUID].health = packet.health
}
if (packet.action === 3 && packet.title !== undefined) {
bars[packet.entityUUID].title = extractTitle(packet.title)
}
if (packet.action === 4) {
if (packet.dividers !== undefined) {
bars[packet.entityUUID].dividers = packet.dividers
}
if (packet.color !== undefined) {
bars[packet.entityUUID].color = packet.color
}
}
if (packet.action === 5 && packet.flags !== undefined) {
bars[packet.entityUUID].flags = packet.flags
}
bot.emit('bossBarUpdated', bars[packet.entityUUID])
}
}
// Handle all possible packet names
bot._client.on('boss_bar', handleBossBarPacket)
bot._client.on('bossbar', handleBossBarPacket)
bot._client.on('boss_bar_update', handleBossBarPacket)
Object.defineProperty(bot, 'bossBars', {
get () {
return Object.values(bars)
}
})
}