Skip to content

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.

override val aliases = listOf("myplaceholder", "coolplaceholder")

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 happened
  • trigger - the trigger which has activated the enchantment
  • args - the arguments supplied for the placeholder
  • target - 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:

val distance = args["distance"]?.toDoubleOrNull() ?: return null

Returning

In the end, you should return what the placeholder evaluates to.

return player.level.toString()

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
  }
}