fix some issue

This commit is contained in:
Yaode_owo 2024-10-22 09:15:30 -04:00
parent a0093a8379
commit 6515374fa8

View file

@ -225,14 +225,15 @@ function parseMinecraftMessage(component) {
if (comp.with) { if (comp.with) {
const withArgs = comp.with.map(arg => extractText(arg)); const withArgs = comp.with.map(arg => extractText(arg));
let usedReplacements = 0; let usedReplacements = 0;
translateString = translateString.replace(/thing__placeholder__/g, 'default_thing__placeholder__'); translateString = translateString.replace(/thing__placeholder__/g, 'default_thing__placeholder__');
translateString = translateString.replace(/%s/g, (match, offset, string) => { translateString = translateString.replace(/%s/g, (match, offset, string) => {
if (offset > 0 && string[offset - 1] === '%') { if (offset > 0 && string[offset - 1] === '%') {
return 's'; return 's';
} }
if (usedReplacements < withArgs.length) { if (usedReplacements < withArgs.length) {
if (translateString.length + formatfunction(comp, withArgs[usedReplacements]).length > 2048) return 'Translate Crash'; // Prevent translate crash
return `thing__placeholder__${usedReplacements++}`; return `thing__placeholder__${usedReplacements++}`;
} }
@ -251,11 +252,12 @@ function parseMinecraftMessage(component) {
if (stringindex > 0 && string[stringindex - 1] === '%') { if (stringindex > 0 && string[stringindex - 1] === '%') {
return match; return match;
} }
if (translateString.length + formatfunction(comp, withArgs[argIndex]).length > 2048) return 'Translate Crash'; // Prevent translate crash
return `thing__placeholder__${argIndex}`; return `thing__placeholder__${argIndex}`;
}); });
for (let i = 0; i < withArgs.length; i++) { for (let i = 0; i < withArgs.length; i++) {
if (translateString.length + formatfunction(comp, withArgs[i]).length > 2048) return 'Translate Crash'; // Prevent translate crash
translateString = translateString.replace(new RegExp(`thing__placeholder__${i}`, 'g'), (match) => { translateString = translateString.replace(new RegExp(`thing__placeholder__${i}`, 'g'), (match) => {
const formattedArg = formatfunction(comp, withArgs[i]); const formattedArg = formatfunction(comp, withArgs[i]);
return formattedArg; return formattedArg;
@ -318,6 +320,7 @@ function parseMinecraftMessageNoColor(component) {
} }
if (usedReplacements < withArgs.length) { if (usedReplacements < withArgs.length) {
if (translateString.length + withArgs[usedReplacements].length > 2048) return 'Translate Crash'; // Prevent translate crash
return `thing__placeholder__${usedReplacements++}`; return `thing__placeholder__${usedReplacements++}`;
} }
@ -336,11 +339,13 @@ function parseMinecraftMessageNoColor(component) {
if (stringindex > 0 && string[stringindex - 1] === '%') { if (stringindex > 0 && string[stringindex - 1] === '%') {
return match; return match;
} }
if (translateString.length + withArgs[argIndex].length > 2048) return 'Translate Crash'; // Prevent translate crash
return `thing__placeholder__${argIndex}`; return `thing__placeholder__${argIndex}`;
}); });
for (let i = 0; i < withArgs.length; i++) { for (let i = 0; i < withArgs.length; i++) {
if (translateString.length + withArgs[i].length > 2048) return 'Translate Crash'; // Prevent translate crash
translateString = translateString.replace(new RegExp(`thing__placeholder__${i}`, 'g'), (match) => { translateString = translateString.replace(new RegExp(`thing__placeholder__${i}`, 'g'), (match) => {
const formattedArg = withArgs[i]; const formattedArg = withArgs[i];
return formattedArg; return formattedArg;