node-minecraft-protocol/test/common/clientHelpers.js
extremeheat 367c01567c
Initial 1.19.1/2 signed chat support (#1050)
* Initial 1.19.1/2 signed chat impl

* lint

* remove node 15 nullish operators

* fix undefined uuid error

* handle player left

* fix

* add some feature flags

* fix

* Fix test to use new client.chat() wrapper method

* refactoring

* corrections, working client example

* refactoring

* message expiry checking

* Fix UUID write serialization

* Remove padding from client login to match vanilla client

* Fix server verification

* update packet field terminology

* Add some tech docs
Rename `map` field in Pending to not conflict with Array.map method

* update tech doc

* lint

* Bump mcdata and pauth

* add doc on playerChat event, .chat function

* update doc

* use supportFeature, update doc

Co-authored-by: Romain Beaumont <romain.rom1@gmail.com>
2023-01-14 20:33:04 +01:00

25 lines
715 B
JavaScript

module.exports = client => {
const mcData = require('minecraft-data')(client.version)
const hasSignedChat = mcData.supportFeature('signedChat')
client.nextMessage = (containing) => {
return new Promise((resolve) => {
function onChat (packet) {
const m = packet.message || packet.unsignedChatContent || packet.signedChatContent
if (containing) {
if (m.includes(containing)) return finish(m)
else return
}
return finish(m)
}
client.on(hasSignedChat ? 'player_chat' : 'chat', onChat)
function finish (m) {
client.off(hasSignedChat ? 'player_chat' : 'chat', onChat)
resolve(m)
}
})
}
return client
}