Repository navigation
Placeholders
This library has its own placeholders feature, allowing you to conveniently replace text blocks with data.
The pattern it uses is the following: %{placeholderId}_{args_if_supported}%
The placeholders are divided into 2 types:
- Registrable, i.e. global
- Injectable, i.e. local
There is the PlaceholderManager, which is used to save the global placeholders and format the text.
The Registrable placeholders are the ones which are automatically used in every text which you try to format.
To register it you need to:
PlaceholderManager.registerPlaceholder(RegistrablePlaceholder object)
RegistrablePlaceholder is just an interface, so, you need to create an implementation for it, or just use SimplePlaceholder and DynamicPlaceholder. In most cases you will be fine with SimplePlaceholder, but if you need a placeholder to support arguments, then use DynamicPlaceholder
Example:
new SimplePlaceholder(GTWModClient.instance,"player_level",
()-> String.valueOf(playerData.getLevel())
).register();
new SimplePlaceholder(GTWModClient.instance,"player_rank",
()-> playerData.getRank()
).register();
new SimplePlaceholder(GTWModClient.instance,"player_gang",
()-> playerData.getGang()
).register();
The second parameter is the pattern. I.e. %player_level% %player_rank% %player_gang%
It is the placeholder which is applied only if it is in a PlaceholderContext.
The PlaceholderContext contains the InjectablePlaceholderList objects.
InjectablePlaceholderList contains the Injectable placeholders.
It is made this way, to be able to implement the InjectablePlaceholderList to the classes which might be beneficial to support injectable placeholders. The Config class and DisplayRenderer are such classes
PlaceholderContext can also merge different InjectablePlaceholderList objects, it makes the injecting pretty simple.
Where is it used in a lib:



And more