Create Custom Effects

Registering Custom Effects

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

EffectActivationEvent explanation

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

Example

This is an example of MULTIPLY_DAMAGE:(multiplier) effect, where the multiplier argument would be a double.
1
AEAPI.registerEffect(instance, "MULTIPLY_DAMAGE", new CustomEffect() {
2
@Override
3
public boolean onEffectActivation(EffectActivationEvent event) {
4
if(!event.getEnchantmentType().equals(AEnchantmentType.ATTACK))
5
return false;
6
if(event.getArgs().length == 0)
7
return false;
8
9
double damage = ((EntityDamageByEntityEvent) event.getEnchantmentEvent()).getDamage();
10
if(damage == 0)
11
return false;
12
13
String multiplierString = event.getArgs()[0].replaceAll("[^0-9]", "");
14
double multiplier = Double.parseDouble(multiplierString);
15
16
event.getVictim().damage(damage * multiplier, event.getAttacker());
17
return true;
18
}
19
});
Copied!
Last modified 5mo ago
Copy link