Skip to content

Conditions

Conditions get evaluated before processing actions or even levels.

Creating a condition

To start, create a class that implements the interface RegistrableCondition.

class MyCondition : RegistrableCondition {
  override val aliases = listOf<String>()

  override fun evaluateCondition(trigger: RegistrableTrigger, event: Event, target: TargetType, arguments: List<String>) = false
}

Fill the aliases list with however you want to identify your condition.

override val aliases = listOf("mycondition", "coolcondition")

The evaluateCondition method is the main part of the condition 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
  • arguments - the arguments supplied for the condition
  • target - the target supplied for the condition

Obtaining the target

Please refer to the actions' guide on obtaining the target and learning about TriggerDataHolders.

Using the arguments

Please refer to the actions' guide on using the arguments.

Returning

In the end, you should return the result of your evaluation. If the condition fails, it should return false, otherwise it should return true.

return player.isSprinting

Example condition

Built-in HardcoreCondition
class HardcoreCondition : RegistrableCondition {
  override val aliases = listOf(
    "hardcore",
    "ishardcore",
    "is-hardcore"
  )

  override fun evaluateCondition(trigger: RegistrableTrigger, event: Event, target: TargetType, arguments: List<String>): Boolean {
    val method = trigger.getTriggerDataHolder().dataRetrievalMethods[target.mapToDrt()] ?: return false
    val entity = method.invoke(event) as? Entity ?: return false
    return entity.world.isHardcore
  }
}