1. Go to this page and download the library: Download pup/placeholderapi library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pup / placeholderapi example snippets
use pup\placeholderapi\PlaceholderApi;
public function onEnable(): void
{
PlaceholderApi::initialize();
PlaceholderApi::registerPlaceholder(...);
}
use pup\placeholderapi\PlaceholderApi;
// No player: colors and server placeholders only
$message = "{gold}Server: {server_online}/{server_max} players online";
$formatted = PlaceholderApi::parse($message);
// With player context
$message = "{green}Welcome {player_name}! Health: {player_health}";
$formatted = PlaceholderApi::parse($message, $player);
$player->sendMessage($formatted);
// Multiple messages
$messages = [
"{gold}Welcome to the server!",
"{aqua}You have {player_health} health",
"{yellow}TPS: {server_tps}"
];
$parsed = PlaceholderApi::parseMultiple($messages, $player);
use pup\placeholderapi\PlaceholderApi;
PlaceholderApi::registerPlaceholder(
"server_name",
fn(?Player $player, ?string $params): string => "My Server",
yer === null) return "0";
return (string)MyEconomy::getCoins($player);
},
esPlayer: false,
supportsParameters: true
);
use pocketmine\player\Player;
use pup\placeholderapi\PlaceholderApi;
use pup\placeholderapi\placeholder\PlayerPlaceholder;
use pup\placeholderapi\placeholder\ServerPlaceholder;
class PlayerBalancePlaceholder extends PlayerPlaceholder
{
public function __construct()
{
parent::__construct("player_balance");
}
protected function processPlayer(Player $player, ?string $params): string
{
$balance = MyEconomy::getBalance($player);
return "$" . number_format($balance, 2);
}
}
class TotalMoneyPlaceholder extends ServerPlaceholder
{
public function __construct()
{
parent::__construct("total_money");
}
protected function processServer(?string $params): string
{
return "$" . number_format(MyEconomy::getTotalMoney(), 2);
}
}
PlaceholderApi::registerCustomPlaceholder(new PlayerBalancePlaceholder());
PlaceholderApi::registerCustomPlaceholder(new TotalMoneyPlaceholder());