Placeholder Tree offers a more maintainable way to create and manage PlaceholderAPI placeholders—and potentially any placeholder system. It allows you to group placeholders into logical sets, while transforming the provided Context as needed for each placeholder.
PlaceholderTree.builder("prisons", Function.identity()) // %prisons_
.group("stats", context -> { // %prisons_stats_
return new PrisonsContext(...);
})
.node("blocks", prisonContext -> { // %prisons_stats_blocks%
return prisonContext.getPrisonPlayer().getTotalBlocksMined();
})
.parent() // %prisons_
.group("balance", context -> { // %prisons_balance_
return new BalanceContext(...);
})
.node("btc", balanceContext -> { // %prisons_balance_btc%
return balanceContext.getPrisonPlayer().getBalance(Currency.BITCOIN);
})
.node("eth", balanceContext -> { // %prisons_balance_eth%
return balanceContext.getPrisonPlayer().getBalance(Currency.ETHEREUM);
})
.node("usd", balanceContext -> { // %prisons_balance_usd%
return balanceContext.getPrisonPlayer().getBalance(Currency.DOLLAR);
})
.build();Each tree acts essentially as a linked list. Each node contains a PlaceholderNode set, which hold this nodes complete placeholders. Each node may also contain multiple child nodes. Each node or branch also has the ability to transform the inbound context using the previous context. This allows placeholders to share data instead of each method needing to retrieve data on its own.
Add a new placeholder to the current node's set. A node is the end of the line for resolving placeholders. It is a full, complete path to retrieve data.
Add a new child node to the current node. This allows you to create a new branch in the tree, which can then have its own placeholders. The contextTransformer is used to transform the context from the parent node into a new context for this group. If this node, and it's parent share a context, Function.identity() should be used.
Return to the parent node. This allows you to create a new branch in the tree, while still being able to return to the previous node.
Build the tree. This will return a PlaceholderTree instance, which can then be used to register placeholders with PlaceholderAPI. Can be called at any level, the root node will be resolved automatically.
Allows you to create a "catch all" or * node. If no PlaceholderNode within the current branch matches the requested placeholder, this node will be used instead. This is useful for creating id or parameter fields within placeholders, similar to factions_<faction_id>_members where <faction_id> is a catch-all node, which we would attempt to resolve ourselves on each request.
- Refactor to separate Minecraft related code & the standalone library.
- Add a timed caching system, to allow faster resolving and caching results to reduce load.