PHPackages                             aiptu/libplaceholder - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. aiptu/libplaceholder

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

aiptu/libplaceholder
====================

A flexible placeholder library for PocketMine-MP plugins, allowing dynamic insertion of player and global data into messages.

1.1.0(5mo ago)11.2k1MITPHPPHP ^8.3

Since Sep 7Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/AIPTU/libplaceholder)[ Packagist](https://packagist.org/packages/aiptu/libplaceholder)[ RSS](/packages/aiptu-libplaceholder/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (3)Used By (1)

🎯 libplaceholder
================

[](#-libplaceholder)

[![PHP Version](https://camo.githubusercontent.com/ef0054230522e542bc1f908ac005c6c75888dea255bac910f9015e12095e31d7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e332d626c7565)](https://www.php.net/)[![PocketMine-MP](https://camo.githubusercontent.com/74467c4a4cd508c06d08d951de730556d031b8dbabdb287fd4e3a2e3bc5ee9e8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f506f636b65744d696e652d2d4d502d253545352e33362e302d677265656e)](https://github.com/pmmp/PocketMine-MP)[![License](https://camo.githubusercontent.com/be07a68b57a673af622198c336264f89d82bf4cd5d87bc0cb3f7b6ae47cc43ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d6c6967687467726579)](LICENSE.md)

A flexible placeholder library for PocketMine-MP plugins, allowing dynamic insertion of player and global data into messages.

✨ Features
----------

[](#-features)

- **🚀 3.75x Faster**: Optimized regex caching, fast-path checks, and match expressions
- **💎 Immutable Context**: Thread-safe design prevents accidental state mutations
- **🎨 Color Support**: Automatic TextFormat colorization with opt-out
- **📦 Extensible**: Register custom placeholder handlers with namespaced groups
- **🛡️ Production-Ready**: Input validation, exception handling, comprehensive tests
- **⚡ Zero-Allocation Parsing**: Minimal memory overhead per parse operation

📊 Performance
-------------

[](#-performance)

```
┌───────────────────────┬─────────┬─────────┬─────────────┐
│ Scenario              │ Before  │ After   │ Improvement │
├───────────────────────┼─────────┼─────────┼─────────────┤
│ Parse 10 placeholders │ 45µs    │ 12µs    │ 3.75x       │
│ Parse plain text      │ 5µs     │ 2µs     │ 2.5x        │
│ Memory (1000 parses)  │ 2.4MB   │ 2.1MB   │ -12%        │
└───────────────────────┴─────────┴─────────┴─────────────┘

```

📦 Installation
--------------

[](#-installation)

### Composer (Recommended)

[](#composer-recommended)

```
composer require aiptu/libplaceholder
```

🚀 Quick Start
-------------

[](#-quick-start)

### Basic Usage

[](#basic-usage)

```
use aiptu\libplaceholder\PlaceholderManager;
use aiptu\libplaceholder\PlaceholderContext;

// Initialize once in onEnable()
PlaceholderManager::getInstance()->init();

// Create context with player
$context = new PlaceholderContext($player);

// Parse message
$message = "Hello {player:name}! Health: {player:health}/{player:max_health}";
$parsed = PlaceholderManager::getInstance()->parsePlaceholders($message, $context);
// Result: "Hello Steve! Health: 18.50/20"
```

### Custom Data Context

[](#custom-data-context)

```
$context = new PlaceholderContext($player);
$context = $context->withData('guild', 'Warriors')
                   ->withData('rank', 'Leader')
                   ->withData('coins', 1500);

$message = "Welcome {player:name} of {guild}!{line}Rank: {rank}{line}Coins: {coins}";
$parsed = PlaceholderManager::getInstance()->parsePlaceholders($message, $context);
```

### Performance Tip: Raw Parsing

[](#performance-tip-raw-parsing)

```
// Skip TextFormat colorization for better performance
$parsed = PlaceholderManager::getInstance()->parsePlaceholdersRaw($message, $context);
```

🔧 Creating Custom Handlers
--------------------------

[](#-creating-custom-handlers)

```
use aiptu\libplaceholder\PlaceholderHandler;
use aiptu\libplaceholder\PlaceholderContext;

final class EconomyPlaceholderHandler implements PlaceholderHandler {
    public function __construct(
        private EconomyAPI $economy
    ) {}

    public function handle(string $placeholder, PlaceholderContext $context, string ...$args): string {
        $player = $context->getPlayer();
        if ($player === null) {
            return 'N/A';
        }

        return match($placeholder) {
            'money' => number_format($this->economy->myMoney($player), 2),
            'currency' => $this->economy->getCurrencySymbol(),
            'rank' => $this->economy->getRank($player),
            'top' => $this->getTopPlayer((int) ($args[0] ?? 1)),
            default => '{' . $placeholder . '}'
        };
    }

    private function getTopPlayer(int $position): string {
        // Your implementation
        return "Player#{$position}";
    }
}

// Register the handler
PlaceholderManager::getInstance()->registerHandler(
    'economy',
    new EconomyPlaceholderHandler(EconomyAPI::getInstance())
);

// Usage
$msg = "Balance: {economy:currency}{economy:money}{line}Top Player: {economy:top:1}";
```

📖 Placeholder Syntax
--------------------

[](#-placeholder-syntax)

```
{group:placeholder:arg1,arg2|fallback}

```

**Components:**

- `group` - Handler namespace (e.g., `player`, `economy`)
- `placeholder` - Specific value identifier (e.g., `name`, `health`)
- `args` - Comma-separated arguments (optional)
- `fallback` - Default value if resolution fails (optional)

**Special Placeholders:**

- `{line}` - Inserts newline character (`\n`)

**Examples:**

```
"{player:name}"                          // Simple placeholder
"{player:health:2}"                      // With precision argument
"{economy:money|0.00}"                   // With fallback
"{guild:name|No Guild}"                  // Fallback for missing data
"{player:x}, {player:y}, {player:z}"     // Multiple placeholders
```

📋 Built-in Player Placeholders
------------------------------

[](#-built-in-player-placeholders)

### Basic Information

[](#basic-information)

PlaceholderDescriptionExample`{player:name}`Username`Steve``{player:display_name}`Display name with formatting`§aSteve``{player:ip}`IP address`127.0.0.1``{player:port}`Connection port`19132``{player:ping}`Network latency (ms)`45`### Health &amp; Food

[](#health--food)

PlaceholderDescriptionExample`{player:health}`Current health (2 decimals)`18.50``{player:max_health}`Maximum health`20``{player:health_percentage}`Health as percentage`92.5``{player:food}`Food level`18``{player:max_food}`Maximum food level`20``{player:saturation}`Saturation level`5.60`### Position &amp; World

[](#position--world)

PlaceholderDescriptionExample`{player:x}`X coordinate (floor)`128``{player:y}`Y coordinate (floor)`64``{player:z}`Z coordinate (floor)`-45``{player:world}`World display name`Lobby``{player:world_folder}`World folder name`worlds/lobby`### Experience &amp; Gamemode

[](#experience--gamemode)

PlaceholderDescriptionExample`{player:xp_level}`Experience level`30``{player:xp_progress}`XP progress to next level (%)`45.2``{player:gamemode}`Gamemode name`Survival``{player:gamemode_id}`Gamemode ID`0`🏆 Acknowledgments
-----------------

[](#-acknowledgments)

Built with ❤️ by **AIPTU**

---

**Star ⭐ this repository if you find it useful!**

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance70

Regular maintenance activity

Popularity18

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~449 days

Total

2

Last Release

169d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/aa0f82ae31849fc12498a3f34c511bd347db0a2c7f5892b0cb2b5d754e0d3127?d=identicon)[AIPTU](/maintainers/AIPTU)

---

Top Contributors

[![AIPTU](https://avatars.githubusercontent.com/u/85402087?v=4)](https://github.com/AIPTU "AIPTU (6 commits)")

---

Tags

minecraftphp8placeholderapipocketmine-mp

### Embed Badge

![Health badge](/badges/aiptu-libplaceholder/health.svg)

```
[![Health](https://phpackages.com/badges/aiptu-libplaceholder/health.svg)](https://phpackages.com/packages/aiptu-libplaceholder)
```

###  Alternatives

[muqsit/invmenu

A PocketMine-MP virion to create and manage virtual inventories!

2234.2k1](/packages/muqsit-invmenu)[muqsit/simple-packet-handler

Handle specific data packets (virion for PMMP API 4.0.0)

426.1k3](/packages/muqsit-simple-packet-handler)[dktapps/pmforms

Form API library for PocketMine-MP plugins

522.3k1](/packages/dktapps-pmforms)[muqsit/asynciterator

A virion that simplifies writing tasks that traverse iterators

182.9k](/packages/muqsit-asynciterator)[tomk79/php-excel2html

Convert Excel(\*.xlsx) to HTML table. with PHPExcel.

1513.7k3](/packages/tomk79-php-excel2html)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
