aboutsummaryrefslogtreecommitdiff
path: root/mod/src/main
diff options
context:
space:
mode:
authorsyeyoung <cyoung06@naver.com>2023-02-06 02:36:16 +0900
committersyeyoung <cyoung06@naver.com>2023-02-06 02:36:16 +0900
commitc7a5bb1d66b385d4ce2b13cdd3cd37d569ae5d2e (patch)
tree821a01496deca124607668d11e3a8ae11b3cf4d8 /mod/src/main
parent15f5e1bf9aaf9c461abd0203ad7c0fd4c5355f56 (diff)
downloadSkyblock-Dungeons-Guide-c7a5bb1d66b385d4ce2b13cdd3cd37d569ae5d2e.tar.gz
Skyblock-Dungeons-Guide-c7a5bb1d66b385d4ce2b13cdd3cd37d569ae5d2e.tar.bz2
Skyblock-Dungeons-Guide-c7a5bb1d66b385d4ce2b13cdd3cd37d569ae5d2e.zip
- Fix surgical replacer unable to handle custom character codes
Signed-off-by: syeyoung <cyoung06@naver.com>
Diffstat (limited to 'mod/src/main')
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/cosmetics/surgical/SurgicalReplacer.java108
1 files changed, 76 insertions, 32 deletions
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/cosmetics/surgical/SurgicalReplacer.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/cosmetics/surgical/SurgicalReplacer.java
index 3fdc1a79..ac0bd857 100644
--- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/cosmetics/surgical/SurgicalReplacer.java
+++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/cosmetics/surgical/SurgicalReplacer.java
@@ -33,7 +33,8 @@ public class SurgicalReplacer {
boolean strikethroughStyle = parentStyle.getStrikethrough();
boolean underlineStyle = parentStyle.getUnderlined();
boolean italicStyle = parentStyle.getItalic();
- int colorStyle = parentStyle.getColor() == null ? 15 : parentStyle.getColor().getColorIndex();
+ char possibleLastColorChar = parentStyle.getColor() == null ? 'f' : "0123456789abcdefklmnor".charAt(parentStyle.getColor().getColorIndex());
+ boolean isLegalColor = true;
char[] charArr = str.toCharArray();
List<ChatComponentText> list = new LinkedList<>();
@@ -43,33 +44,55 @@ public class SurgicalReplacer {
char c0 = charArr[i];
if (c0 == 167 && i + 1 < charArr.length) {
if (stringBuilder.length() != 0) {
- ChatComponentText chatComponents = new ChatComponentText(stringBuilder.toString());
- chatComponents.setChatStyle(new ChatStyle()
- .setBold(boldStyle)
- .setObfuscated(randomStyle)
- .setStrikethrough(strikethroughStyle)
- .setUnderlined(underlineStyle)
- .setItalic(italicStyle)
- .setColor(EnumChatFormatting.func_175744_a(colorStyle))
- .setChatHoverEvent(parentStyle.getChatHoverEvent())
- .setChatClickEvent(parentStyle.getChatClickEvent()));
- list.add(chatComponents);
- stringBuilder = new StringBuilder();
+ if (isLegalColor) {
+ ChatComponentText chatComponents = new ChatComponentText(
+ stringBuilder.toString());
+ chatComponents.setChatStyle(new ChatStyle()
+ .setBold(boldStyle)
+ .setObfuscated(randomStyle)
+ .setStrikethrough(strikethroughStyle)
+ .setUnderlined(underlineStyle)
+ .setItalic(italicStyle)
+ .setColor(EnumChatFormatting.func_175744_a("0123456789abcdefklmnor".indexOf(possibleLastColorChar)))
+ .setChatHoverEvent(parentStyle.getChatHoverEvent())
+ .setChatClickEvent(parentStyle.getChatClickEvent()));
+ list.add(chatComponents);
+ stringBuilder = new StringBuilder();
+ } else {
+ ChatComponentText chatComponents = new ChatComponentText(
+ "§"+possibleLastColorChar+
+ (randomStyle ? "§k" : "")+
+ (boldStyle ? "§l" : "")+
+ (italicStyle ? "§o" : "")+
+ (underlineStyle ? "§n" : "")+
+ (strikethroughStyle ? "§m" : "") +stringBuilder.toString());
+ chatComponents.setChatStyle(new ChatStyle()
+ .setBold(boldStyle)
+ .setObfuscated(randomStyle)
+ .setStrikethrough(strikethroughStyle)
+ .setUnderlined(underlineStyle)
+ .setItalic(italicStyle)
+ .setColor(EnumChatFormatting.WHITE)
+ .setChatHoverEvent(parentStyle.getChatHoverEvent())
+ .setChatClickEvent(parentStyle.getChatClickEvent()));
+ list.add(chatComponents);
+ stringBuilder = new StringBuilder();
+ }
}
int i1 = "0123456789abcdefklmnor".indexOf(Character.toLowerCase(charArr[i + 1]));
- if (i1 == -1) {
- stringBuilder.append(c0);
- continue;
- } else if (i1 < 16) {
+ if (i1 < 16) {
randomStyle = false;
boldStyle = false;
strikethroughStyle = false;
underlineStyle = false;
italicStyle = false;
- if (i1 < 0) {
- i1 = 15;
+ if (i1 >= 0) {
+ possibleLastColorChar = "0123456789abcdef".charAt(i1);
+ isLegalColor = true;
+ } else {
+ possibleLastColorChar = charArr[i+1];
+ isLegalColor = false;
}
- colorStyle = i1;
} else if (i1 == 16) {
randomStyle = true;
} else if (i1 == 17) {
@@ -86,7 +109,7 @@ public class SurgicalReplacer {
strikethroughStyle = false;
underlineStyle = false;
italicStyle = false;
- colorStyle = 15;
+ possibleLastColorChar = 'f';
}
++i;
@@ -94,17 +117,38 @@ public class SurgicalReplacer {
stringBuilder.append(c0);
}
}
- ChatComponentText chatComponents = new ChatComponentText(stringBuilder.toString());
- chatComponents.setChatStyle(new ChatStyle()
- .setBold(boldStyle)
- .setObfuscated(randomStyle)
- .setStrikethrough(strikethroughStyle)
- .setUnderlined(underlineStyle)
- .setItalic(italicStyle)
- .setColor(EnumChatFormatting.func_175744_a(colorStyle))
- .setChatHoverEvent(parentStyle.getChatHoverEvent())
- .setChatClickEvent(parentStyle.getChatClickEvent()));
- list.add(chatComponents);
+ if (isLegalColor) {
+ ChatComponentText chatComponents = new ChatComponentText(
+ stringBuilder.toString());
+ chatComponents.setChatStyle(new ChatStyle()
+ .setBold(boldStyle)
+ .setObfuscated(randomStyle)
+ .setStrikethrough(strikethroughStyle)
+ .setUnderlined(underlineStyle)
+ .setItalic(italicStyle)
+ .setColor(EnumChatFormatting.func_175744_a("0123456789abcdefklmnor".indexOf(possibleLastColorChar)))
+ .setChatHoverEvent(parentStyle.getChatHoverEvent())
+ .setChatClickEvent(parentStyle.getChatClickEvent()));
+ list.add(chatComponents);
+ } else {
+ ChatComponentText chatComponents = new ChatComponentText(
+ "§"+possibleLastColorChar+
+ (randomStyle ? "§k" : "")+
+ (boldStyle ? "§b" : "")+
+ (italicStyle ? "§o" : "")+
+ (underlineStyle ? "§n" : "")+
+ (strikethroughStyle ? "§m" : "") +stringBuilder.toString());
+ chatComponents.setChatStyle(new ChatStyle()
+ .setBold(boldStyle)
+ .setObfuscated(randomStyle)
+ .setStrikethrough(strikethroughStyle)
+ .setUnderlined(underlineStyle)
+ .setItalic(italicStyle)
+ .setColor(EnumChatFormatting.WHITE)
+ .setChatHoverEvent(parentStyle.getChatHoverEvent())
+ .setChatClickEvent(parentStyle.getChatClickEvent()));
+ list.add(chatComponents);
+ }
return list;
}