PlaceHolderApi integration

Using placeholders in scripts

Method

PlaceholderAPI.parseString(player: Player, input: String): String

Parameters:

  • 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

Example:
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)
    }
})

Creating placeholders with scripts

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 an onRequest(player, params) method, which will be called whenever the placeholder is parsed

Parameter: onRequest(player: Player | null, params: String | null): String

  • player (Player | null) The player for whom the placeholder is being resolved. Can be null (e.g., if not run in a player context)

  • params (String | null) The parameter string following your prefix in the placeholder. Can also be null.

Placeholder Syntax


  • Example: %openjs_greetplr_to this server!%

    • Prefix: greetplr

    • Params: to this server!


Removing placeholders with scripts

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?