Package me.croabeast.takion.placeholder
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
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
ConstructorsConstructorDescriptionPlaceholder(String key, Function<org.bukkit.entity.Player, T> function) Constructs a newPlaceholderwith the specified key and value generator function.Placeholder(String key, T value) Constructs a newPlaceholderwith a constant value.Placeholder(Placeholder<T> placeholder) Copy constructor that creates a newPlaceholderbased on an existing one. -
Method Summary
Modifier and TypeMethodDescriptionReplaces all occurrences of the placeholder key in the provided string with the computed value for the given player.toString()Returns a string representation of this placeholder, including its key and sensitivity flag.
-
Constructor Details
-
Placeholder
Constructs a newPlaceholderwith 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 aPlayer- Throws:
NullPointerException- if the key is blank or the function is null
-
Placeholder
Constructs a newPlaceholderwith 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
Copy constructor that creates a newPlaceholderbased on an existing one.- Parameters:
placeholder- the placeholder to copy
-
-
Method Details
-
replace
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 computedstring- the string in which to replace the placeholder key- Returns:
- the resulting string with all placeholder keys replaced by the computed value
-
toString
Returns a string representation of this placeholder, including its key and sensitivity flag.
-