Class Placeholder<T>

java.lang.Object
me.croabeast.takion.placeholder.Placeholder<T>
Type Parameters:
T - the type of the value to be inserted into the placeholder

public class Placeholder<T> extends Object
Represents a dynamic placeholder that can be replaced in strings with a value computed for a given player.

A Placeholder is defined by a unique key and a function that generates a value based on a Player. This value can then be substituted into any string containing the placeholder key. Optionally, the replacement can be marked as case-sensitive.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Placeholder(String key, Function<org.bukkit.entity.Player,T> function)
    Constructs a new Placeholder with the specified key and value generator function.
    Placeholder(String key, T value)
    Constructs a new Placeholder with a constant value.
    Placeholder(Placeholder<T> placeholder)
    Copy constructor that creates a new Placeholder based on an existing one.
  • Method Summary

    Modifier and Type
    Method
    Description
    replace(org.bukkit.entity.Player player, String string)
    Replaces all occurrences of the placeholder key in the provided string with the computed value for the given player.
    Returns a string representation of this placeholder, including its key and sensitivity flag.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Placeholder

      public Placeholder(String key, Function<org.bukkit.entity.Player,T> function)
      Constructs a new Placeholder with the specified key and value generator function.
      Parameters:
      key - the unique key for this placeholder (must not be blank)
      function - a function that computes the placeholder's value based on a Player
      Throws:
      NullPointerException - if the key is blank or the function is null
    • Placeholder

      public Placeholder(String key, T value)
      Constructs a new Placeholder with a constant value.

      The resulting placeholder will always return the given value, regardless of the player.

      Parameters:
      key - the unique key for this placeholder (must not be blank)
      value - the constant value to be used for replacement
      See Also:
    • Placeholder

      public Placeholder(Placeholder<T> placeholder)
      Copy constructor that creates a new Placeholder based on an existing one.
      Parameters:
      placeholder - the placeholder to copy
  • Method Details

    • replace

      public String replace(org.bukkit.entity.Player player, String string)
      Replaces all occurrences of the placeholder key in the provided string with the computed value for the given player.

      The replacement is performed using ReplaceUtils.replace(String, Object, String, boolean), which handles conversion of the value and optional case sensitivity.

      Parameters:
      player - the player for whom the value is computed
      string - the string in which to replace the placeholder key
      Returns:
      the resulting string with all placeholder keys replaced by the computed value
    • toString

      public String toString()
      Returns a string representation of this placeholder, including its key and sensitivity flag.
      Overrides:
      toString in class Object
      Returns:
      a string representation of the placeholder