Search in sources :

Example 1 with Monster

use of org.bukkit.entity.Monster in project Parties by AlessioDP.

the class FightListener method onEntityDieKill.

@EventHandler
public void onEntityDieKill(EntityDeathEvent event) {
    if (event.getEntity().getKiller() instanceof Player) {
        Player killer = event.getEntity().getKiller();
        PartyPlayerEntity ppKiller = plugin.getPlayerManager().getPlayer(killer.getUniqueId());
        if (!ppKiller.getPartyName().isEmpty()) {
            PartyEntity party = plugin.getPartyManager().getParty(ppKiller.getPartyName());
            if (ConfigParties.KILLS_ENABLE) {
                boolean gotKill = false;
                if (ConfigParties.KILLS_MOB_HOSTILE && event.getEntity() instanceof Monster)
                    gotKill = true;
                else if (ConfigParties.KILLS_MOB_NEUTRAL && event.getEntity() instanceof Animals)
                    gotKill = true;
                else if (ConfigParties.KILLS_MOB_PLAYERS && event.getEntity() instanceof Player)
                    gotKill = true;
                if (gotKill) {
                    party.setKills(party.getKills() + 1);
                    party.updateParty();
                    LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_KILL_ADD.replace("{party}", party.getName()).replace("{player}", killer.getName()), true);
                }
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) Animals(org.bukkit.entity.Animals) Monster(org.bukkit.entity.Monster) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity) EventHandler(org.bukkit.event.EventHandler)

Example 2 with Monster

use of org.bukkit.entity.Monster in project Spirits by xNuminousx.

the class Infest method infestEntities.

public void infestEntities(Entity entity) {
    if (new Random().nextInt(effectInt) == 0) {
        if (entity instanceof Player) {
            Player ePlayer = (Player) entity;
            BendingPlayer bEntity = BendingPlayer.getBendingPlayer(ePlayer);
            if (bEntity.hasElement(Element.getElement("DarkSpirit")) && healDarkSpirits) {
                LivingEntity le = (LivingEntity) entity;
                le.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 120, 1));
                ParticleEffect.HEART.display(entity.getLocation().add(0, 2, 0), 0, 0, 0, 0, 1);
            }
        } else if (entity instanceof Monster) {
            LivingEntity le = (LivingEntity) entity;
            le.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 120, 1));
            ParticleEffect.ANGRY_VILLAGER.display(entity.getLocation().add(0, 1, 0), 0, 0, 0, 0, 1);
        } else if (entity instanceof LivingEntity && damageEntities) {
            DamageHandler.damageEntity(entity, damage, this);
            ParticleEffect.PORTAL.display(entity.getLocation().add(0, 1, 0), 0, 0, 0, 1.5F, 5);
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) BendingPlayer(com.projectkorra.projectkorra.BendingPlayer) BendingPlayer(com.projectkorra.projectkorra.BendingPlayer) Player(org.bukkit.entity.Player) Random(java.util.Random) PotionEffect(org.bukkit.potion.PotionEffect) Monster(org.bukkit.entity.Monster)

Example 3 with Monster

use of org.bukkit.entity.Monster 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 4 with Monster

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

the class RPEntityListener method onCreatureSpawn.

@EventHandler
public void onCreatureSpawn(CreatureSpawnEvent event) {
    if (event.isCancelled()) {
        return;
    }
    Entity e = event.getEntity();
    if (e == null) {
        return;
    }
    RedProtect.get().logger.debug("Spawn monster " + event.getEntityType().name());
    if (e instanceof Wither && event.getSpawnReason().equals(SpawnReason.BUILD_WITHER)) {
        Location l = event.getLocation();
        Region r = RedProtect.get().rm.getTopRegion(l);
        if (r != null && !r.canSpawnWhiter()) {
            event.isCancelled();
            return;
        }
    }
    if (e instanceof Monster) {
        Location l = event.getLocation();
        Region r = RedProtect.get().rm.getTopRegion(l);
        if (r != null && !r.canSpawnMonsters()) {
            RedProtect.get().logger.debug("Cancelled spawn of monster " + event.getEntityType().name());
            event.setCancelled(true);
        }
    }
    if (e instanceof LivingEntity && (!(e instanceof Monster) && !(e instanceof Player)) && (RedProtect.get().version >= 180 && !(e instanceof ArmorStand)) && !(e instanceof Hanging)) {
        Location l = event.getLocation();
        Region r = RedProtect.get().rm.getTopRegion(l);
        if (r != null && !r.canSpawnPassives()) {
            RedProtect.get().logger.debug("Cancelled spawn of animal " + event.getEntityType().name());
            event.setCancelled(true);
        }
    }
}
Also used : Wither(org.bukkit.entity.Wither) LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) ArmorStand(org.bukkit.entity.ArmorStand) Hanging(org.bukkit.entity.Hanging) Monster(org.bukkit.entity.Monster) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 5 with Monster

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

the class RPGlobalListener method onEntityDamageEntity.

@EventHandler
public void onEntityDamageEntity(EntityDamageByEntityEvent e) {
    if (e.isCancelled()) {
        return;
    }
    Entity e1 = e.getEntity();
    Entity e2 = e.getDamager();
    Location loc = e1.getLocation();
    Region r1 = RedProtect.get().rm.getTopRegion(loc);
    if (r1 != null) {
        return;
    }
    if (e2 instanceof Creeper || e2.getType().equals(EntityType.PRIMED_TNT) || e2.getType().equals(EntityType.MINECART_TNT)) {
        if (e1 instanceof Player) {
            if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".explosion-entity-damage")) {
                e.setCancelled(true);
                return;
            }
        }
        if (e1 instanceof Animals || e1 instanceof Villager || e1 instanceof Golem) {
            if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".explosion-entity-damage")) {
                e.setCancelled(true);
                return;
            }
        }
        if (e1 instanceof Monster) {
            if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".explosion-entity-damage")) {
                e.setCancelled(true);
                return;
            }
        }
    }
    if (e2 instanceof Player) {
        Player p = (Player) e2;
        if (e.getCause().equals(DamageCause.LIGHTNING) || e.getCause().equals(DamageCause.BLOCK_EXPLOSION) || e.getCause().equals(DamageCause.ENTITY_EXPLOSION)) {
            if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".entity-block-damage")) {
                e.setCancelled(true);
                return;
            }
        }
        if ((e1 instanceof Minecart || e1 instanceof Boat) && !RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".use-minecart") && !p.hasPermission("redprotect.bypass.world")) {
            e.setCancelled(true);
            return;
        }
        if (e1 instanceof Player) {
            if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".pvp") && !p.hasPermission("redprotect.bypass.world")) {
                e.setCancelled(true);
                return;
            }
        }
        if (e1 instanceof Animals || e1 instanceof Villager || e1 instanceof Golem) {
            if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".player-hurt-passives") && !p.hasPermission("redprotect.bypass.world")) {
                e.setCancelled(true);
                return;
            }
        }
        if (e1 instanceof Monster) {
            if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".player-hurt-monsters") && !p.hasPermission("redprotect.bypass.world")) {
                e.setCancelled(true);
                return;
            }
        }
        if (e1 instanceof Hanging || e1 instanceof EnderCrystal || e1 instanceof ArmorStand) {
            if (!RPConfig.getGlobalFlagList(p.getWorld().getName() + ".if-build-false.break-blocks").contains(e1.getType().name()) && !bypassBuild(p, null, 0)) {
                e.setCancelled(true);
                return;
            }
        }
    }
    if (e2 instanceof Projectile) {
        Projectile proj = (Projectile) e2;
        if (proj.getShooter() instanceof Player) {
            Player p = (Player) proj.getShooter();
            if (e1 instanceof Player) {
                if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".pvp") && !p.hasPermission("redprotect.bypass.world")) {
                    e.setCancelled(true);
                    return;
                }
            }
            if (e1 instanceof Animals || e1 instanceof Villager || e1 instanceof Golem) {
                if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".player-hurt-passives") && !p.hasPermission("redprotect.bypass.world")) {
                    e.setCancelled(true);
                    return;
                }
            }
            if (e1 instanceof Monster) {
                if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".player-hurt-monsters") && !p.hasPermission("redprotect.bypass.world")) {
                    e.setCancelled(true);
                    return;
                }
            }
            if (e1 instanceof Hanging || e1 instanceof EnderCrystal || e1 instanceof ArmorStand) {
                if (!RPConfig.getGlobalFlagList(p.getWorld().getName() + ".if-build-false.break-blocks").contains(e1.getType().name()) && !bypassBuild(p, null, 0)) {
                    e.setCancelled(true);
                }
            }
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) Creeper(org.bukkit.entity.Creeper) Minecart(org.bukkit.entity.Minecart) EnderCrystal(org.bukkit.entity.EnderCrystal) Projectile(org.bukkit.entity.Projectile) Golem(org.bukkit.entity.Golem) Animals(org.bukkit.entity.Animals) ArmorStand(org.bukkit.entity.ArmorStand) Hanging(org.bukkit.entity.Hanging) Monster(org.bukkit.entity.Monster) Villager(org.bukkit.entity.Villager) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) Location(org.bukkit.Location) Boat(org.bukkit.entity.Boat) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Monster (org.bukkit.entity.Monster)27 EventHandler (org.bukkit.event.EventHandler)22 Player (org.bukkit.entity.Player)18 LivingEntity (org.bukkit.entity.LivingEntity)16 Animals (org.bukkit.entity.Animals)15 Entity (org.bukkit.entity.Entity)14 Villager (org.bukkit.entity.Villager)11 Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)10 Projectile (org.bukkit.entity.Projectile)9 Location (org.bukkit.Location)8 Slime (org.bukkit.entity.Slime)8 Squid (org.bukkit.entity.Squid)8 IronGolem (org.bukkit.entity.IronGolem)6 Snowman (org.bukkit.entity.Snowman)6 Island (com.wasteofplastic.acidisland.Island)4 Island (com.wasteofplastic.askyblock.Island)4 Golem (org.bukkit.entity.Golem)4 Hanging (org.bukkit.entity.Hanging)4 UUID (java.util.UUID)3 ArmorStand (org.bukkit.entity.ArmorStand)3