Create Custom Effects

Basic template of Custom Effect registration:
AEAPI.registerEffect(pluginInstance, "effectName", new CustomEffect() {
@Override
public boolean onEffectActivation(EffectActivationEvent event) {
return true;
}
});
Custom Effects must be registered on plugin enable.

This is an extremely powerful method. EffectActivationEvent gives you access to every essential you would need to create custom effects:
AEnchantmentType getEnchantmentType() - returns Enchant Type
Event getEnchantmentEvent() - returns original Event
String getEnchantName() - returns enchant name
LivingEntity getAttacker() - returns attacker entity
LivingEntity getVictim() - returns victim entity (may be null, depends on AEnchantmentType, if there's 2 parties involved
String[] getArgs() - returns arguments provided with effect line
LivingEntity event.getMainEntity() - returns main entity, specified by enchantments.yml effects line

This is an example of MULTIPLY_DAMAGE:(multiplier) effect, where the multiplier argument would be a double.
AEAPI.registerEffect(instance, "MULTIPLY_DAMAGE", new CustomEffect() {
@Override
public boolean onEffectActivation(EffectActivationEvent event) {
if(!event.getEnchantmentType().equals(AEnchantmentType.ATTACK))
return false;
if(event.getArgs().length == 0)
return false;
double damage = ((EntityDamageByEntityEvent) event.getEnchantmentEvent()).getDamage();
if(damage == 0)
return false;
String multiplierString = event.getArgs()[0].replaceAll("[^0-9]", "");
double multiplier = Double.parseDouble(multiplierString);
event.getVictim().damage(damage * multiplier, event.getAttacker());
return true;
}
});
Copy link
On this page