From 0b3c8802ad0cd05197b6f490db640c2ae2f7afb4 Mon Sep 17 00:00:00 2001 From: extremeheat Date: Sat, 24 Feb 2024 18:46:01 -0500 Subject: [PATCH] Update server.js --- examples/server/server.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/server/server.js b/examples/server/server.js index 482531a..338cc4f 100644 --- a/examples/server/server.js +++ b/examples/server/server.js @@ -10,6 +10,11 @@ const options = { const server = mc.createServer(options) const mcData = require('minecraft-data')(server.version) const loginPacket = mcData.loginPacket +function chatText (text) { + return mcData.supportFeature('chatPacketsUseNbtComponents') + ? nbt.comp({ text: nbt.string(text) }) + : JSON.stringify({ text }) +} server.on('playerJoin', function (client) { broadcast(client.username + ' joined the game.') @@ -67,7 +72,7 @@ function sendBroadcastMessage (server, clients, message, sender) { server.writeToClients(clients, 'player_chat', { plainMessage: message, signedChatContent: '', - unsignedChatContent: JSON.stringify({ text: message }), + unsignedChatContent: chatText(message), type: 0, senderUuid: 'd3527a0b-bc03-45d5-a878-2aafdd8c8a43', // random senderName: JSON.stringify({ text: sender }),