> For the complete documentation index, see [llms.txt](https://ersha.gitbook.io/attributeplus-pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ersha.gitbook.io/attributeplus-pro/kai-fa-wen-dang/descriptionlinecondition.md).

# CustomTriggerComponent

请结合 [**CUSTOM**](/attributeplus-pro/shu-xing-jiao-ben/shou-ba-shou-jiao-ni-xie-shu-xing-jiao-ben/update-lei-xing-1.md) 类型属性教学页面开发

```kotlin
interface CustomTriggerComponent<E: Event> {

    //触发器名称
    val name: String
    
    //触发器事件
    val event: Class<E>
    
    //触发器事件监听优先级
    val priority: EventPriority
    
    //触发器事件是否忽略取消
    val ignoreCancelled: Boolean

    /**
     * 触发器触发条件,条件不满足时将不触发处理
     * [event] 触发器此次事件
     */
    fun condition(event: E): Boolean {
        return true
    }

    /**
     * 触发者对象传入
     * [event] 触发器此次事件
     */
    fun caster(event: E): LivingEntity

    /**
     * 目标对象传入
     * [event] 触发器此次事件
     */
    fun target(event: E): LivingEntity? {
        return null
    }

    /**
     * 触发事件相关参数传入，可在 runCustom 属性处理方法获取
     * [event] 触发器此次事件
     */
    fun params(event: E): Array<Any> {
        return emptyArray()
    }

    /* 注册触发器 */
    fun register() {
        attributeManager.registerTrigger(this)
    }
}
```

## 示例

玩家使用 **SkillAPI** 技能时触发属性，触发器名称为 "`SKILL CAST`"

```kotlin
class SkillCastAttributeTrigger : CustomTriggerComponent<PlayerCastSkillEvent> {

    override val name: String = "SKILL CAST"

    override val event: Class<PlayerCastSkillEvent> = PlayerCastSkillEvent::class.java

    override val priority: EventPriority = EventPriority.NORMAL

    override val ignoreCancelled: Boolean = false

    override fun caster(event: PlayerCastSkillEvent): LivingEntity {
        return event.player
    }

    override fun params(event: PlayerCastSkillEvent): Array<Any> {
        val skillName = event.skill.data.name
        return arrayOf(skillName)
    }

}
```

玩家使用 **SkillAPI** 技能对玩家类型的实体造成伤害时触发，触发器名称为 "`SKILL DAMAGE PLAYER`"

```kotlin
class SkillDamagePlayerAttributeTrigger : CustomTriggerComponent<SkillDamageEvent> {

    override val name: String = "SKILL DAMAGE PLAYER"

    override val event: Class<SkillDamageEvent> = SkillDamageEvent::class.java

    override val priority: EventPriority = EventPriority.NORMAL

    override val ignoreCancelled: Boolean = false

    override fun condition(event: SkillDamageEvent): Boolean {
        return event.target is Player
    }

    override fun caster(event: SkillDamageEvent): LivingEntity {
        return event.damager
    }

    override fun target(event: SkillDamageEvent): LivingEntity? {
        return event.target
    }

    override fun params(event: SkillDamageEvent): Array<Any> {
        val damage = event.damage
        val classification = event.classification
        return arrayOf(damage, classification)
    }

}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ersha.gitbook.io/attributeplus-pro/kai-fa-wen-dang/descriptionlinecondition.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
