diff --git a/gradle.properties b/gradle.properties index 9a8f3c1..c7aaa78 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ fabric_version=0.75.1+1.19.4 # Mod Properties - mod_version = 2.1.5+1.19.4 + mod_version = 2.1.6+1.19.4 maven_group = eu.pb4 archives_base_name = styled-chat diff --git a/src/main/java/eu/pb4/styledchat/parser/LinkParser.java b/src/main/java/eu/pb4/styledchat/parser/LinkParser.java index 6907e3c..7d47677 100644 --- a/src/main/java/eu/pb4/styledchat/parser/LinkParser.java +++ b/src/main/java/eu/pb4/styledchat/parser/LinkParser.java @@ -1,14 +1,19 @@ package eu.pb4.styledchat.parser; +import eu.pb4.placeholders.api.ParserContext; import eu.pb4.placeholders.api.PlaceholderContext; import eu.pb4.placeholders.api.Placeholders; +import eu.pb4.placeholders.api.node.DirectTextNode; import eu.pb4.placeholders.api.node.LiteralNode; import eu.pb4.placeholders.api.node.TextNode; import eu.pb4.placeholders.api.node.parent.ClickActionNode; +import eu.pb4.placeholders.api.node.parent.ParentNode; import eu.pb4.placeholders.api.node.parent.ParentTextNode; import eu.pb4.placeholders.api.parsers.NodeParser; import eu.pb4.styledchat.config.ConfigManager; import net.minecraft.text.ClickEvent; +import net.minecraft.text.MutableText; +import net.minecraft.text.Style; import net.minecraft.text.Text; import java.util.ArrayList; @@ -41,7 +46,11 @@ public TextNode[] parseNodes(TextNode node) { list.add(new LiteralNode(betweenText)); } - list.add(new ClickActionNode(Placeholders.parseNodes(style, Placeholders.PREDEFINED_PLACEHOLDER_PATTERN, Map.of("link", Text.literal(matcher.group()))).getChildren(), ClickEvent.Action.OPEN_URL, new LiteralNode(matcher.group()))); + var link = matcher.group(); + + var text = style.toText(ParserContext.of(DynamicNode.NODES, Map.of("url", Text.literal(link), "link", Text.literal(link)))); + + list.add(new DirectTextNode(Text.empty().append(text).setStyle(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, link))))); currentPos = matcher.end(); } @@ -54,14 +63,14 @@ public TextNode[] parseNodes(TextNode node) { } return list.toArray(new TextNode[0]); - } else if (node instanceof ParentTextNode parentTextNode) { + } else if (node instanceof ParentNode parentNode) { var list = new ArrayList(); - for (var child : parentTextNode.getChildren()) { + for (var child : parentNode.getChildren()) { list.addAll(List.of(this.parseNodes(child))); } - return new TextNode[] { parentTextNode.copyWith(list.toArray(new TextNode[0])) }; + return new TextNode[] { parentNode.copyWith(list.toArray(new TextNode[0])) }; } return new TextNode[] { node }; diff --git a/src/main/java/eu/pb4/styledchat/parser/MentionParser.java b/src/main/java/eu/pb4/styledchat/parser/MentionParser.java index 9dfa07d..0857f4e 100644 --- a/src/main/java/eu/pb4/styledchat/parser/MentionParser.java +++ b/src/main/java/eu/pb4/styledchat/parser/MentionParser.java @@ -2,6 +2,7 @@ import eu.pb4.placeholders.api.PlaceholderContext; import eu.pb4.placeholders.api.Placeholders; +import eu.pb4.placeholders.api.node.DirectTextNode; import eu.pb4.placeholders.api.node.LiteralNode; import eu.pb4.placeholders.api.node.TextNode; import eu.pb4.placeholders.api.node.parent.ParentTextNode; @@ -43,7 +44,7 @@ public TextNode[] parseInput(String input) { if (startPos != -1) { int endPos = startPos + player.getEntityName().length(); TextNode[] before = parseInput(input.substring(0, startPos)); - TextNode mention = TextNode.convert(Placeholders.parseText(style, PlaceholderContext.of(player))); + TextNode mention = new DirectTextNode(style.toText(PlaceholderContext.of(player))); TextNode[] after = parseInput(input.substring(Math.min(endPos, input.length()))); return Stream.of(before, new TextNode[]{mention}, after).flatMap(Stream::of).toArray(TextNode[]::new); } diff --git a/src/main/java/eu/pb4/styledchat/parser/SpoilerNode.java b/src/main/java/eu/pb4/styledchat/parser/SpoilerNode.java index 0e37c8e..5c3cacf 100644 --- a/src/main/java/eu/pb4/styledchat/parser/SpoilerNode.java +++ b/src/main/java/eu/pb4/styledchat/parser/SpoilerNode.java @@ -22,12 +22,9 @@ public SpoilerNode(TextNode[] children) { protected Text applyFormatting(MutableText out, ParserContext context) { var config = ConfigManager.getConfig(); var ctx = context.get(PlaceholderContext.KEY); - var obj = ((MutableText) Placeholders.parseText(config.getSpoilerStyle(ctx), - Placeholders.PREDEFINED_PLACEHOLDER_PATTERN, - Map.of("spoiler", Text.literal(config.getSpoilerSymbole(ctx).repeat(out.getString().length()))) - )); - - return obj.setStyle(obj.getStyle().withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, out))); + var obj = config.getSpoilerStyle(ctx).toText(ctx.asParserContext() + .with(DynamicNode.NODES, Map.of("spoiler", Text.literal(config.getSpoilerSymbole(ctx).repeat(out.getString().length()))))); + return Text.empty().append(obj).setStyle(obj.getStyle().withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, out))); } @Override