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)
|
2024-10-12 17:55:36 -04:00
|
|
|
client.registry.loadDimensionCodec(data.codec || data)
|
2024-02-25 19:14:49 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|