Search in sources :

Example 1 with Guardian

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);
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) StackedEntity(dev.rosewood.rosestacker.stack.StackedEntity) Player(org.bukkit.entity.Player) AttributeInstance(org.bukkit.attribute.AttributeInstance) Guardian(org.bukkit.entity.Guardian) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Aggregations

StackedEntity (dev.rosewood.rosestacker.stack.StackedEntity)1 AttributeInstance (org.bukkit.attribute.AttributeInstance)1 Entity (org.bukkit.entity.Entity)1 Guardian (org.bukkit.entity.Guardian)1 LivingEntity (org.bukkit.entity.LivingEntity)1 Player (org.bukkit.entity.Player)1 Projectile (org.bukkit.entity.Projectile)1 EventHandler (org.bukkit.event.EventHandler)1