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);
}
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)));
}
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);
}
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)));
}
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);
}
Aggregations