anti translate crash
This commit is contained in:
parent
4fab8457f6
commit
3fad481e1c
1 changed files with 10 additions and 6 deletions
|
@ -166,24 +166,25 @@ function parseMinecraftMessage(component) {
|
|||
if (comp.translate) {
|
||||
let translateString = lang[comp.translate] || comp.translate;
|
||||
if (comp.with) {
|
||||
const withArgs = comp.with.map(arg => {
|
||||
return parseMinecraftColor(comp.color) + parseMinecraftFormat(comp) + extractText(arg);
|
||||
});
|
||||
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));
|
||||
});
|
||||
|
||||
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++]);
|
||||
}
|
||||
return "%s";
|
||||
});
|
||||
}
|
||||
text += formatfunction(comp, translateString);
|
||||
|
||||
text += translateString;
|
||||
}
|
||||
|
||||
text = parseMinecraftColor(comp.color) + parseMinecraftFormat(comp) + text + ansiFormatCodes['reset'];
|
||||
|
@ -228,17 +229,20 @@ function parseMinecraftMessageNoColor(component) {
|
|||
|
||||
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);
|
||||
});
|
||||
|
||||
let usedReplacements = 0;
|
||||
translateString = translateString.replace(/%s/g, () => {
|
||||
if (usedReplacements < withArgs.length) {
|
||||
return formatfunction(comp, withArgs[usedReplacements++]);
|
||||
if (translateString.length + withArgs[usedReplacements++].length > 2048) return 'Translate Crash'; // Anti translate Crash
|
||||
return withArgs[usedReplacements++];
|
||||
}
|
||||
return "%s";
|
||||
});
|
||||
}
|
||||
|
||||
text += translateString;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue