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