Totally not minecraft code 100%.
This commit is contained in:
parent
0f7c65b5ac
commit
fc0396d9f6
2 changed files with 19 additions and 7 deletions
|
@ -5,7 +5,7 @@
|
|||
*
|
||||
* Language File Version: 1.21.3
|
||||
*
|
||||
* ChatParser Version: 1359
|
||||
* ChatParser Version: 1426
|
||||
*
|
||||
* Update:
|
||||
* - fix translate
|
||||
|
@ -533,7 +533,7 @@ const ansiMap = {
|
|||
function parseMinecraftMessage(component) {
|
||||
if (component === undefined || component === null) return undefined;
|
||||
if (typeof component !== "object") return component;
|
||||
let parts = []; // idk. but dont move it.
|
||||
let Allparts = [];
|
||||
function extractText(comp, prevColor = { color: '', have: false }, prevFormat = { format: '', have: false }) {
|
||||
let text = '';
|
||||
|
||||
|
@ -586,24 +586,28 @@ function parseMinecraftMessage(component) {
|
|||
|
||||
let usedReplacements = 0;
|
||||
let lastIndex = 0;
|
||||
let parts = [];
|
||||
|
||||
for (const match of matches) {
|
||||
if (parts.join("").length > 32768) throw new Error("TextsHasTooMuch-OOHHHMMMYYYPPPCCC");
|
||||
if (Allparts.join("").length > 32768) throw new Error("TextsHasTooMuch-OOHHHMMMYYYPPPCCC");
|
||||
let startIndex = match.index;
|
||||
|
||||
if (startIndex > lastIndex) {
|
||||
let textSegment = translateString.substring(lastIndex, startIndex);
|
||||
if (textSegment.indexOf('%') !== -1) throw new Error("UnexpectedPercentCharacterError");
|
||||
parts.push(textSegment);
|
||||
Allparts.push(textSegment);
|
||||
}
|
||||
|
||||
|
||||
if (match[2] === "%" && match[0] === "%%") {
|
||||
parts.push("%"); // For escaped %%
|
||||
Allparts.push("%");
|
||||
} else if (match[2] === "s") {
|
||||
const argIndex = match[1] !== undefined ? parseInt(match[1], 10) - 1 : usedReplacements++;
|
||||
if (argIndex < 0 || argIndex >= withArgs.length) throw new Error("InvalidPlaceholderIndexError");
|
||||
parts.push(withArgs[argIndex]);
|
||||
Allparts.push(withArgs[argIndex]);
|
||||
|
||||
} else {
|
||||
throw new Error("UnsupportedPlaceholderTypeError");
|
||||
|
@ -617,6 +621,7 @@ function parseMinecraftMessage(component) {
|
|||
let remainingText = translateString.substring(lastIndex);
|
||||
if (remainingText.indexOf('%') !== -1) throw new Error("UnmatchedTrailingPercentError");
|
||||
parts.push(remainingText);
|
||||
Allparts.push(remainingText);
|
||||
}
|
||||
translateString = parts.join("");
|
||||
}
|
||||
|
@ -647,7 +652,7 @@ function parseMinecraftMessage(component) {
|
|||
function parseMinecraftMessageNoColor(component) {
|
||||
if (component === undefined || component === null) return undefined;
|
||||
if (typeof component !== "object") return component;
|
||||
let parts = [];
|
||||
let Allparts = [];
|
||||
function extractText(comp) {
|
||||
let text = '';
|
||||
|
||||
|
@ -675,26 +680,32 @@ function parseMinecraftMessageNoColor(component) {
|
|||
|
||||
let usedReplacements = 0;
|
||||
let lastIndex = 0;
|
||||
let parts = [];
|
||||
|
||||
for (const match of matches) {
|
||||
if (parts.join("").length > 32768) throw new Error("TextsHasTooMuch-OOHHHMMMYYYPPPCCC");
|
||||
if (Allparts.join("").length > 32768) throw new Error("TextsHasTooMuch-OOHHHMMMYYYPPPCCC");
|
||||
let startIndex = match.index;
|
||||
|
||||
if (startIndex > lastIndex) {
|
||||
let textSegment = translateString.substring(lastIndex, startIndex);
|
||||
if (textSegment.indexOf('%') !== -1) throw new Error("UnexpectedPercentCharacterError");
|
||||
parts.push(textSegment);
|
||||
Allparts.push(textSegment);
|
||||
}
|
||||
|
||||
|
||||
if (match[2] === "%" && match[0] === "%%") {
|
||||
parts.push("%"); // For escaped %%
|
||||
Allparts.push("%");
|
||||
} else if (match[2] === "s") {
|
||||
const argIndex = match[1] !== undefined ? parseInt(match[1], 10) - 1 : usedReplacements++;
|
||||
if (argIndex < 0 || argIndex >= withArgs.length) throw new Error("InvalidPlaceholderIndexError");
|
||||
parts.push(withArgs[argIndex]);
|
||||
Allparts.push(withArgs[argIndex]);
|
||||
|
||||
} else {
|
||||
throw new Error("UnsupportedPlaceholderTypeError");
|
||||
throw new Error("UnsupportedPlaceholderTypeError");
|
||||
break;
|
||||
}
|
||||
|
||||
lastIndex = match.index + match[0].length;
|
||||
|
@ -704,6 +715,7 @@ function parseMinecraftMessageNoColor(component) {
|
|||
let remainingText = translateString.substring(lastIndex);
|
||||
if (remainingText.indexOf('%') !== -1) throw new Error("UnmatchedTrailingPercentError");
|
||||
parts.push(remainingText);
|
||||
Allparts.push(remainingText);
|
||||
}
|
||||
|
||||
translateString = parts.join("");
|
||||
|
|
2
main.js
2
main.js
|
@ -2,7 +2,7 @@
|
|||
* *Info in chat parser*
|
||||
*
|
||||
* Minecraft Version: 1.21.3
|
||||
* ChatParser Version: 1, 1359
|
||||
* ChatParser Version: 1, 1426
|
||||
*
|
||||
*/
|
||||
|
||||
|
|
Loading…
Reference in a new issue