Search in sources :

Example 1 with Component.text

use of net.kyori.adventure.text.Component.text in project adventure by KyoriPowered.

the class ComponentCompactionBenchmark method prepare.

@Setup(Level.Trial)
public void prepare() {
    this.alreadyCompactedInput = Component.text().content("Hello World!").color(NamedTextColor.RED).append(Component.text(" aaaa", style(b -> b.color(NamedTextColor.BLUE).font(Key.key("uniform"))))).build();
    final Style simpleScenarioStyle = style().color(NamedTextColor.AQUA).font(key("uniform")).decorate(TextDecoration.BOLD, TextDecoration.ITALIC).build();
    this.simpleScenarioInput = text().content("Hello ").style(simpleScenarioStyle).append(text("World!", style(TextDecoration.BOLD).font(key("uniform")))).build();
    this.moreComplexInput = text().content("Hello ").style(style(NamedTextColor.RED, TextDecoration.BOLD, TextDecoration.OBFUSCATED)).append(text("World! ")).append(text("What a ", NamedTextColor.RED)).append(text(c -> c.content("beautiful day ").color(NamedTextColor.BLUE).append(text("to create ", style(TextDecoration.ITALIC))).append(text("a PR ", style(TextDecoration.BOLD))).append(text("on Adventure!")))).build();
}
Also used : RunnerException(org.openjdk.jmh.runner.RunnerException) Component.text(net.kyori.adventure.text.Component.text) BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) Setup(org.openjdk.jmh.annotations.Setup) Mode(org.openjdk.jmh.annotations.Mode) TextDecoration(net.kyori.adventure.text.format.TextDecoration) Scope(org.openjdk.jmh.annotations.Scope) State(org.openjdk.jmh.annotations.State) NamedTextColor(net.kyori.adventure.text.format.NamedTextColor) Benchmark(org.openjdk.jmh.annotations.Benchmark) Key.key(net.kyori.adventure.key.Key.key) Style.style(net.kyori.adventure.text.format.Style.style) TimeUnit(java.util.concurrent.TimeUnit) Style(net.kyori.adventure.text.format.Style) OptionsBuilder(org.openjdk.jmh.runner.options.OptionsBuilder) OutputTimeUnit(org.openjdk.jmh.annotations.OutputTimeUnit) Level(org.openjdk.jmh.annotations.Level) Runner(org.openjdk.jmh.runner.Runner) Options(org.openjdk.jmh.runner.options.Options) Key(net.kyori.adventure.key.Key) Style(net.kyori.adventure.text.format.Style) Setup(org.openjdk.jmh.annotations.Setup)

Example 2 with Component.text

use of net.kyori.adventure.text.Component.text in project adventure by KyoriPowered.

the class TagResolverTest method testSingleAndResolversCombine.

@Test
void testSingleAndResolversCombine() {
    final List<TagResolver> placeholders = Arrays.asList(Placeholder.component("foo", Component.text("fizz")), Placeholder.parsed("overlapping", "from list"));
    final TagResolver.WithoutArguments resolver = key -> {
        switch(key) {
            case "one":
                return Tag.preProcessParsed("fish");
            case "overlapping":
                return Tag.preProcessParsed("from resolver");
            default:
                return null;
        }
    };
    final TagResolver built = TagResolver.builder().resolvers(placeholders).resolver(resolver).build();
    // from placeholders only
    assertEquals(Component.text("fizz"), ((Inserting) resolveForTest(built, "foo")).value());
    // from resolver only
    assertEquals("fish", ((PreProcess) resolveForTest(built, "one")).value());
    // shared, resolver takes priority
    assertEquals("from resolver", ((PreProcess) resolveForTest(built, "overlapping")).value());
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Component.text(net.kyori.adventure.text.Component.text) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) ParsingException(net.kyori.adventure.text.minimessage.ParsingException) NamedTextColor(net.kyori.adventure.text.format.NamedTextColor) Test(org.junit.jupiter.api.Test) AbstractTest(net.kyori.adventure.text.minimessage.AbstractTest) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Component(net.kyori.adventure.text.Component) Context(net.kyori.adventure.text.minimessage.Context) TextColor.color(net.kyori.adventure.text.format.TextColor.color) Placeholder(net.kyori.adventure.text.minimessage.tag.resolver.Placeholder) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) NotNull(org.jetbrains.annotations.NotNull) Assertions.assertDoesNotThrow(org.junit.jupiter.api.Assertions.assertDoesNotThrow) TagResolver(net.kyori.adventure.text.minimessage.tag.resolver.TagResolver) TagResolver(net.kyori.adventure.text.minimessage.tag.resolver.TagResolver) Test(org.junit.jupiter.api.Test) AbstractTest(net.kyori.adventure.text.minimessage.AbstractTest)

Aggregations

Component.text (net.kyori.adventure.text.Component.text)2 NamedTextColor (net.kyori.adventure.text.format.NamedTextColor)2 Arrays (java.util.Arrays)1 List (java.util.List)1 TimeUnit (java.util.concurrent.TimeUnit)1 Key (net.kyori.adventure.key.Key)1 Key.key (net.kyori.adventure.key.Key.key)1 Component (net.kyori.adventure.text.Component)1 Style (net.kyori.adventure.text.format.Style)1 Style.style (net.kyori.adventure.text.format.Style.style)1 TextColor.color (net.kyori.adventure.text.format.TextColor.color)1 TextDecoration (net.kyori.adventure.text.format.TextDecoration)1 AbstractTest (net.kyori.adventure.text.minimessage.AbstractTest)1 Context (net.kyori.adventure.text.minimessage.Context)1 ParsingException (net.kyori.adventure.text.minimessage.ParsingException)1 Placeholder (net.kyori.adventure.text.minimessage.tag.resolver.Placeholder)1 TagResolver (net.kyori.adventure.text.minimessage.tag.resolver.TagResolver)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1 Assertions.assertDoesNotThrow (org.junit.jupiter.api.Assertions.assertDoesNotThrow)1