EpicEnchants/src/main/java/com/craftaro/epicenchants/effect/effects/ModifyHealth.java

30 lines
1.0 KiB
Java

package com.craftaro.epicenchants.effect.effects;
import com.craftaro.epicenchants.effect.EffectExecutor;
import com.craftaro.epicenchants.enums.EventType;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class ModifyHealth extends EffectExecutor {
public ModifyHealth(ConfigurationSection section) {
super(section);
}
@Override
public void execute(@NotNull Player user, LivingEntity opponent, int level, EventType eventType) {
consume(entity -> {
double amount = getAmount().get(level, 0, user, opponent);
if (entity.getHealth() + amount > entity.getMaxHealth()) {
entity.setHealth(entity.getMaxHealth());
} else if (entity.getHealth() + amount < 0) {
entity.setHealth(0D);
} else {
entity.setHealth(entity.getHealth() + amount);
}
}, user, opponent);
}
}