# Create Custom Triggers

### Using AE's API for Trigger Registration

To integrate custom triggers into the AdvancedEnchantments system, developers must utilize the `AEAPI` class from the `net.advancedplugins.ae.api` package. The crucial method in this process is `registerTrigger`, defined in the `AEAPI` class.

#### `registerTrigger` Method

{% code fullWidth="false" %}

```java
/**
* Register a new trigger.
*
* @param plugin  Plugin that is registering the trigger.
* @param trigger Trigger to register.
* @return true if the trigger was registered, false if not.
*/
public static boolean registerTrigger(JavaPlugin plugin, AdvancedTrigger trigger) { }
```

{% endcode %}

This method is pivotal for registering new triggers. It requires the plugin instance and the custom trigger as arguments. The method returns a boolean indicating the success or failure of the registration process.

### The `AdvancedTrigger` Class

To create a custom trigger, developers must extend the `AdvancedTrigger` class. This class serves as the base for all custom triggers and provides several constructors and methods to define the triggers's behavior.

The `AdvancedTrigger` class implements a bukkit Listener interface and is automatically registered in the super constructor.

All you need to do is build the execution when the trigger should be triggered. This is how an `EAT` trigger would look:

```java
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onConsume(PlayerItemConsumeEvent e) {
    Player p = e.getPlayer();

    if (p.isDead() || !p.isValid()) return;

    for (StackItem si: GetAllRollItems.getMainItems(p)) {
        executionBuilder()
            .setAttacker(p)
            .setAttackerMain(true)
            .processVariables(
                "%food type%;" + ASManager.getMaterial(e.getItem())
            )
            .setEvent(e)
            .setStackItem(si)
            .setItemType(si.getRollItemType())
            .setItem(si.getItem())
            .buildAndExecute();
    }
}
```


---

# Agent Instructions: 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:

```
GET https://ae.advancedplugins.net/for-developers/create-custom-effects-1.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
