Interface Expansion.Builder

All Superinterfaces:
AbstractBuilder<Expansion>
Enclosing interface:
Expansion

public static interface Expansion.Builder extends AbstractBuilder<Expansion>
Expansion Builder

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 Details

    • audiencePlaceholder

      @NotNull @NotNull Expansion.Builder audiencePlaceholder(@NotNull @NotNull String key, @NotNull @NotNull AudiencePlaceholder audiencePlaceholder)
      Adds an audience placeholder

      This 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 string
      audiencePlaceholder - 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 audiences

      This 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 string
      relationalPlaceholder - 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 placeholder

      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 string
      function - 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 placeholder

      This placeholder is not cached and is immutable

      Parameters:
      key - the placeholder key, cannot be an empty or black string
      tag - 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 receive

      In case the Expansion.audiencePlaceholders(Audience) or Expansion.relationalPlaceholders(Audience, Audience) method is called and the provided audiences are not instances of the specified class, a TagResolver.empty() will be returned

      This 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 Predicate

      Example:

        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