Update main/chatparser.js

This commit is contained in:
Yaode_owo 2024-10-12 09:27:44 -04:00
parent 130f4f4e62
commit cacadafd59

View file

@ -8,14 +8,23 @@ function uuidFromIntArray (arr) {
}
function processNbtMessage(msg) {
try { // RangeError: Maximum call stack size exceeded
if (!msg || msg.type === 'end' || msg === undefined) return undefined
const simplified = nbt.simplify(msg)
const json = JSON.stringify(simplified, (key, val) => {
if (key === 'id' && Array.isArray(val)) return uuidFromIntArray(val)
return val
})
return json
try {
if (typeof msg === 'string') { // just create simple nbt structure
msg = {
id: 'string',
value: msg
};
}
if (!msg || msg.type === 'end') return msg;
const simplified = nbt.simplify(msg); // Ensure nbt is defined elsewhere
const json = JSON.stringify(simplified, (key, val) => {
if (key === 'id' && Array.isArray(val)) return uuidFromIntArray(val);
return val;
});
return json;
} catch (e) {
return '{"text":""}';
}