2024-02-25 19:14:49 -05:00
|
|
|
const Registry = require('prismarine-registry')
|
2022-08-15 18:57:26 -04:00
|
|
|
module.exports = client => {
|
|
|
|
client.nextMessage = (containing) => {
|
|
|
|
return new Promise((resolve) => {
|
|
|
|
function onChat (packet) {
|
2023-01-21 14:31:17 -05:00
|
|
|
const m = packet.formattedMessage || packet.unsignedChatContent || JSON.stringify({ text: packet.plainMessage })
|
2022-08-15 18:57:26 -04:00
|
|
|
if (containing) {
|
|
|
|
if (m.includes(containing)) return finish(m)
|
|
|
|
else return
|
|
|
|
}
|
|
|
|
return finish(m)
|
|
|
|
}
|
2023-01-21 14:31:17 -05:00
|
|
|
client.on('playerChat', onChat)
|
|
|
|
client.on('systemChat', onChat) // For 1.7.10
|
2022-08-15 18:57:26 -04:00
|
|
|
|
|
|
|
function finish (m) {
|
2023-01-21 14:31:17 -05:00
|
|
|
client.off('playerChat', onChat)
|
|
|
|
client.off('systemChat', onChat)
|
2022-08-15 18:57:26 -04:00
|
|
|
resolve(m)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-02-25 19:14:49 -05:00
|
|
|
client.on('login', (packet) => {
|
|
|
|
client.registry ??= Registry(client.version)
|
|
|
|
if (packet.dimensionCodec) {
|
|
|
|
client.registry.loadDimensionCodec(packet.dimensionCodec)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
client.on('registry_data', (data) => {
|
|
|
|
client.registry ??= Registry(client.version)
|
|
|
|
client.registry.loadDimensionCodec(data.codec)
|
|
|
|
})
|
|
|
|
|
|
|
|
client.on('playerJoin', () => {
|
|
|
|
const ChatMessage = require('prismarine-chat')(client.registry || client.version)
|
|
|
|
client.parseMessage = (comp) => {
|
|
|
|
return new ChatMessage(comp)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-08-15 18:57:26 -04:00
|
|
|
return client
|
|
|
|
}
|