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
registerTrigger
Method/**
* 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) { }
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
AdvancedTrigger
ClassTo 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:
@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();
}
}
Last updated
Was this helpful?