use of org.bukkit.entity.Guardian in project RoseStacker by Rosewood-Development.
the class EntityListener method onEntityDamageByEntity.
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
// Prevent guardians with disabled AI from spiking their attacker
if (event.getEntity().getType() == EntityType.PLAYER && event.getDamager() instanceof Guardian && PersistentDataUtils.isAiDisabled((Guardian) event.getDamager())) {
event.setCancelled(true);
}
if (!(event.getEntity() instanceof LivingEntity) || event.getEntity().getType() == EntityType.PLAYER)
return;
LivingEntity entity = (LivingEntity) event.getEntity();
if (!Setting.ENTITY_INSTANT_KILL_DISABLED_AI.getBoolean() || this.stackManager.isWorldDisabled(entity.getWorld()) || !PersistentDataUtils.isAiDisabled(entity))
return;
Entity damager = event.getDamager();
if (damager instanceof Projectile) {
Projectile projectile = (Projectile) damager;
if (!(projectile.getShooter() instanceof Player))
return;
} else if (!(damager instanceof Player)) {
return;
}
AttributeInstance attributeInstance = entity.getAttribute(Attribute.GENERIC_MAX_HEALTH);
if (attributeInstance != null) {
event.setDamage(attributeInstance.getValue() * 2);
} else {
event.setDamage(entity.getHealth() * 2);
}
}
Aggregations