fix playerchat, profileless chat packet

This commit is contained in:
Yaode_owo 2024-10-14 07:22:26 -04:00
parent 17d9868ec7
commit ceb3f8d869

View file

@ -1,4 +1,4 @@
const lang = require("../util/en_us.json"); // translate message
const lang = require("./en_us.json"); // translate message
const nbt = require('prismarine-nbt');
function uuidFromIntArray (arr) {
@ -30,10 +30,16 @@ function processNbtMessage(msg) {
}
}
let profilelesschat = {};
let systemchat = {};
let playerchat = {};
function inject(bot) {
let playerchat = {};
let systemchat = {};
let profilelesschat = {};
bot.on('end', () => { // im think this can fix memory leak.
playerchat = {}; delete playerchat;
systemchat = {}; delete systemchat;
profilelesschat = {}; delete profilelesschat;
})
bot.on('system_chat', (packet) => { // system
if (packet.isActionBar) return;
@ -58,9 +64,40 @@ bot.on('profileless_chat', (packet) => { // sudo and vanish
profilelesschat.nocolor_formattedMessage = parseMinecraftMessageNoColor(processNbtMessage(packet.message))
profilelesschat.nocolor_senderName = parseMinecraftMessageNoColor(processNbtMessage(packet.name))
profilelesschat.nocolor_targetName = parseMinecraftMessageNoColor(processNbtMessage(packet.target))
bot.emit('Custom_ProfilelessChat', profilelesschat.formattedMessage, profilelesschat)
bot.emit('Custom_AllChat', profilelesschat.formattedMessage, profilelesschat)
switch (profilelesschat.type) {
case 1: // /me text
profilelesschat.message = `* ${profilelesschat.senderName} ${profilelesschat.formattedMessage}`;
profilelesschat.nocolor_msg = `* ${profilelesschat.nocolor_senderName} ${profilelesschat.nocolor_formattedMessage}`;
break;
case 2: // someone /tell you text
profilelesschat.message = `${profilelesschat.senderName} whispers to you: ${profilelesschat.formattedMessage}`;
profilelesschat.nocolor_msg = `${profilelesschat.nocolor_senderName} whispers to you: ${profilelesschat.nocolor_formattedMessage}`;
break;
case 3: // you /tell someone text
profilelesschat.message = `You whisper to ${profilelesschat.targetName}: ${profilelesschat.formattedMessage}`;
profilelesschat.nocolor_msg = `You whisper to ${profilelesschat.nocolor_targetName}: ${profilelesschat.nocolor_formattedMessage}`;
break;
case 4: // player chat
profilelesschat.message = profilelesschat.unsignedContent;
profilelesschat.nocolor_msg = profilelesschat.nocolor_unsignedContent;
break;
case 5: // /say text
profilelesschat.message = `[${profilelesschat.senderName}] ${profilelesschat.formattedMessage}`;
profilelesschat.nocolor_msg = `[${profilelesschat.nocolor_senderName}] ${profilelesschat.nocolor_formattedMessage}`;
break;
case 6: // /minecraft:teammsg text
profilelesschat.message = `${profilelesschat.targetName} <${profilelesschat.senderName}> ${profilelesschat.formattedMessage}`;
profilelesschat.nocolor_msg = `${profilelesschat.nocolor_targetName} <${profilelesschat.nocolor_senderName}> ${profilelesschat.formattedMessage}`;
break;
default:
console.log(`Unknown player_chat packet. Type: ${profilelesschat.type}`);
console.log(packet);
break;
}
bot.emit('Custom_ProfilelessChat', profilelesschat.message, profilelesschat)
bot.emit('Custom_AllChat', profilelesschat.message, profilelesschat)
})
bot.on('player_chat', (packet) => { // player
@ -82,36 +119,36 @@ bot.on('player_chat', (packet) => { // player
switch (playerchat.type) {
case 1: // /me text
msg = `* ${playerchat.senderName} ${playerchat.formattedMessage}`;
playerchat.message = `* ${playerchat.senderName} ${playerchat.formattedMessage}`;
playerchat.nocolor_msg = `* ${playerchat.nocolor_senderName} ${playerchat.nocolor_formattedMessage}`;
break;
case 2: // someone /tell you text
msg = `${playerchat.senderName} whispers to you: ${playerchat.plainMessage || playerchat.formattedMessage}`;
playerchat.message = `${playerchat.senderName} whispers to you: ${playerchat.plainMessage || playerchat.formattedMessage}`;
playerchat.nocolor_msg = `${playerchat.nocolor_senderName} whispers to you: ${playerchat.plainMessage || playerchat.nocolor_formattedMessage}`;
break;
case 3: // you /tell someone text
msg = `You whisper to ${playerchat.targetName}: ${playerchat.plainMessage || playerchat.formattedMessage}`;
playerchat.nocolor_msg = `You whisper to ${NoColorTargetName}: ${playerchat.plainMessage || playerchat.nocolor_formattedMessage}`;
playerchat.message = `You whisper to ${playerchat.targetName}: ${playerchat.plainMessage || playerchat.formattedMessage}`;
playerchat.nocolor_msg = `You whisper to ${playerchat.nocolor_targetName}: ${playerchat.plainMessage || playerchat.nocolor_formattedMessage}`;
break;
case 4: // player chat
msg = playerchat.unsignedContent;
playerchat.message = playerchat.unsignedContent;
playerchat.nocolor_msg = playerchat.nocolor_unsignedContent;
break;
case 5: // /say text
msg = `[${playerchat.senderName}] ${playerchat.plainMessage || playerchat.formattedMessage}`;
playerchat.message = `[${playerchat.senderName}] ${playerchat.plainMessage || playerchat.formattedMessage}`;
playerchat.nocolor_msg = `[${playerchat.nocolor_senderName}] ${playerchat.plainMessage || playerchat.nocolor_formattedMessage}`;
break;
case 6: // /minecraft:teammsg text
msg = `${playerchat.targetName} <${playerchat.senderName}> ${playerchat.plainMessage}`;
playerchat.nocolor_msg = `${playerchat.nocolor_targetName} <${playerchat.nocolor_senderName}> ${playerchat.plainMessage}`;
playerchat.message = `${playerchat.targetName} <${playerchat.senderName}> ${playerchat.plainMessage || playerchat.formattedMessage}`;
playerchat.nocolor_msg = `${playerchat.nocolor_targetName} <${playerchat.nocolor_senderName}> ${playerchat.plainMessage || playerchat.formattedMessage}`;
break;
default:
console.log(`Unknown player_chat packet. Type: ${playerchat.type}`);
console.log(packet);
break;
}
bot.emit('Custom_PlayerChat', msg, playerchat);
bot.emit('Custom_AllChat', msg, playerchat)
bot.emit('Custom_PlayerChat', playerchat.message, playerchat);
bot.emit('Custom_AllChat', playerchat.message, playerchat)
});
}