Download the PHP package pup/placeholderapi without Composer
On this page you can find all versions of the php package pup/placeholderapi. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pup/placeholderapi
More information about pup/placeholderapi
Files in pup/placeholderapi
Package placeholderapi
Short Description A simple and efficient placeholder system for PocketMine-MP. Originally created for the Kyro core.
License GPL-3.0-or-later
Informations about the package placeholderapi
PlaceholderAPI
A placeholder-parsing library for PocketMine-MP plugins. Register placeholders as closures or classes, use them in messages with {identifier} or {identifier:params} syntax, and parse them with or without player context.
Installation
As a virion
Direct include
Copy src/pup/placeholderapi into your plugin's source directory.
Initialization
$manager is a static singleton. getManager() lazily initializes it if initialize() was never called, so registering a placeholder without an explicit initialize() call still works. Calling it explicitly in onEnable() doesn't change behavior, it just makes the setup order visible in your code.
Parsing
A placeholder that requires a player and is parsed without one is left as literal text ({player_name} stays as-is). Same for a :params value passed to a placeholder that doesn't support parameters.
Registering placeholders
Closures
Classes
Use PlayerPlaceholder or ServerPlaceholder when the logic is more than a couple of lines, or when you want it unit-testable independent of the registration call.
PlayerPlaceholder::process() already returns "" if $player is null, before your processPlayer() runs, so you don't need to null-check inside it.
Built-in placeholders
Player (require a player)
| Placeholder | Description | Example |
|---|---|---|
{player} / {player_name} |
Player's name | Steve |
{player_display} |
Display name | §aSteve |
{player_health} |
Current health | 20.0 |
{player_max_health} |
Max health | 20.0 |
{player_food} |
Food level | 20 |
{player_level} |
XP level | 5 |
{player_xp} |
Total XP | 250 |
{player_gamemode} |
Game mode | Survival |
{player_ping} |
Network ping | 42 |
{player_x} |
X coordinate | 123.45 |
{player_y} |
Y coordinate | 64.00 |
{player_z} |
Z coordinate | -789.12 |
{player_world} |
World name | world |
Server
| Placeholder | Description | Example |
|---|---|---|
{server_motd} |
Server MOTD | My Server |
{server_online} |
Online players | 15 |
{server_max} |
Max players | 20 |
{server_tps} |
Server TPS | 19.95 |
Colors and formatting
{black} {dark_blue} {dark_green} {dark_aqua} {dark_red} {dark_purple} {gold} {gray} {dark_gray} {blue} {green} {aqua} {red} {light_purple} {yellow} {white}
{bold} {italic} {underline} {strikethrough} {obfuscated} {reset}
Parameters
Recursion
A placeholder's return value is parsed again, so it can contain other placeholders:
Depth is capped at 10 (PlaceholderManager::MAX_RECURSION_DEPTH). Past that, whatever is left unresolved is returned as-is instead of infinitely looping. If a placeholder's process() throws, the manager catches it and returns the original {tag} unmodified rather than propagating the exception, so a broken custom placeholder won't crash whatever is sending the message. It's still worth logging inside your placeholder if you want to know it's failing.
Gradients
Other utilities
PlaceholderApi::revert($formatted)— converts a formatted string (with § codes) back into{color}placeholder tags. Useful if you store formatted strings and need to make them editable again.PlaceholderApi::stripFormatting($message)— strips all § formatting codes from a string.
Full example
Migrating from v1
v1-style calls still work unchanged:
is equivalent to:
requiresPlayer and supportsParameters default to false, so old registrations behave the same way they did before those flags existed.
Notes
- Unregister placeholders you registered in
onDisable()if your plugin can be reloaded without a full server restart, otherwise a secondonEnable()will fail to re-register them (identifiers already in use returnfalseinstead of overwriting). - Class-based placeholders are easier to unit test in isolation than closures, since you can call
processPlayer()/processServer()directly without going through the manager. - Identifiers are matched case-insensitively and stored lowercased internally.
Credits
Originally written for the Kyro core (Pupggers). Refactored in v2.0.