Skip to content

Commit

Permalink
probable fix for preservation of format through hover/click
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Nov 5, 2020
1 parent 6b054b3 commit e5acbbb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
Expand Up @@ -170,6 +170,10 @@ public static TextComponent copyFormatToNewText(TextComponent last) {
}

public static BaseComponent[] parse(String str) {
return parse(str, true);
}

public static BaseComponent[] parse(String str, boolean cleanBase) {
str = CoreUtilities.clearNBSPs(str);
int firstChar = str.indexOf(ChatColor.COLOR_CHAR);
if (firstChar == -1) {
Expand All @@ -179,12 +183,14 @@ public static BaseComponent[] parse(String str) {
}
TextComponent root = new TextComponent(str.substring(0, firstChar));
TextComponent base = new TextComponent();
base.setBold(false);
base.setItalic(false);
base.setStrikethrough(false);
base.setUnderlined(false);
base.setObfuscated(false);
base.setColor(ChatColor.WHITE);
if (cleanBase) {
base.setBold(false);
base.setItalic(false);
base.setStrikethrough(false);
base.setUnderlined(false);
base.setObfuscated(false);
base.setColor(ChatColor.WHITE);
}
root.addExtra(base);
str = str.substring(firstChar);
char[] chars = str.toCharArray();
Expand Down Expand Up @@ -228,7 +234,7 @@ else if (innardType.equals("translate")) {
TranslatableComponent component = new TranslatableComponent();
component.setTranslate(unescape(innardBase.get(1)));
for (String extra : innardParts) {
for (BaseComponent subComponent : parse(unescape(extra))) {
for (BaseComponent subComponent : parse(unescape(extra), false)) {
component.addWith(subComponent);
}
}
Expand All @@ -245,7 +251,7 @@ else if (innardType.equals("click") && innardParts.size() == 1) {
}
TextComponent clickableText = new TextComponent();
clickableText.setClickEvent(new ClickEvent(ClickEvent.Action.valueOf(innardBase.get(1).toUpperCase()), unescape(innardParts.get(0))));
for (BaseComponent subComponent : parse(str.substring(endBracket + 1, endIndex))) {
for (BaseComponent subComponent : parse(str.substring(endBracket + 1, endIndex), false)) {
clickableText.addExtra(subComponent);
}
lastText.addExtra(clickableText);
Expand Down Expand Up @@ -284,11 +290,11 @@ else if (action == HoverEvent.Action.SHOW_ENTITY) {
hoverValue = new BaseComponent[] {new TextComponent(NMSHandler.getEntityHelper().getRawHoverText(entity.getBukkitEntity()))};
}
else {
hoverValue = parse(unescape(innardParts.get(0)));
hoverValue = parse(unescape(innardParts.get(0)), false);
}
hoverableText.setHoverEvent(new HoverEvent(action, hoverValue));
}
for (BaseComponent subComponent : parse(str.substring(endBracket + 1, endIndex))) {
for (BaseComponent subComponent : parse(str.substring(endBracket + 1, endIndex), false)) {
hoverableText.addExtra(subComponent);
}
lastText.addExtra(hoverableText);
Expand All @@ -305,7 +311,7 @@ else if (innardType.equals("insertion")) {
}
TextComponent insertableText = new TextComponent();
insertableText.setInsertion(unescape(innardBase.get(1)));
for (BaseComponent subComponent : parse(str.substring(endBracket + 1, endIndex))) {
for (BaseComponent subComponent : parse(str.substring(endBracket + 1, endIndex), false)) {
insertableText.addExtra(subComponent);
}
lastText.addExtra(insertableText);
Expand Down Expand Up @@ -450,6 +456,6 @@ else if (i + "https://a.".length() < chars.length && chars[i] == 'h' && chars[i
if (!nextText.getText().isEmpty()) {
base.addExtra(nextText);
}
return new BaseComponent[] { root };
return new BaseComponent[] { cleanBase ? root : base };
}
}
Expand Up @@ -109,7 +109,7 @@ public void submit(CommandContext args, final CommandSender sender) throws Comma
// server will run slower while outputting debug information.
//
// There are also several options to further help debugging. To use an option, simply attach them
// to the /denizen debug command. One option, or multiple options can be used. For example: /denizen debug -ce
// to the /denizen debug command. One option, or multiple options can be used. For example: /denizen debug -sbi
//
// '-c' enables/disables color. This is sometimes useful when debugging with a non-color console.
// '-r' enables recording mode. See also: /denizen submit command
Expand Down

0 comments on commit e5acbbb

Please sign in to comment.