Interface PlaceholderManager


public interface PlaceholderManager
A manager interface for handling dynamic placeholders within text.

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 Type
    Method
    Description
    boolean
    edit(String oldKey, String newKey)
    Edits an existing placeholder by changing its key.
    default <T> boolean
    load(String key, Function<org.bukkit.entity.Player,T> function)
    Creates and loads a placeholder with the specified key and value provider function.
    <T> boolean
    load(Placeholder<T> placeholder)
    Loads a placeholder into the manager.
    boolean
    Removes the placeholder with the specified key from the manager.
    default String
    replace(org.bukkit.entity.Player player, String string)
    Replaces all occurrences of loaded placeholder keys in the given string with their corresponding values for the specified player.
    replace(org.bukkit.entity.Player player, String string, boolean sensitive)
    Replaces all occurrences of loaded placeholder keys in the given string with their corresponding values for the specified player.
    void
    Loads the default set of placeholders into the manager.
  • Method Details

    • load

      <T> boolean load(Placeholder<T> placeholder)
      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 - the Placeholder to load
      Returns:
      true if the placeholder was loaded successfully; false otherwise
    • load

      default <T> boolean load(String key, Function<org.bukkit.entity.Player,T> function)
      Creates and loads a placeholder with the specified key and value provider function.

      This is a convenience method that internally creates a new Placeholder instance and then loads it using load(Placeholder).

      Type Parameters:
      T - the type of the value the placeholder represents
      Parameters:
      key - the unique key identifying the placeholder
      function - a function that generates a value based on a Player
      Returns:
      true if the placeholder was loaded successfully; false otherwise
    • remove

      boolean remove(String key)
      Removes the placeholder with the specified key from the manager.
      Parameters:
      key - the key of the placeholder to remove
      Returns:
      true if the placeholder was successfully removed; false otherwise
    • edit

      boolean edit(String oldKey, String newKey)
      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 placeholder
      newKey - the new key to assign to the placeholder
      Returns:
      true if the key was successfully updated; false otherwise
    • replace

      String replace(org.bukkit.entity.Player player, String string, boolean sensitive)
      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 values
      string - the string in which to perform the replacements
      sensitive - true if the replacement should be case-sensitive; false otherwise
      Returns:
      the resulting string with all placeholder keys replaced by their computed values
    • replace

      default String replace(org.bukkit.entity.Player player, String string)
      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 values
      string - 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.