The
PlaceholderAPI class exposes the API for formatting placeholders. At the moment, only singleton non-bracketed placeholders are supported (more in the future).
Get an instance of the class with
PlaceholderAPI.getInstance(), then use the
#formatPlaceholders method to format a string with placeholders on a player (specified with UUID for cross-platform simplicity).
The method returns a
CompletableFuture (since we don't want to lock threads while the proxy networks with players on the backend) that you can use to accept the formatted string.
Code (Java):
// Format a string with placeholders
final PlaceholderAPI api
= PlaceholderAPI.
createInstance
(
)
;
final UUID player
= player.
getUniqueId
(
)
;
api.
formatPlaceholders
(
"Hello %player_name%!", player
).
thenAccept
(formatted
->
{
player.
sendMessage
(formatted
)
;
}
)
;
Never invoke
#join() on calls to
#formatPlaceholders; this is unsafe.
PAPIProxyBridge caches resolved requests for 30000 milliseconds (30 seconds), to avoid causing excessive traffic over your server's network channels. You can adjust how long to cache requests for using the
PlaceholderAPI#setCacheExpiry(long) method.
There also exists
#formatComponentPlaceholders. This method allows you to supply a string containing placeholders and receive an adventure component containing the formatted text, which may contain formatting and chat events.