Search in sources :

Example 1 with SmallFireball

use of org.bukkit.entity.SmallFireball in project Essentials by EssentialsX.

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;
        }
        final EntityDamageByBlockEvent edbEvent = (EntityDamageByBlockEvent) event;
        if (prot.getSettingBool(ProtectConfig.prevent_tnt_explosion) && edbEvent.getDamager() != null && edbEvent.getDamager().getType() == Material.TNT && 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_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) Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) User(com.earth2me.essentials.User) EntityDamageByBlockEvent(org.bukkit.event.entity.EntityDamageByBlockEvent) Creeper(org.bukkit.entity.Creeper) TNTPrimed(org.bukkit.entity.TNTPrimed) Projectile(org.bukkit.entity.Projectile) Fireball(org.bukkit.entity.Fireball) SmallFireball(org.bukkit.entity.SmallFireball) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) Villager(org.bukkit.entity.Villager) DamageCause(org.bukkit.event.entity.EntityDamageEvent.DamageCause) SmallFireball(org.bukkit.entity.SmallFireball) WitherSkull(org.bukkit.entity.WitherSkull) EventHandler(org.bukkit.event.EventHandler)

Example 2 with SmallFireball

use of org.bukkit.entity.SmallFireball 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;
        }
        final EntityDamageByBlockEvent edbEvent = (EntityDamageByBlockEvent) event;
        if (prot.getSettingBool(ProtectConfig.prevent_tnt_explosion) && edbEvent.getDamager() != null && edbEvent.getDamager().getType() == Material.TNT && 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_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) Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) User(com.earth2me.essentials.User) EntityDamageByBlockEvent(org.bukkit.event.entity.EntityDamageByBlockEvent) Creeper(org.bukkit.entity.Creeper) TNTPrimed(org.bukkit.entity.TNTPrimed) Projectile(org.bukkit.entity.Projectile) Fireball(org.bukkit.entity.Fireball) SmallFireball(org.bukkit.entity.SmallFireball) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) Villager(org.bukkit.entity.Villager) DamageCause(org.bukkit.event.entity.EntityDamageEvent.DamageCause) SmallFireball(org.bukkit.entity.SmallFireball) WitherSkull(org.bukkit.entity.WitherSkull) EventHandler(org.bukkit.event.EventHandler)

Example 3 with SmallFireball

use of org.bukkit.entity.SmallFireball in project EcoEnchants by Auxilor.

the class Firewand method onUse.

@Override
public boolean onUse(@NotNull final Player player, final int level, @NotNull final PlayerInteractEvent event) {
    SmallFireball fireball = player.launchProjectile(SmallFireball.class, player.getEyeLocation().getDirection().multiply(this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "velocity")));
    fireball.setIsIncendiary(this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "fire"));
    fireball.setMetadata("eco-damage", this.getPlugin().getMetadataValueFactory().create(this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage-per-level") * level));
    if (this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "no-explode")) {
        fireball.setMetadata("nobreak", this.getPlugin().getMetadataValueFactory().create(true));
    }
    fireball.setShooter(player);
    return true;
}
Also used : SmallFireball(org.bukkit.entity.SmallFireball)

Aggregations

SmallFireball (org.bukkit.entity.SmallFireball)3 User (com.earth2me.essentials.User)2 Creeper (org.bukkit.entity.Creeper)2 Entity (org.bukkit.entity.Entity)2 Fireball (org.bukkit.entity.Fireball)2 Player (org.bukkit.entity.Player)2 Projectile (org.bukkit.entity.Projectile)2 TNTPrimed (org.bukkit.entity.TNTPrimed)2 Villager (org.bukkit.entity.Villager)2 WitherSkull (org.bukkit.entity.WitherSkull)2 ExplosiveMinecart (org.bukkit.entity.minecart.ExplosiveMinecart)2 EventHandler (org.bukkit.event.EventHandler)2 EntityDamageByBlockEvent (org.bukkit.event.entity.EntityDamageByBlockEvent)2 EntityDamageByEntityEvent (org.bukkit.event.entity.EntityDamageByEntityEvent)2 DamageCause (org.bukkit.event.entity.EntityDamageEvent.DamageCause)2