Search in sources :

Example 1 with Expansion

use of me.dreamerzero.miniplaceholders.api.Expansion in project MiniPlaceholders by 4drian3d.

the class PlaceholderTest method globalExpansionPlaceholderTest.

@Test
@DisplayName("Global Placeholder Test")
void globalExpansionPlaceholderTest() {
    Expansion expansion = Expansion.builder("global").globalPlaceholder("players", (queue, ctx) -> Tag.selfClosingInserting(Component.text(1305))).globalPlaceholder("servers", (queue, ctx) -> Tag.selfClosingInserting(Component.text(7))).build();
    final Component expected = Component.text("Online players: 1305 | Servers: 7");
    final Component actual = MiniMessage.miniMessage().deserialize("Online players: <global_players> | Servers: <global_servers>", expansion.globalPlaceholders());
    assertEquals(expected, actual);
}
Also used : Test(org.junit.jupiter.api.Test) Tag(net.kyori.adventure.text.minimessage.tag.Tag) MiniPlaceholders(me.dreamerzero.miniplaceholders.api.MiniPlaceholders) Audience(net.kyori.adventure.audience.Audience) PlainTextComponentSerializer(net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer) Component(net.kyori.adventure.text.Component) TestAudience(me.dreamerzero.miniplaceholders.testobjects.TestAudience) MiniMessage(net.kyori.adventure.text.minimessage.MiniMessage) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Expansion(me.dreamerzero.miniplaceholders.api.Expansion) NamedTextColor(net.kyori.adventure.text.format.NamedTextColor) DisplayName(org.junit.jupiter.api.DisplayName) Component(net.kyori.adventure.text.Component) Expansion(me.dreamerzero.miniplaceholders.api.Expansion) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 2 with Expansion

use of me.dreamerzero.miniplaceholders.api.Expansion in project MiniPlaceholders by 4drian3d.

the class PlaceholderTest method filteredExpansion.

@Test
@DisplayName("Filtered Expansion")
void filteredExpansion() {
    Expansion expansion = Expansion.builder("filter").audiencePlaceholder("name", (aud, queue, ctx) -> Tag.selfClosingInserting(Component.text(((TestAudience) aud).getName()))).filter(TestAudience.class).build();
    Audience player = new TestAudience("TestPlayer04");
    Audience emptyAudience = Audience.empty();
    String string = "Player Name: <filter_name>";
    Component playerExpected = Component.text("Player Name: TestPlayer04");
    Component emptyExpected = Component.text("Player Name: <filter_name>");
    assertEquals(playerExpected, MiniMessage.miniMessage().deserialize(string, expansion.audiencePlaceholders(player)));
    assertEquals(emptyExpected, MiniMessage.miniMessage().deserialize(string, expansion.audiencePlaceholders(emptyAudience)));
}
Also used : TestAudience(me.dreamerzero.miniplaceholders.testobjects.TestAudience) Audience(net.kyori.adventure.audience.Audience) TestAudience(me.dreamerzero.miniplaceholders.testobjects.TestAudience) Component(net.kyori.adventure.text.Component) Expansion(me.dreamerzero.miniplaceholders.api.Expansion) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with Expansion

use of me.dreamerzero.miniplaceholders.api.Expansion in project MiniPlaceholders by 4drian3d.

the class PlaceholderTest method audienceExpansionPlaceholdersTest.

@Test
@DisplayName("Audience Placeholder Test")
void audienceExpansionPlaceholdersTest() {
    TestAudience player = new TestAudience("4drian3d");
    Expansion expansion = Expansion.builder("example").audiencePlaceholder("name", (aud, queue, ctx) -> Tag.selfClosingInserting(Component.text(((TestAudience) aud).getName()))).build();
    final Component expected = Component.text("Player Name: 4drian3d");
    final Component result = MiniMessage.miniMessage().deserialize("Player Name: <example_name>", expansion.audiencePlaceholders(player));
    assertEquals(expected, result);
}
Also used : TestAudience(me.dreamerzero.miniplaceholders.testobjects.TestAudience) Test(org.junit.jupiter.api.Test) Tag(net.kyori.adventure.text.minimessage.tag.Tag) MiniPlaceholders(me.dreamerzero.miniplaceholders.api.MiniPlaceholders) Audience(net.kyori.adventure.audience.Audience) PlainTextComponentSerializer(net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer) Component(net.kyori.adventure.text.Component) TestAudience(me.dreamerzero.miniplaceholders.testobjects.TestAudience) MiniMessage(net.kyori.adventure.text.minimessage.MiniMessage) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Expansion(me.dreamerzero.miniplaceholders.api.Expansion) NamedTextColor(net.kyori.adventure.text.format.NamedTextColor) DisplayName(org.junit.jupiter.api.DisplayName) Component(net.kyori.adventure.text.Component) Expansion(me.dreamerzero.miniplaceholders.api.Expansion) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with Expansion

use of me.dreamerzero.miniplaceholders.api.Expansion in project MiniPlaceholders by 4drian3d.

the class PlaceholderTest method relationalExpansionPlaceholdersTest.

@Test
@DisplayName("Relational Placeholder Test")
void relationalExpansionPlaceholdersTest() {
    Audience p1 = new TestAudience("PlayerOne");
    Audience p2 = new TestAudience("PlayerTwo");
    Expansion expansion = Expansion.builder("relational").relationalPlaceholder("enemy", (aud, otheraud, queue, ctx) -> Tag.selfClosingInserting(this.isEnemy(((TestAudience) aud), ((TestAudience) otheraud)) ? Component.text("Enemy", NamedTextColor.RED) : Component.text("Neutral", NamedTextColor.GREEN))).build();
    assertEquals(MiniMessage.miniMessage().deserialize("You are <red>Enemy"), MiniMessage.miniMessage().deserialize("You are <relational_rel_enemy>", expansion.relationalPlaceholders(p1, p2)));
}
Also used : TestAudience(me.dreamerzero.miniplaceholders.testobjects.TestAudience) Test(org.junit.jupiter.api.Test) Tag(net.kyori.adventure.text.minimessage.tag.Tag) MiniPlaceholders(me.dreamerzero.miniplaceholders.api.MiniPlaceholders) Audience(net.kyori.adventure.audience.Audience) PlainTextComponentSerializer(net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer) Component(net.kyori.adventure.text.Component) TestAudience(me.dreamerzero.miniplaceholders.testobjects.TestAudience) MiniMessage(net.kyori.adventure.text.minimessage.MiniMessage) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Expansion(me.dreamerzero.miniplaceholders.api.Expansion) NamedTextColor(net.kyori.adventure.text.format.NamedTextColor) DisplayName(org.junit.jupiter.api.DisplayName) Audience(net.kyori.adventure.audience.Audience) TestAudience(me.dreamerzero.miniplaceholders.testobjects.TestAudience) Expansion(me.dreamerzero.miniplaceholders.api.Expansion) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 5 with Expansion

use of me.dreamerzero.miniplaceholders.api.Expansion in project MiniPlaceholders by 4drian3d.

the class PlaceholderBenchmark method placeholderBench.

@Benchmark
public void placeholderBench() {
    BenchAudience player = new BenchAudience("4drian3d");
    Expansion.Builder expansion = Expansion.builder("benchmark").audiencePlaceholder("name", (aud, queue, ctx) -> Tag.selfClosingInserting(Component.text(((BenchAudience) aud).getName()))).audiencePlaceholder("uuid", (aud, queue, ctx) -> Tag.selfClosingInserting(Component.text(((BenchAudience) aud).getUUID().toString()))).audiencePlaceholder("tablistfooter", (aud, queue, ctx) -> Tag.selfClosingInserting(Component.text("footer")));
    Expansion expansionBuilded = expansion.build();
    expansionBuilded.audiencePlaceholders(player);
    final TagResolver resolvers = MiniPlaceholders.getAudiencePlaceholders(player);
    MiniMessage.miniMessage().deserialize("Player Name: <benchmark-name>", resolvers);
}
Also used : Tag(net.kyori.adventure.text.minimessage.tag.Tag) MiniPlaceholders(me.dreamerzero.miniplaceholders.api.MiniPlaceholders) Component(net.kyori.adventure.text.Component) MiniMessage(net.kyori.adventure.text.minimessage.MiniMessage) Scope(org.openjdk.jmh.annotations.Scope) State(org.openjdk.jmh.annotations.State) Expansion(me.dreamerzero.miniplaceholders.api.Expansion) TagResolver(net.kyori.adventure.text.minimessage.tag.resolver.TagResolver) Benchmark(org.openjdk.jmh.annotations.Benchmark) TagResolver(net.kyori.adventure.text.minimessage.tag.resolver.TagResolver) Expansion(me.dreamerzero.miniplaceholders.api.Expansion) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Aggregations

Expansion (me.dreamerzero.miniplaceholders.api.Expansion)5 Component (net.kyori.adventure.text.Component)5 MiniPlaceholders (me.dreamerzero.miniplaceholders.api.MiniPlaceholders)4 TestAudience (me.dreamerzero.miniplaceholders.testobjects.TestAudience)4 Audience (net.kyori.adventure.audience.Audience)4 MiniMessage (net.kyori.adventure.text.minimessage.MiniMessage)4 Tag (net.kyori.adventure.text.minimessage.tag.Tag)4 DisplayName (org.junit.jupiter.api.DisplayName)4 Test (org.junit.jupiter.api.Test)4 NamedTextColor (net.kyori.adventure.text.format.NamedTextColor)3 PlainTextComponentSerializer (net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer)3 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)3 TagResolver (net.kyori.adventure.text.minimessage.tag.resolver.TagResolver)1 Benchmark (org.openjdk.jmh.annotations.Benchmark)1 Scope (org.openjdk.jmh.annotations.Scope)1 State (org.openjdk.jmh.annotations.State)1