use of de.Keyle.MyPet.api.event.MyPetOnHitSkillEvent in project MyPet by xXKeyleXx.
the class MyPetEntityListener method onMyPetDamageMonitor.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onMyPetDamageMonitor(final EntityDamageByEntityEvent event) {
if (event.getEntity() == null) {
// catch invalid events (i.e. EnchantmentAPI)
return;
}
Entity target = event.getEntity();
if (WorldGroup.getGroupByWorld(target.getWorld()).isDisabled()) {
return;
}
if (target instanceof LivingEntity) {
Entity source = event.getDamager();
if (Configuration.LevelSystem.Experience.DAMAGE_WEIGHTED_EXPERIENCE_DISTRIBUTION && !(target instanceof Player) && !(target instanceof MyPetBukkitEntity)) {
LivingEntity livingSource = null;
if (source instanceof Projectile) {
Projectile projectile = (Projectile) source;
if (projectile.getShooter() instanceof LivingEntity) {
livingSource = (LivingEntity) projectile.getShooter();
}
} else if (source instanceof LivingEntity) {
livingSource = (LivingEntity) source;
}
if (livingSource != null) {
MyPetExperience.addDamageToEntity(livingSource, (LivingEntity) target, event.getDamage());
}
}
if (source instanceof Projectile) {
ProjectileSource projectileSource = ((Projectile) source).getShooter();
if (projectileSource instanceof Entity) {
source = (Entity) projectileSource;
}
}
if (source instanceof MyPetBukkitEntity) {
MyPet myPet = ((MyPetBukkitEntity) source).getMyPet();
if (myPet.getStatus() != PetState.Here) {
return;
}
// fix influence of other plugins for this event and throw damage event
MyPetDamageEvent petDamageEvent = new MyPetDamageEvent(myPet, target, event.getOriginalDamage(EntityDamageEvent.DamageModifier.BASE));
Bukkit.getPluginManager().callEvent(petDamageEvent);
if (petDamageEvent.isCancelled()) {
event.setCancelled(true);
return;
} else {
event.setDamage(petDamageEvent.getDamage());
}
if (!isSkillActive) {
for (Skill skill : myPet.getSkills().all()) {
if (skill instanceof OnHitSkill) {
OnHitSkill onHitSkill = (OnHitSkill) skill;
if (onHitSkill.trigger()) {
MyPetOnHitSkillEvent skillEvent = new MyPetOnHitSkillEvent(myPet, onHitSkill, (LivingEntity) target);
Bukkit.getPluginManager().callEvent(skillEvent);
if (!skillEvent.isCancelled()) {
isSkillActive = true;
onHitSkill.apply((LivingEntity) target);
isSkillActive = false;
}
}
}
}
}
}
}
}
Aggregations