Update chat example for 1.19 (#1059)

* Update example

* Fix lint
This commit is contained in:
Frej Alexander Nielsen 2023-01-16 20:35:26 +01:00 committed by GitHub
parent 4f9341e654
commit f2875a5f03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -43,9 +43,17 @@ client.on('connect', () => {
console.log('Connected to server')
rl.prompt()
client.on('playerChat', function ({ senderName, message, formattedMessage, verified }) {
const chat = new ChatMessage(formattedMessage ? JSON.parse(formattedMessage) : message)
console.log(senderName, { true: 'Verified:', false: 'UNVERIFIED:' }[verified] || '', chat.toAnsi())
client.on('playerChat', function ({ senderName, plainMessage, unsignedContent, formattedMessage, verified }) {
let content
const allowInsecureChat = true
if (formattedMessage) content = JSON.parse(formattedMessage)
else if (allowInsecureChat && unsignedContent) content = JSON.parse(unsignedContent)
else content = { text: plainMessage }
const chat = new ChatMessage(content)
console.log(senderName, { trugie: 'Verified:', false: 'UNVERIFIED:' }[verified] || '', chat.toAnsi())
})
})