Class PlaceholderAPI

java.lang.Object
net.william278.papiproxybridge.api.PlaceholderAPI

public final class PlaceholderAPI extends Object
The main API for the ProxyPlaceholderAPI plugin

Use getInstance() to get the instance of this class, then use formatPlaceholders(String, OnlineUser) to get a future that will supply the formatted text

Example:


     final PlaceholderAPI api = PlaceholderAPI.getInstance();
     final UUID player = player.getUniqueId();
     api.formatPlaceholders("Hello %player_name%!", player).thenAccept(formatted -> {
         player.sendMessage(formatted);
     });
 
  • Method Details

    • getInstance

      @Deprecated(since="1.3") @NotNull public static @NotNull PlaceholderAPI getInstance()
      Deprecated.
      Use createInstance() instead
      Get the instance of the API. This is an entry point for the API.

      Shares expiration settings with all other plugins using this instance. Prefer createInstance() for unique instance customization.

      Returns:
      An instance of the API
      Since:
      1.0
    • createInstance

      @NotNull public static @NotNull PlaceholderAPI createInstance()
      Create a new instance of PlaceholderAPI allowing unique customization of caching mechanisms
      Returns:
      PlaceholderAPI instance that can be used to format text
      Since:
      1.3
    • register

      @Internal public static void register(@NotNull @NotNull PAPIProxyBridge plugin)
      Internal only - Register the plugin with the API
      Parameters:
      plugin - The plugin to register
    • clearCache

      @Internal public static void clearCache(@NotNull @NotNull UUID player)
    • formatPlaceholders

      public CompletableFuture<String> formatPlaceholders(@NotNull @NotNull String text, @NotNull @NotNull OnlineUser requester, @NotNull @NotNull UUID formatFor)
      Format the text with the placeholders of the player

      This method accepts the unique id of a player who will be passed as the user for formatting the placeholders; distinct from the player dispatching the plugin message across the network.

      Parameters:
      text - The text to format
      requester - The player used to request the formatting
      formatFor - The player to format the text for
      Returns:
      A future that will supply the formatted text
      Since:
      1.2
    • formatPlaceholders

      public CompletableFuture<String> formatPlaceholders(@NotNull @NotNull String text, @NotNull @NotNull OnlineUser player)
      Format the text with the placeholders of the player
      Parameters:
      text - The text to format
      player - The player to format the text for
      Returns:
      A future that will supply the formatted text
      Since:
      1.0
    • formatPlaceholders

      public CompletableFuture<String> formatPlaceholders(@NotNull @NotNull String text, @NotNull @NotNull UUID requester, @NotNull @NotNull UUID formatFor)
      Format the text with the placeholders of the player

      This method accepts the unique id of a player who will be passed as the user for formatting the placeholders; distinct from the player dispatching the plugin message across the network.

      Parameters:
      text - The text to format
      requester - The unique id of the player used to request the formatting. Note that this user must be online.
      formatFor - The unique id of the player to format the text for
      Returns:
      A future that will supply the formatted text. If the requester is not online, the original text will be returned
      Since:
      1.2
    • formatPlaceholders

      public CompletableFuture<String> formatPlaceholders(@NotNull @NotNull String text, @NotNull @NotNull UUID player)
      Format the text with the placeholders of the player
      Parameters:
      text - The text to format
      player - The unique id of the player to format the text for. Note that this user must be online.
      Returns:
      A future that will supply the formatted text. If the player is not online, the original text will be returned
      Since:
      1.0
    • formatComponentPlaceholders

      public CompletableFuture<net.kyori.adventure.text.Component> formatComponentPlaceholders(@NotNull @NotNull String text, @NotNull @NotNull OnlineUser requester, @NotNull @NotNull UUID formatFor)
      Format the text with the placeholders of the player

      This method accepts the unique id of a player who will be passed as the user for formatting the placeholders; distinct from the player dispatching the plugin message across the network.

      Parameters:
      text - The text to format
      requester - The player used to request the formatting
      formatFor - The player to format the text for
      Returns:
      A future that will supply the formatted component
      Since:
      1.4
    • formatComponentPlaceholders

      public CompletableFuture<net.kyori.adventure.text.Component> formatComponentPlaceholders(@NotNull @NotNull String text, @NotNull @NotNull OnlineUser player)
      Format the text with the placeholders of the player
      Parameters:
      text - The text to format
      player - The player to format the text for
      Returns:
      A future that will supply the formatted component
      Since:
      1.4
    • formatComponentPlaceholders

      public CompletableFuture<net.kyori.adventure.text.Component> formatComponentPlaceholders(@NotNull @NotNull String text, @NotNull @NotNull UUID requester, @NotNull @NotNull UUID formatFor)
      Format the text with the placeholders of the player

      This method accepts the unique id of a player who will be passed as the user for formatting the placeholders; distinct from the player dispatching the plugin message across the network.

      Parameters:
      text - The text to format
      requester - The unique id of the player used to request the formatting. Note that this user must be online.
      formatFor - The unique id of the player to format the text for
      Returns:
      A future that will supply the formatted component. If the requester is not online, the original text will be returned
      Since:
      1.4
    • formatComponentPlaceholders

      public CompletableFuture<net.kyori.adventure.text.Component> formatComponentPlaceholders(@NotNull @NotNull String text, @NotNull @NotNull UUID player)
      Format the text with the placeholders of the player
      Parameters:
      text - The text to format
      player - The unique id of the player to format the text for. Note that this user must be online.
      Returns:
      A future that will supply the formatted component. If the player is not online, the original text will be returned
      Since:
      1.4
    • findServers

      Deprecated, for removal: This API element is subject to removal in a future version.
      Use getServers() instead
      Fetch the list of backend servers with PAPIProxyBridge installed
      Returns:
      A future that will supply the list of backend servers
      Throws:
      UnsupportedOperationException - If this method is called from a backend (Bukkit, Fabric) server
      Since:
      1.3
    • getServers

      Fetch the list of backend servers with PAPIProxyBridge installed
      Returns:
      A future that will supply the list of backend servers
      Throws:
      UnsupportedOperationException - If this method is called from a backend (Bukkit, Fabric) server
      Since:
      1.6
    • setRequestTimeout

      public void setRequestTimeout(long requestTimeout)
      Set the timeout for requesting formatting from the proxy in milliseconds. If a request is not completed within this time, the original text will be returned

      The default value is 400 milliseconds (0.4 seconds)

      Parameters:
      requestTimeout - The timeout for requesting formatting from the proxy in milliseconds
      Throws:
      IllegalArgumentException - If the timeout is negative
      Since:
      1.2
    • setCacheExpiry

      public void setCacheExpiry(long cacheExpiry)
      Set the expiry time for the cache in milliseconds

      The default value is 30000 milliseconds (30 seconds)

      Parameters:
      cacheExpiry - The expiry time for the cache in milliseconds
      Throws:
      IllegalArgumentException - If the expiry time is negative
      Since:
      1.2
    • getRequestTimeout

      public long getRequestTimeout()
      Returns the timeout for requesting formatting from the proxy in milliseconds. If a request is not completed within this time, the original text will be returned.
      Returns:
      The timeout in milliseconds
      Since:
      1.2
    • getCacheExpiry

      public long getCacheExpiry()
      Returns the expiry time for the cache in milliseconds.
      Returns:
      The expiry time for the cache in milliseconds
      Since:
      1.2
    • setRetryTimes

      public void setRetryTimes(int retryTimes)
      Set the number of times to retry formatting placeholders if the request times out

      The default value is 3

      Parameters:
      retryTimes - The number of times to retry formatting placeholders if the request times out
      Throws:
      IllegalArgumentException - If the number of retries is negative
      Since:
      1.6
    • getRetryTimes

      public int getRetryTimes()
      Returns the number of times to retry formatting placeholders if the request times out
      Returns:
      The number of times to retry formatting placeholders if the request times out
      Since:
      1.6
    • getMessengerType

      public Settings.MessengerType getMessengerType()
      Returns the messenger type
      Returns:
      The messenger type
      Since:
      1.7.3