This commit is contained in:
Yaode_owo 2024-10-12 11:38:45 -04:00
parent 3fad481e1c
commit 17d9868ec7

View file

@ -165,20 +165,25 @@ function parseMinecraftMessage(component) {
if (comp.translate) { if (comp.translate) {
let translateString = lang[comp.translate] || comp.translate; let translateString = lang[comp.translate] || comp.translate;
if (comp.with) { if (comp.with) {
const withArgs = comp.with.map(arg => extractText(arg)); const withArgs = comp.with.map(arg => extractText(arg));
withArgs.forEach((arg, index) => { withArgs.forEach((arg, index) => {
const regex = new RegExp(`%${index + 1}\\$s`, 'g'); const regex = new RegExp(`%${index + 1}\\$s`, 'g');
if (translateString.length + formatfunction(comp, arg).length > 2048) return 'Translate Crash'; // Anti translate Crash const formattedArg = formatfunction(comp, arg);
translateString = translateString.replace(regex, formatfunction(comp, arg)); if (translateString.length + formattedArg.length > 2048) return text += 'Translate Crash';
translateString = translateString.replace(regex, formattedArg);
}); });
let usedReplacements = 0; let usedReplacements = 0;
translateString = translateString.replace(/%s/g, () => { translateString = translateString.replace(/%s/g, () => {
if (usedReplacements < withArgs.length) { if (usedReplacements < withArgs.length) {
if (translateString.length + formatfunction(comp, withArgs[usedReplacements++]).length > 2048) return 'Translate Crash'; // Anti translate Crash const formattedArg = formatfunction(comp, withArgs[usedReplacements]);
return formatfunction(comp, withArgs[usedReplacements++]); if (translateString.length + formattedArg.length > 2048) return 'Translate Crash';
usedReplacements++;
return formattedArg;
} }
return "%s"; return "%s";
}); });
@ -224,20 +229,25 @@ function parseMinecraftMessageNoColor(component) {
if (comp.translate) { if (comp.translate) {
let translateString = lang[comp.translate] || comp.translate; let translateString = lang[comp.translate] || comp.translate;
if (comp.with) { if (comp.with) {
const withArgs = comp.with.map(arg => extractText(arg)); const withArgs = comp.with.map(arg => extractText(arg));
withArgs.forEach((arg, index) => { withArgs.forEach((arg, index) => {
const regex = new RegExp(`%${index + 1}\\$s`, 'g'); const regex = new RegExp(`%${index + 1}\\$s`, 'g');
if (translateString.length + arg.length > 2048) return 'Translate Crash'; // Anti translate Crash const formattedArg = arg;
translateString = translateString.replace(regex, arg); if (translateString.length + formattedArg.length > 2048) return 'Translate Crash';
translateString = translateString.replace(regex, formattedArg);
}); });
let usedReplacements = 0; let usedReplacements = 0;
translateString = translateString.replace(/%s/g, () => { translateString = translateString.replace(/%s/g, () => {
if (usedReplacements < withArgs.length) { if (usedReplacements < withArgs.length) {
if (translateString.length + withArgs[usedReplacements++].length > 2048) return 'Translate Crash'; // Anti translate Crash const formattedArg = withArgs[usedReplacements];
return withArgs[usedReplacements++]; if (translateString.length + formattedArg.length > 2048) return 'Translate Crash';
usedReplacements++;
return formattedArg;
} }
return "%s"; return "%s";
}); });