Interface Expansion.Builder
- All Superinterfaces:
AbstractBuilder<Expansion>
- Enclosing interface:
- Expansion
Example use:
Expansion.Builder builder = Expansion.builder("player"); builder // Thanks to this filter, a cast can be performed without the probability of a ClassCastException .filter(Player.class) .audiencePlaceholder("name", (audience, queue, ctx) -> Tag.selfClosingInserting(Component.text(((Player)audience).getUsername()))); Expansion expansion = builder.build();then use it:
Player player = event.getPlayer();
TagResolver resolver = expansion.audiencePlaceholder(player);
Component messageReplaced = MiniMessage.deserialize(String
, resolver);
- Since:
- 1.0.0
-
Method Summary
Modifier and TypeMethodDescription@NotNull Expansion.Builder
audiencePlaceholder
(@NotNull String key, @NotNull AudiencePlaceholder audiencePlaceholder) Adds an audience placeholder@NotNull Expansion.Builder
Filter the type of Audiences that this expansion can receive@NotNull Expansion.Builder
Filters the audiences that this expansion can receive through a Predicate@NotNull Expansion.Builder
globalPlaceholder
(@NotNull String key, @NotNull BiFunction<@NotNull ArgumentQueue, @NotNull Context, @Nullable Tag> function) Adds a global placeholder@NotNull Expansion.Builder
globalPlaceholder
(@NotNull String key, @NotNull Tag tag) Adds a global placeholder@NotNull Expansion.Builder
relationalPlaceholder
(@NotNull String key, @NotNull RelationalPlaceholder relationalPlaceholder) Adds a Relational Placeholder based on two audiencesMethods inherited from interface net.kyori.adventure.builder.AbstractBuilder
build
-
Method Details
-
audiencePlaceholder
@NotNull @NotNull Expansion.Builder audiencePlaceholder(@NotNull @NotNull String key, @NotNull @NotNull AudiencePlaceholder audiencePlaceholder) Adds an audience placeholderThis type of Placeholder depends on a specific audience to obtain its values
The content of this Placeholder is cached and can mutate depending on when it is invoked
- Parameters:
key
- the placeholder key, cannot be an empty or black stringaudiencePlaceholder
- the single placeholder- Returns:
- the
Expansion.Builder
itself - Since:
- 1.0.0
-
relationalPlaceholder
@NotNull @NotNull Expansion.Builder relationalPlaceholder(@NotNull @NotNull String key, @NotNull @NotNull RelationalPlaceholder relationalPlaceholder) Adds a Relational Placeholder based on two audiencesThis type of placeholder allows you to create components based on a 2-audiences relationship, one is the one on which the placeholder is based and the other is the one on which the placeholder is displayed.
The content of this Placeholder is cached and can mutate depending on when it is invoked
- Parameters:
key
- the placeholder key, cannot be an empty or black stringrelationalPlaceholder
- the relational placeholder- Returns:
- the
Expansion.Builder
itself - Since:
- 1.0.0
-
globalPlaceholder
@NotNull @NotNull Expansion.Builder globalPlaceholder(@NotNull @NotNull String key, @NotNull @NotNull BiFunction<@NotNull ArgumentQueue, @NotNull Context, @Nullable Tag> function) Adds a global placeholderThe content of this Placeholder is cached and can mutate depending on when it is invoked
- Parameters:
key
- the placeholder key, cannot be an empty or black stringfunction
- the function- Returns:
- the
Expansion.Builder
itself - Since:
- 1.0.0
-
globalPlaceholder
@NotNull @NotNull Expansion.Builder globalPlaceholder(@NotNull @NotNull String key, @NotNull @NotNull Tag tag) Adds a global placeholderThis placeholder is not cached and is immutable
- Parameters:
key
- the placeholder key, cannot be an empty or black stringtag
- the tag of this placeholder- Returns:
- the
Expansion.Builder
itself - Since:
- 1.1.0
-
filter
@Contract("_ -> this") @NotNull @NotNull Expansion.Builder filter(@Nullable @Nullable Class<? extends Audience> clazz) Filter the type of Audiences that this expansion can receiveIn case the
Expansion.audiencePlaceholders(Audience)
orExpansion.relationalPlaceholders(Audience, Audience)
method is called and the provided audiences are not instances of the specified class, aTagResolver.empty()
will be returnedThis eliminates the need to perform a manual
if(!(audience instanceof Player)) return TagResolver.empty();
- Parameters:
clazz
- the class to filter- Returns:
- the
Expansion.Builder
itself - Since:
- 1.0.0
-
filter
@Contract("_ -> this") @NotNull @NotNull Expansion.Builder filter(@Nullable @Nullable Predicate<@NotNull Audience> predicate) Filters the audiences that this expansion can receive through a PredicateExample:
Expansion.builder("example") .filter(aud -> aud instanceof Player player&& isInProtectedServer(player) .audiencePlaceholder("hello", (aud, queue, ctx) -> Tag.selfInsertingClosing(Component.text("you are in protected server"))) .build();
- Parameters:
predicate
- the check to realize- Returns:
- the
Expansion.Builder
itself - Since:
- 1.0.0
-