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