2023-12-17 14:55:27 -05:00
|
|
|
function parseMessage (message, data, context) {
|
2023-12-20 11:54:03 -05:00
|
|
|
try {
|
|
|
|
if (message === null || typeof message !== 'object') return
|
2023-12-17 14:55:27 -05:00
|
|
|
|
|
|
|
if (message.with?.length < 2 || (message.translate !== 'chat.type.text' && message.translate !== '%s %s')) return
|
|
|
|
|
|
|
|
const senderComponent = message.with[0]
|
|
|
|
// wtf spam again - console.log(senderComponent)//wtf...
|
|
|
|
//console.log(senderComponent)
|
|
|
|
|
|
|
|
const contents = message.with[1]
|
|
|
|
// spam lol - console.log(contents)
|
|
|
|
//console.log(contents)
|
|
|
|
let sender
|
|
|
|
|
|
|
|
const hoverEvent = senderComponent.hoverEvent
|
|
|
|
if (hoverEvent?.action === 'show_entity') {
|
|
|
|
const id = hoverEvent.contents.id
|
|
|
|
//
|
|
|
|
sender = data.players.find(player => player.uuid === id)
|
|
|
|
} else {
|
|
|
|
const stringUsername = data.getMessageAsPrismarine(senderComponent).toString() // TypeError: data.getMessageAsPrismarine is not a function
|
|
|
|
|
|
|
|
sender = data.players.find(player => player.profile.name) //=== stringusername)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!sender) return undefined
|
|
|
|
|
|
|
|
return { sender, contents, type: 'minecraft:chat', senderComponent }
|
2023-12-20 11:54:03 -05:00
|
|
|
}catch(e){
|
|
|
|
console.log(e.stack)
|
|
|
|
}
|
2023-12-17 14:55:27 -05:00
|
|
|
}
|
|
|
|
module.exports = parseMessage
|