Skip to content

Commit

Permalink
Fix NBT chat not being used for 1.20.3+ kicks
Browse files Browse the repository at this point in the history
  • Loading branch information
extremeheat committed Jan 6, 2025
1 parent a9345e2 commit 5ec70a5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/createServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function createServer (options = {}) {
server.onlineModeExceptions = Object.create(null)
server.favicon = favicon
server.options = options
server._supportFeature = mcData.supportFeature
options.registryCodec = options.registryCodec || mcData.registryCodec || mcData.loginPacket?.dimensionCodec

// The RSA keypair can take some time to generate
Expand Down
4 changes: 3 additions & 1 deletion src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const net = require('net')
const EventEmitter = require('events').EventEmitter
const Client = require('./client')
const states = require('./states')
const nbt = require('prismarine-nbt')
const { createSerializer } = require('./transforms/serializer')

class Server extends EventEmitter {
Expand All @@ -26,7 +27,8 @@ class Server extends EventEmitter {
self.socketServer.on('connection', socket => {
const client = new Client(true, this.version, this.customPackets, this.hideErrors)
client._end = client.end
client.end = function end (endReason, fullReason = JSON.stringify({ text: endReason })) {
client.end = function end (endReason, fullReason) {
fullReason ??= this._supportFeature('chatPacketsUseNbtComponents') ? nbt.comp({ text: nbt.string(endReason) }) : JSON.stringify({ text: endReason })
if (client.state === states.PLAY) {
client.write('kick_disconnect', { reason: fullReason })
} else if (client.state === states.LOGIN) {
Expand Down

0 comments on commit 5ec70a5

Please sign in to comment.