PlaceholderApi
Services.get("PlaceholderApi")
Overview
API Reference
parseString()
parseString()PlaceholderAPI.parseString(player: Player, input: String): StringParameters:
player (
Player): The player for whom the placeholder should be parsed.input (
String): The string containing one or more placeholders (e.g.,%placeholder%).
Returns:
String: A copy of the input string with all placeholders replaced with their actual values.
Example:
const PlaceholderAPI = Services.get("PlaceholderApi")
registerEvent("org.bukkit.event.player.PlayerJoinEvent", {
handleEvent: function(event) {
var player = event.getPlayer()
var message = "Placeholder data: %placeholder%"
var parsedMsg = PlaceholderAPI.parseString(player, message)
player.sendMessage(parsedMsg)
}
})registerPlaceholder()
registerPlaceholder()Method: PlaceholderAPI.registerPlaceholder(prefix, listener)
prefix (
String): The unique identifier for your placeholder. It will be used in the placeholder format%openjs_<prefix>_<params>%listener (
Object): An object containing anonRequest(player, params)method, which will be called whenever the placeholder is parsed
Parameter: onRequest(player: Player, params: String): String
player (
Player) The player for whom the placeholder is being resolved. Can be null (e.g., if not run in a player context)params (
String) The parameter string following your prefix in the placeholder. Can also be null.
Placeholder Syntax
Example:
%openjs_greetplr_to this server!%Prefix:
greetplrParams:
to this server!
unregisterPlaceholder()
unregisterPlaceholder()Parameters:
prefix (
String): The unique identifier for your placeholder. It will be used in the placeholder format%openjs_<prefix>_<params>%
Last updated
Was this helpful?