Interface PlaceholderManager
The PlaceholderManager provides methods to load, remove, and edit placeholders,
as well as to perform placeholder replacement in strings for a given player.
Placeholders are used to dynamically inject values (such as player data or other runtime information)
into text, making it more flexible and contextual.
Typical implementations of this interface manage a collection of Placeholder instances,
allowing them to be registered or deregistered at runtime.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbooleanEdits an existing placeholder by changing its key.default <T> booleanCreates and loads a placeholder with the specified key and value provider function.<T> booleanload(Placeholder<T> placeholder) Loads a placeholder into the manager.booleanRemoves the placeholder with the specified key from the manager.default StringReplaces all occurrences of loaded placeholder keys in the given string with their corresponding values for the specified player.Replaces all occurrences of loaded placeholder keys in the given string with their corresponding values for the specified player.voidLoads the default set of placeholders into the manager.
-
Method Details
-
load
Loads a placeholder into the manager.If a placeholder with the same key already exists, the behavior should be defined by the implementation (e.g., replace the existing one or ignore the new one).
- Type Parameters:
T- the type of the value the placeholder represents- Parameters:
placeholder- thePlaceholderto load- Returns:
trueif the placeholder was loaded successfully;falseotherwise
-
load
Creates and loads a placeholder with the specified key and value provider function.This is a convenience method that internally creates a new
Placeholderinstance and then loads it usingload(Placeholder).- Type Parameters:
T- the type of the value the placeholder represents- Parameters:
key- the unique key identifying the placeholderfunction- a function that generates a value based on aPlayer- Returns:
trueif the placeholder was loaded successfully;falseotherwise
-
remove
Removes the placeholder with the specified key from the manager.- Parameters:
key- the key of the placeholder to remove- Returns:
trueif the placeholder was successfully removed;falseotherwise
-
edit
Edits an existing placeholder by changing its key.This method allows the key of a loaded placeholder to be updated. Implementations should ensure that the new key does not conflict with existing placeholders.
- Parameters:
oldKey- the current key of the placeholdernewKey- the new key to assign to the placeholder- Returns:
trueif the key was successfully updated;falseotherwise
-
replace
Replaces all occurrences of loaded placeholder keys in the given string with their corresponding values for the specified player.The replacement process takes into account the sensitivity flag to determine whether the matching should be case-sensitive.
- Parameters:
player- the player whose context is used to compute the placeholder valuesstring- the string in which to perform the replacementssensitive-trueif the replacement should be case-sensitive;falseotherwise- Returns:
- the resulting string with all placeholder keys replaced by their computed values
-
replace
Replaces all occurrences of loaded placeholder keys in the given string with their corresponding values for the specified player.This method uses a default non-sensitive mode for replacement.
- Parameters:
player- the player whose context is used to compute the placeholder valuesstring- the string in which to perform the replacements- Returns:
- the resulting string with placeholders replaced
-
setDefaults
void setDefaults()Loads the default set of placeholders into the manager.This method is intended to initialize the manager with a predefined set of placeholder values, ensuring that common placeholders are available for use.
-