Upload files to "Player chat"
This commit is contained in:
parent
2b4bdbdf70
commit
e09c668733
2 changed files with 6291 additions and 5 deletions
|
@ -1,17 +1,39 @@
|
|||
const mc = require('minecraft-protocol');
|
||||
const lang = require("./en_us.json"); // translate message
|
||||
const ChatMessage = require('../util/ChatMessage')('1.20.4')
|
||||
|
||||
const bot = mc.createClient({
|
||||
//host: 'chipmunk.land',
|
||||
host: '95.216.192.50', //kaboom.pw
|
||||
host: 'chipmunk.land',
|
||||
//host: '95.216.192.50', //kaboom.pw
|
||||
port: 25565,
|
||||
username: 'catparser',
|
||||
version: "1.20.4",
|
||||
});
|
||||
|
||||
bot.on('player_chat', (packet) => {
|
||||
console.log(parseMinecraftMessage(packet.unsignedChatContent));
|
||||
|
||||
switch (packet.type) { // have better way? where 1 and 3 ?
|
||||
case 2:
|
||||
console.log(parseMinecraftMessage(packet.networkName) + ' whispers to you: ' + packet.plainMessage);
|
||||
break;
|
||||
case 4:
|
||||
console.log(parseMinecraftMessage(packet.unsignedChatContent));
|
||||
break;
|
||||
case 5:
|
||||
console.log(`[parseMinecraftMessage(packet.networkName)] ` + packet.plainMessage);
|
||||
break;
|
||||
case 6:
|
||||
console.log(parseMinecraftMessage(packet.networkTargetName) + ` <${parseMinecraftMessage(packet.networkName)}> ` + packet.plainMessage);
|
||||
break;
|
||||
default:
|
||||
console.log(JSON.stringify(packet, null, 2));
|
||||
console.log(`Unknown player_chat packet. Type: ${packet.type}`);
|
||||
break;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
const ansiCodes = {
|
||||
'§0': '\x1B[30m', // Black
|
||||
'§1': '\x1B[34m', // Dark Blue
|
||||
|
@ -89,7 +111,52 @@ function parseMinecraftMessage(component) {
|
|||
text += extractText(valueComp);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if (comp.translate) {
|
||||
let translateString = lang[comp.translate.value] || comp.translate.value;
|
||||
|
||||
if (typeof translateString === 'string') {
|
||||
if (comp.with) {
|
||||
const withArray = Array.isArray(comp.with.value) ? comp.with.value : [comp.with.value];
|
||||
let formattedString = translateString;
|
||||
|
||||
const replacements = [];
|
||||
|
||||
withArray.forEach((replacementText) => {
|
||||
if (replacementText.value) {
|
||||
const items = Array.isArray(replacementText.value) ? replacementText.value : [replacementText.value];
|
||||
|
||||
items.forEach((item) => {
|
||||
//console.log(item)
|
||||
const itemText = extractText(item);
|
||||
if (itemText) replacements.push(itemText);
|
||||
if (item.with && item.with.value) {
|
||||
const nestedValues = Array.isArray(item.with.value) ? item.with.value : [item.with.value];
|
||||
nestedValues.forEach(nestedItem => {
|
||||
const nestedText = extractText(nestedItem);
|
||||
if (nestedText) replacements.push(nestedText);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
let replacementIndex = 0;
|
||||
formattedString = formattedString.replace(/%s/g, () => {
|
||||
return replacementIndex < replacements.length ? replacements[replacementIndex++] : '%s';
|
||||
});
|
||||
formattedString = formattedString.replace(/%s/g, () => {
|
||||
return replacementIndex < replacements.length ? replacements[replacementIndex++] : '%s';
|
||||
});
|
||||
text += formattedString;
|
||||
} else {
|
||||
text += extractText(translateString);
|
||||
}
|
||||
} else {
|
||||
console.warn(`Translation not found for: ${comp.translate.value}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (comp.color && ansiCodes[comp.color.value]) {
|
||||
text = ansiCodes[comp.color.value] + text;
|
||||
}
|
||||
|
@ -119,5 +186,5 @@ function parseMinecraftMessage(component) {
|
|||
});
|
||||
}
|
||||
|
||||
return `Result: ${result}\x1B[0m`; // Ensure to reset colors at the end
|
||||
return `${result}\x1B[0m`; // Ensure to reset colors at the end
|
||||
}
|
6219
Player chat/en_us.json
Normal file
6219
Player chat/en_us.json
Normal file
File diff suppressed because it is too large
Load diff
Reference in a new issue