Class PlaceholderAPI
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 Summary
Modifier and TypeMethodDescriptionstatic void
clearCache
(@NotNull UUID player) static @NotNull PlaceholderAPI
Create a new instance of PlaceholderAPI allowing unique customization of caching mechanismsDeprecated, for removal: This API element is subject to removal in a future version.CompletableFuture<net.kyori.adventure.text.Component>
formatComponentPlaceholders
(@NotNull String text, @NotNull UUID player) Format the text with the placeholders of the playerCompletableFuture<net.kyori.adventure.text.Component>
formatComponentPlaceholders
(@NotNull String text, @NotNull UUID requester, @NotNull UUID formatFor) Format the text with the placeholders of the playerCompletableFuture<net.kyori.adventure.text.Component>
formatComponentPlaceholders
(@NotNull String text, @NotNull OnlineUser player) Format the text with the placeholders of the playerCompletableFuture<net.kyori.adventure.text.Component>
formatComponentPlaceholders
(@NotNull String text, @NotNull OnlineUser requester, @NotNull UUID formatFor) Format the text with the placeholders of the playerformatPlaceholders
(@NotNull String text, @NotNull UUID player) Format the text with the placeholders of the playerformatPlaceholders
(@NotNull String text, @NotNull UUID requester, @NotNull UUID formatFor) Format the text with the placeholders of the playerformatPlaceholders
(@NotNull String text, @NotNull OnlineUser player) Format the text with the placeholders of the playerformatPlaceholders
(@NotNull String text, @NotNull OnlineUser requester, @NotNull UUID formatFor) Format the text with the placeholders of the playerlong
Returns the expiry time for the cache in milliseconds.static @NotNull PlaceholderAPI
Deprecated.UsecreateInstance()
insteadReturns the messenger typelong
Returns the timeout for requesting formatting from the proxy in milliseconds.int
Returns the number of times to retry formatting placeholders if the request times outFetch the list of backend servers with PAPIProxyBridge installedstatic void
register
(@NotNull PAPIProxyBridge plugin) Internal only - Register the plugin with the APIvoid
setCacheExpiry
(long cacheExpiry) Set the expiry time for the cache in millisecondsvoid
setRequestTimeout
(long requestTimeout) Set the timeout for requesting formatting from the proxy in milliseconds.void
setRetryTimes
(int retryTimes) Set the number of times to retry formatting placeholders if the request times out
-
Method Details
-
getInstance
Deprecated.UsecreateInstance()
insteadGet 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
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 only - Register the plugin with the API- Parameters:
plugin
- The plugin to register
-
clearCache
-
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 playerThis 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 formatrequester
- The player used to request the formattingformatFor
- 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 formatplayer
- 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 playerThis 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 formatrequester
- Theunique id
of the player used to request the formatting. Note that this user must be online.formatFor
- Theunique 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 formatplayer
- Theunique 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 playerThis 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 formatrequester
- The player used to request the formattingformatFor
- 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 formatplayer
- 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 playerThis 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 formatrequester
- Theunique id
of the player used to request the formatting. Note that this user must be online.formatFor
- Theunique 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 formatplayer
- Theunique 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(since="1.6", forRemoval=true) public CompletableFuture<List<String>> findServers() throws UnsupportedOperationExceptionDeprecated, for removal: This API element is subject to removal in a future version.UsegetServers()
insteadFetch 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 returnedThe 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 millisecondsThe 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 outThe 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
Returns the messenger type- Returns:
- The messenger type
- Since:
- 1.7.3
-
getServers()
instead