> For the complete documentation index, see [llms.txt](https://ae.advancedplugins.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ae.advancedplugins.net/for-developers/create-custom-effects-1.md).

# 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();
    }
}
```
