Search in sources :

Example 1 with Explosive

use of org.bukkit.entity.Explosive in project RedProtect by FabioZumbi12.

the class RPEntityListener method onEntityDamage.

@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGHEST)
public void onEntityDamage(EntityDamageEvent e) {
    if (e.isCancelled()) {
        return;
    }
    Entity ent = e.getEntity();
    Region r = RedProtect.get().rm.getTopRegion(ent.getLocation());
    if (ent instanceof LivingEntity && !(ent instanceof Monster)) {
        if (r != null && r.flagExists("invincible")) {
            if (r.getFlagBool("invincible")) {
                if (ent instanceof Animals) {
                    ((Animals) ent).setTarget(null);
                }
                e.setCancelled(true);
            }
        }
    }
    if (e instanceof EntityDamageByEntityEvent) {
        EntityDamageByEntityEvent de = (EntityDamageByEntityEvent) e;
        Entity e1 = de.getEntity();
        Entity e2 = de.getDamager();
        if (e2 == null) {
            return;
        }
        RedProtect.get().logger.debug("RPEntityListener - Is EntityDamageByEntityEvent event. Damager: " + e2.getType().name());
        if (e2 instanceof Projectile) {
            Projectile a = (Projectile) e2;
            if (a.getShooter() instanceof Entity) {
                e2 = (Entity) a.getShooter();
            }
            a = null;
            if (e2 == null) {
                return;
            }
        }
        RedProtect.get().logger.debug("EntityDamageByEntityEvent event. Damager Player: " + e2.getType().name());
        RedProtect.get().logger.debug("Cause: " + de.getCause().name());
        Region r1 = RedProtect.get().rm.getTopRegion(e1.getLocation());
        Region r2 = RedProtect.get().rm.getTopRegion(e2.getLocation());
        if (de.getCause().equals(DamageCause.LIGHTNING) || de.getCause().equals(DamageCause.BLOCK_EXPLOSION) || de.getCause().equals(DamageCause.FIRE) || de.getCause().equals(DamageCause.WITHER) || de.getCause().equals(DamageCause.CUSTOM) || de.getCause().equals(DamageCause.ENTITY_EXPLOSION)) {
            if (r1 != null && !r1.canFire() && !(e2 instanceof Player)) {
                e.setCancelled(true);
                return;
            }
        }
        if (e1 instanceof Player) {
            if (e2 instanceof Player && !e1.equals(e2)) {
                Player p2 = (Player) e2;
                if (r1 != null) {
                    Material mp2 = p2.getItemInHand().getType();
                    if (RedProtect.get().version >= 190) {
                        if (p2.getInventory().getItemInMainHand() != null) {
                            mp2 = p2.getInventory().getItemInMainHand().getType();
                        } else {
                            mp2 = p2.getInventory().getItemInOffHand().getType();
                        }
                    }
                    if (mp2.equals(Material.EGG) && !r1.canProtectiles(p2)) {
                        e.setCancelled(true);
                        RPLang.sendMessage(p2, "playerlistener.region.cantuse");
                        return;
                    }
                    if (r2 != null) {
                        if (mp2.equals(Material.EGG) && !r2.canProtectiles(p2)) {
                            e.setCancelled(true);
                            RPLang.sendMessage(p2, "playerlistener.region.cantuse");
                            return;
                        }
                        if ((r1.flagExists("pvp") && !r1.canPVP((Player) e1, p2)) || (r1.flagExists("pvp") && !r2.canPVP((Player) e1, p2))) {
                            e.setCancelled(true);
                            RPLang.sendMessage(p2, "entitylistener.region.cantpvp");
                        }
                    } else if (r1.flagExists("pvp") && !r1.canPVP((Player) e1, p2)) {
                        e.setCancelled(true);
                        RPLang.sendMessage(p2, "entitylistener.region.cantpvp");
                    }
                } else if (r2 != null && r2.flagExists("pvp") && !r2.canPVP((Player) e1, p2)) {
                    e.setCancelled(true);
                    RPLang.sendMessage(p2, "entitylistener.region.cantpvp");
                }
            }
        } else if (e1 instanceof Animals || e1 instanceof Villager || e1 instanceof Golem) {
            if (r1 != null && e2 instanceof Player) {
                Player p2 = (Player) e2;
                if (!r1.canInteractPassives(p2)) {
                    e.setCancelled(true);
                    RPLang.sendMessage(p2, "entitylistener.region.cantpassive");
                }
            }
        } else if (e1 instanceof Hanging && e2 instanceof Player) {
            Player p2 = (Player) e2;
            if (r1 != null && !r1.canBuild(p2) && !r1.canBreak(e1.getType())) {
                e.setCancelled(true);
                RPLang.sendMessage(p2, "playerlistener.region.cantuse");
                return;
            }
            if (r2 != null && !r2.canBuild(p2) && !r2.canBreak(e1.getType())) {
                e.setCancelled(true);
                RPLang.sendMessage(p2, "playerlistener.region.cantuse");
            }
        } else if (e1 instanceof Hanging && e2 instanceof Monster) {
            if (r1 != null || r2 != null) {
                RedProtect.get().logger.debug("Cancelled ItemFrame drop Item");
                e.setCancelled(true);
            }
        } else if (e2 instanceof Explosive) {
            if ((r1 != null && !r1.canFire()) || (r2 != null && !r2.canFire())) {
                e.setCancelled(true);
            }
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) Material(org.bukkit.Material) Projectile(org.bukkit.entity.Projectile) LivingEntity(org.bukkit.entity.LivingEntity) Golem(org.bukkit.entity.Golem) Animals(org.bukkit.entity.Animals) Explosive(org.bukkit.entity.Explosive) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) Hanging(org.bukkit.entity.Hanging) Monster(org.bukkit.entity.Monster) Villager(org.bukkit.entity.Villager) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) EventHandler(org.bukkit.event.EventHandler)

Example 2 with Explosive

use of org.bukkit.entity.Explosive in project RedProtect by FabioZumbi12.

the class RPEntityListener method entityFire.

@EventHandler(priority = EventPriority.HIGHEST)
public void entityFire(EntityCombustByEntityEvent e) {
    Entity e1 = e.getEntity();
    Entity e2 = e.getCombuster();
    if (e2 == null) {
        return;
    }
    RedProtect.get().logger.debug("EntityCombustByEntityEvent - Is EntityCombustByEntityEvent event.");
    if (e2 instanceof Projectile) {
        Projectile a = (Projectile) e2;
        if (a.getShooter() instanceof Entity) {
            e2 = (Entity) a.getShooter();
        }
        a = null;
        if (e2 == null) {
            return;
        }
    }
    Region r1 = RedProtect.get().rm.getTopRegion(e1.getLocation());
    Region r2 = RedProtect.get().rm.getTopRegion(e2.getLocation());
    if (r1 != null && !r1.canFire() && !(e2 instanceof Player)) {
        e.setCancelled(true);
        return;
    }
    if (e1 instanceof Player) {
        if (e2 instanceof Player && !e1.equals(e2)) {
            Player p2 = (Player) e2;
            if (r1 != null) {
                if (r2 != null) {
                    if ((r1.flagExists("pvp") && !r1.canPVP((Player) e1, p2)) || (r1.flagExists("pvp") && !r2.canPVP((Player) e1, p2))) {
                        e.setCancelled(true);
                        RPLang.sendMessage(p2, "entitylistener.region.cantpvp");
                    }
                } else if (r1.flagExists("pvp") && !r1.canPVP((Player) e1, p2)) {
                    e.setCancelled(true);
                    RPLang.sendMessage(p2, "entitylistener.region.cantpvp");
                }
            } else if (r2 != null && r2.flagExists("pvp") && !r2.canPVP((Player) e1, p2)) {
                e.setCancelled(true);
                RPLang.sendMessage(p2, "entitylistener.region.cantpvp");
            }
        }
    } else if (e1 instanceof Animals || e1 instanceof Villager || e1 instanceof Golem) {
        if (r1 != null && e2 instanceof Player) {
            Player p2 = (Player) e2;
            if (!r1.canInteractPassives(p2)) {
                e.setCancelled(true);
                RPLang.sendMessage(p2, "entitylistener.region.cantpassive");
            }
        }
    } else if (e1 instanceof Hanging && e2 instanceof Player) {
        Player p2 = (Player) e2;
        if (r1 != null && !r1.canBuild(p2) && !r1.canBreak(e1.getType())) {
            e.setCancelled(true);
            RPLang.sendMessage(p2, "playerlistener.region.cantuse");
            return;
        }
        if (r2 != null && !r2.canBuild(p2) && !r2.canBreak(e1.getType())) {
            e.setCancelled(true);
            RPLang.sendMessage(p2, "playerlistener.region.cantuse");
        }
    } else if (e1 instanceof Hanging && e2 instanceof Monster) {
        if (r1 != null || r2 != null) {
            RedProtect.get().logger.debug("Cancelled ItemFrame drop Item");
            e.setCancelled(true);
        }
    } else if (e2 instanceof Explosive) {
        if ((r1 != null && !r1.canFire()) || (r2 != null && !r2.canFire())) {
            e.setCancelled(true);
        }
    }
}
Also used : Golem(org.bukkit.entity.Golem) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) Animals(org.bukkit.entity.Animals) Explosive(org.bukkit.entity.Explosive) Hanging(org.bukkit.entity.Hanging) Monster(org.bukkit.entity.Monster) Villager(org.bukkit.entity.Villager) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)2 Animals (org.bukkit.entity.Animals)2 Entity (org.bukkit.entity.Entity)2 Explosive (org.bukkit.entity.Explosive)2 Golem (org.bukkit.entity.Golem)2 Hanging (org.bukkit.entity.Hanging)2 LivingEntity (org.bukkit.entity.LivingEntity)2 Monster (org.bukkit.entity.Monster)2 Player (org.bukkit.entity.Player)2 Projectile (org.bukkit.entity.Projectile)2 Villager (org.bukkit.entity.Villager)2 EventHandler (org.bukkit.event.EventHandler)2 Material (org.bukkit.Material)1 EntityDamageByEntityEvent (org.bukkit.event.entity.EntityDamageByEntityEvent)1