Placeholders
Placeholders can be used as arguments in actions or conditions and get evaluated before the actions/conditions do.
Creating a placeholder
To start, create a class that implements the interface RegistrablePlaceholder
.
class MyPlaceholder : RegistrablePlaceholder {
override val aliases = listOf<String>()
override fun replacedText(event: Event, trigger: RegistrableTrigger, target: TargetType, args: Map<String, String>): String? = null
}
Fill the aliases list with however you want to identify your placeholder.
The replacedText
method is the main part of the placeholder where the logic happens. You will notice that you are given:
event
- an instance of the event that has happenedtrigger
- the trigger which has activated the enchantmentargs
- the arguments supplied for the placeholdertarget
- the target supplied for the placeholder
Obtaining the target
Please refer to the actions' guide on obtaining the target and learning about TriggerDataHolders.
Using the arguments
Unlike in conditions and actions, arguments in placeholders are named, not positional. This means that instead of indexing a list, you have a map to retrieve the arguments:
Returning
In the end, you should return what the placeholder evaluates to.
Example placeholder
Built-in GamemodePlaceholder
class GamemodePlaceholder : RegistrablePlaceholder {
override val aliases = listOf(
"gamemode",
"gm",
"mode",
)
override fun replacedText(
event: Event,
trigger: RegistrableTrigger,
target: TargetType,
args: Map<String, String>
): String? {
val method = trigger.getTriggerDataHolder().dataRetrievalMethods[target.mapToDrt()] ?: return null
val player = method.invoke(event) as? Player ?: return null
return player.gameMode.name
}
}