Search in sources :

Example 1 with ExplosiveMinecart

use of org.bukkit.entity.minecart.ExplosiveMinecart in project Essentials by drtshock.

the class EssentialsProtectEntityListener method onEntityDamage.

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityDamage(final EntityDamageEvent event) {
    final Entity target = event.getEntity();
    if (target instanceof Villager && prot.getSettingBool(ProtectConfig.prevent_villager_death)) {
        event.setCancelled(true);
        return;
    }
    User user = null;
    if (target instanceof Player) {
        user = ess.getUser((Player) target);
    }
    final DamageCause cause = event.getCause();
    if (event instanceof EntityDamageByBlockEvent) {
        if (prot.getSettingBool(ProtectConfig.disable_contactdmg) && cause == DamageCause.CONTACT && !(target instanceof Player && shouldBeDamaged(user, "contact"))) {
            event.setCancelled(true);
            return;
        }
        if (prot.getSettingBool(ProtectConfig.disable_lavadmg) && cause == DamageCause.LAVA && !(target instanceof Player && shouldBeDamaged(user, "lava"))) {
            event.setCancelled(true);
            return;
        }
        if (prot.getSettingBool(ProtectConfig.prevent_tnt_explosion) && cause == DamageCause.BLOCK_EXPLOSION && !(target instanceof Player && shouldBeDamaged(user, "tnt"))) {
            event.setCancelled(true);
            return;
        }
    }
    if (event instanceof EntityDamageByEntityEvent) {
        final EntityDamageByEntityEvent edEvent = (EntityDamageByEntityEvent) event;
        final Entity eAttack = edEvent.getDamager();
        User attacker = null;
        if (eAttack instanceof Player) {
            attacker = ess.getUser((Player) eAttack);
        }
        //Creeper explode prevention
        if (eAttack instanceof Creeper && (prot.getSettingBool(ProtectConfig.prevent_creeper_explosion) || prot.getSettingBool(ProtectConfig.prevent_creeper_playerdmg)) && !(target instanceof Player && shouldBeDamaged(user, "creeper"))) {
            event.setCancelled(true);
            return;
        }
        if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball) && prot.getSettingBool(ProtectConfig.prevent_fireball_playerdmg) && !(target instanceof Player && shouldBeDamaged(user, "fireball"))) {
            event.setCancelled(true);
            return;
        }
        if (event.getEntity() instanceof WitherSkull && prot.getSettingBool(ProtectConfig.prevent_witherskull_playerdmg) && !(target instanceof Player && shouldBeDamaged(user, "witherskull"))) {
            event.setCancelled(true);
            return;
        }
        if (eAttack instanceof TNTPrimed && prot.getSettingBool(ProtectConfig.prevent_tnt_playerdmg) && !(target instanceof Player && shouldBeDamaged(user, "tnt"))) {
            event.setCancelled(true);
            return;
        }
        if (eAttack instanceof ExplosiveMinecart && prot.getSettingBool(ProtectConfig.prevent_tntminecart_playerdmg) && !(target instanceof Player && shouldBeDamaged(user, "tnt-minecart"))) {
            event.setCancelled(true);
            return;
        }
        // PVP Settings
        if (target instanceof Player && eAttack instanceof Player && prot.getSettingBool(ProtectConfig.disable_pvp) && !user.getName().equalsIgnoreCase(attacker.getName()) && (!user.isAuthorized("essentials.protect.pvp") || !attacker.isAuthorized("essentials.protect.pvp"))) {
            event.setCancelled(true);
            return;
        }
        if (edEvent.getDamager() instanceof Projectile && target instanceof Player && ((prot.getSettingBool(ProtectConfig.disable_projectiles) && !shouldBeDamaged(user, "projectiles")) || (((Projectile) edEvent.getDamager()).getShooter() instanceof Player && prot.getSettingBool(ProtectConfig.disable_pvp) && (!user.isAuthorized("essentials.protect.pvp") || !ess.getUser((Player) ((Projectile) edEvent.getDamager()).getShooter()).isAuthorized("essentials.protect.pvp"))))) {
            event.setCancelled(true);
            return;
        }
    }
    if (target instanceof Player) {
        if (cause == DamageCause.FALL && prot.getSettingBool(ProtectConfig.disable_fall) && !shouldBeDamaged(user, "fall")) {
            event.setCancelled(true);
            return;
        }
        if (cause == DamageCause.SUFFOCATION && prot.getSettingBool(ProtectConfig.disable_suffocate) && !shouldBeDamaged(user, "suffocation")) {
            event.setCancelled(true);
            return;
        }
        if ((cause == DamageCause.FIRE || cause == DamageCause.FIRE_TICK) && prot.getSettingBool(ProtectConfig.disable_firedmg) && !shouldBeDamaged(user, "fire")) {
            event.setCancelled(true);
            return;
        }
        if (cause == DamageCause.DROWNING && prot.getSettingBool(ProtectConfig.disable_drown) && !shouldBeDamaged(user, "drowning")) {
            event.setCancelled(true);
            return;
        }
        if (cause == DamageCause.LIGHTNING && prot.getSettingBool(ProtectConfig.disable_lightning) && !shouldBeDamaged(user, "lightning")) {
            event.setCancelled(true);
            return;
        }
        if (cause == DamageCause.WITHER && prot.getSettingBool(ProtectConfig.disable_wither) && !shouldBeDamaged(user, "wither")) {
            event.setCancelled(true);
        }
    }
}
Also used : ExplosiveMinecart(org.bukkit.entity.minecart.ExplosiveMinecart) User(com.earth2me.essentials.User) DamageCause(org.bukkit.event.entity.EntityDamageEvent.DamageCause) EventHandler(org.bukkit.event.EventHandler)

Aggregations

User (com.earth2me.essentials.User)1 ExplosiveMinecart (org.bukkit.entity.minecart.ExplosiveMinecart)1 EventHandler (org.bukkit.event.EventHandler)1 DamageCause (org.bukkit.event.entity.EntityDamageEvent.DamageCause)1