Search in sources :

Example 1 with TagResolver

use of net.kyori.adventure.text.minimessage.tag.resolver.TagResolver in project MiniPlaceholders by 4drian3d.

the class PlaceholderBenchmark method singleBench.

@Benchmark
public void singleBench() {
    Expansion.builder("single").globalPlaceholder("servername", (queue, ctx) -> Tag.selfClosingInserting(Component.text("Peruviankkit"))).build().register();
    TagResolver resolvers = MiniPlaceholders.getGlobalPlaceholders();
    MiniMessage.miniMessage().deserialize("Server name: <single-servername>", resolvers);
}
Also used : TagResolver(net.kyori.adventure.text.minimessage.tag.resolver.TagResolver) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 2 with TagResolver

use of net.kyori.adventure.text.minimessage.tag.resolver.TagResolver in project adventure by KyoriPowered.

the class MiniMessageParserTest method invalidPreprocessTagNames.

@Test
void invalidPreprocessTagNames() {
    final String input = "Some<##>of<>these<tag>are<3 >tags";
    final Component expected = Component.text("Some<##>of<>these(meow)are<3 >tags");
    final TagResolver alwaysMatchingResolver = new TagResolver() {

        @Override
        public Tag resolve(@NotNull final String name, @NotNull final ArgumentQueue arguments, @NotNull final Context ctx) throws ParsingException {
            return Tag.preProcessParsed("(meow)");
        }

        @Override
        public boolean has(@NotNull final String name) {
            return true;
        }
    };
    assertParsedEquals(expected, input, alwaysMatchingResolver);
}
Also used : TagResolver(net.kyori.adventure.text.minimessage.tag.resolver.TagResolver) Component(net.kyori.adventure.text.Component) TextComponent(net.kyori.adventure.text.TextComponent) NotNull(org.jetbrains.annotations.NotNull) ArgumentQueue(net.kyori.adventure.text.minimessage.tag.resolver.ArgumentQueue) Test(org.junit.jupiter.api.Test)

Example 3 with TagResolver

use of net.kyori.adventure.text.minimessage.tag.resolver.TagResolver in project adventure by KyoriPowered.

the class MiniMessageParserTest method testTreeOutput.

@Test
void testTreeOutput() {
    final String input = "<red> RED <blue> <name> <click:open_url:https://github.com> good <action> </click>";
    final TagResolver resolver = TagResolver.resolver(Placeholder.parsed("name", "you"), Placeholder.component("action", Component.text("click")));
    final Node tree = MiniMessage.miniMessage().deserializeToTree(input, resolver);
    final String expected = "Node {\n" + "  TagNode('red') {\n" + "    TextNode(' RED ')\n" + "    TagNode('blue') {\n" + "      TextNode(' you ')\n" + "      TagNode('click', 'open_url', 'https://github.com') {\n" + "        TextNode(' good ')\n" + "        TagNode('action') {\n" + "        }\n" + "        TextNode(' ')\n" + "      }\n" + "    }\n" + "  }\n" + "}\n";
    assertEquals(expected, tree.toString());
}
Also used : Node(net.kyori.adventure.text.minimessage.tree.Node) TagResolver(net.kyori.adventure.text.minimessage.tag.resolver.TagResolver) Test(org.junit.jupiter.api.Test)

Example 4 with TagResolver

use of net.kyori.adventure.text.minimessage.tag.resolver.TagResolver in project adventure by KyoriPowered.

the class MiniMessageTest method testCustomRegistryBuilder.

@Test
void testCustomRegistryBuilder() {
    final Component expected = empty().color(GREEN).append(text("<bold>")).append(text("TEST"));
    final String input = "<green><bold><test>";
    final TagResolver registry = TagResolver.builder().resolver(StandardTags.color()).build();
    final MiniMessage miniMessage = MiniMessage.builder().tags(registry).build();
    this.assertParsedEquals(miniMessage, expected, input, component("test", text("TEST")));
}
Also used : TagResolver(net.kyori.adventure.text.minimessage.tag.resolver.TagResolver) Component(net.kyori.adventure.text.Component) Test(org.junit.jupiter.api.Test)

Example 5 with TagResolver

use of net.kyori.adventure.text.minimessage.tag.resolver.TagResolver in project adventure by KyoriPowered.

the class MiniMessageTest method testPlaceholderComponentMixed.

@Test
void testPlaceholderComponentMixed() {
    final Component expected = empty().color(GREEN).decorate(BOLD).append(text("TEST", style(RED, UNDERLINED))).append(text("Test2"));
    final String input = "<green><bold><test><test2>";
    final MiniMessage miniMessage = MiniMessage.miniMessage();
    final TagResolver t1 = component("test", text("TEST", style(RED, UNDERLINED)));
    final TagResolver t2 = Placeholder.parsed("test2", "Test2");
    this.assertParsedEquals(miniMessage, expected, input, t1, t2);
}
Also used : TagResolver(net.kyori.adventure.text.minimessage.tag.resolver.TagResolver) Component(net.kyori.adventure.text.Component) Test(org.junit.jupiter.api.Test)

Aggregations

TagResolver (net.kyori.adventure.text.minimessage.tag.resolver.TagResolver)9 Component (net.kyori.adventure.text.Component)6 Test (org.junit.jupiter.api.Test)5 NotNull (org.jetbrains.annotations.NotNull)3 List (java.util.List)2 Token (net.kyori.adventure.text.minimessage.internal.parser.Token)2 Tag (net.kyori.adventure.text.minimessage.tag.Tag)2 Nullable (org.jetbrains.annotations.Nullable)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Objects (java.util.Objects)1 BiConsumer (java.util.function.BiConsumer)1 Consumer (java.util.function.Consumer)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 Expansion (me.dreamerzero.miniplaceholders.api.Expansion)1 MiniPlaceholders (me.dreamerzero.miniplaceholders.api.MiniPlaceholders)1 Component.text (net.kyori.adventure.text.Component.text)1 TextComponent (net.kyori.adventure.text.TextComponent)1 NamedTextColor (net.kyori.adventure.text.format.NamedTextColor)1