mirror of
https://github.com/System-End/Discord-MC-Chat.git
synced 2026-04-19 16:28:23 +00:00
Enhance MinecraftMessageParser to handle underscore delimiters within Discord alias emojis
This commit is contained in:
parent
09bbe31b65
commit
241bc8d8ed
1 changed files with 26 additions and 0 deletions
|
|
@ -294,6 +294,9 @@ public final class MinecraftMessageParser {
|
|||
if (!raw.startsWith(delimiter, i)) {
|
||||
continue;
|
||||
}
|
||||
if (isUnderscoreDelimiter(delimiter) && isInsideDiscordAliasEmoji(raw, i)) {
|
||||
continue;
|
||||
}
|
||||
if (!shouldConsumeDelimiter(state, delimiter, raw, i)) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -555,6 +558,29 @@ public final class MinecraftMessageParser {
|
|||
return hasClosingDelimiter(text, at + delimiter.length(), delimiter);
|
||||
}
|
||||
|
||||
private static boolean isUnderscoreDelimiter(String delimiter) {
|
||||
return "_".equals(delimiter) || "__".equals(delimiter);
|
||||
}
|
||||
|
||||
private static boolean isInsideDiscordAliasEmoji(String text, int index) {
|
||||
if (index <= 0 || index >= text.length()) {
|
||||
return false;
|
||||
}
|
||||
int leftColon = text.lastIndexOf(':', index);
|
||||
if (leftColon < 0) {
|
||||
return false;
|
||||
}
|
||||
int rightColon = text.indexOf(':', index);
|
||||
if (rightColon < 0 || rightColon <= leftColon + 1) {
|
||||
return false;
|
||||
}
|
||||
if (index <= leftColon || index >= rightColon) {
|
||||
return false;
|
||||
}
|
||||
String candidate = text.substring(leftColon, rightColon + 1);
|
||||
return DISCORD_ALIAS_EMOJI_PATTERN.matcher(candidate).matches();
|
||||
}
|
||||
|
||||
private static boolean isDelimiterActive(MarkdownState state, String delimiter) {
|
||||
return switch (delimiter) {
|
||||
case "***" -> state.bold && state.italic;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue