Search in sources :

Example 6 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 7 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)

Example 8 with Monster

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

the class RPBlockListener method onFrameBrake.

@EventHandler
public void onFrameBrake(HangingBreakByEntityEvent e) {
    RedProtect.get().logger.debug("Is BlockListener - HangingBreakByEntityEvent event");
    if (e.isCancelled()) {
        return;
    }
    Entity remover = e.getRemover();
    Entity ent = e.getEntity();
    Location l = e.getEntity().getLocation();
    if ((ent instanceof ItemFrame || ent instanceof Painting) && remover instanceof Monster) {
        Region r = RedProtect.get().rm.getTopRegion(l);
        if (r != null && !r.canMobLoot()) {
            e.setCancelled(true);
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Monster(org.bukkit.entity.Monster) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) ItemFrame(org.bukkit.entity.ItemFrame) Location(org.bukkit.Location) Painting(org.bukkit.entity.Painting) EventHandler(org.bukkit.event.EventHandler)

Example 9 with Monster

use of org.bukkit.entity.Monster in project askyblock by tastybento.

the class IslandGuard method onEntityDamage.

/**
 * This method protects players from PVP if it is not allowed and from
 * arrows fired by other players
 *
 * @param e - event
 */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onEntityDamage(final EntityDamageByEntityEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName());
        plugin.getLogger().info("DEBUG: Damager = " + e.getDamager().toString());
        plugin.getLogger().info("DEBUG: Entitytype = " + e.getEntityType());
        plugin.getLogger().info("DEBUG: Entity = " + e.getEntity());
    }
    // Check world
    if (!inWorld(e.getEntity())) {
        return;
    }
    // Get the island where the damage is occurring
    Island island = plugin.getGrid().getProtectedIslandAt(e.getEntity().getLocation());
    boolean inNether = false;
    if (e.getEntity().getWorld().equals(ASkyBlock.getNetherWorld())) {
        inNether = true;
    }
    // Stop TNT damage if it is disallowed
    if (!Settings.allowTNTDamage && (e.getDamager().getType().equals(EntityType.PRIMED_TNT) || e.getDamager().getType().equals(EntityType.FIREWORK))) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG: cancelling TNT or firework damage");
        e.setCancelled(true);
        return;
    }
    // Check for creeper damage at spawn
    if (island != null && island.isSpawn() && e.getDamager().getType().equals(EntityType.CREEPER) && island.getIgsFlag(SettingsFlag.CREEPER_PAIN)) {
        return;
    }
    // Stop Creeper damager if it is disallowed
    if (!Settings.allowCreeperDamage && e.getDamager().getType().equals(EntityType.CREEPER) && !(e.getEntity() instanceof Player)) {
        e.setCancelled(true);
        return;
    }
    // Stop Creeper griefing if it is disallowed
    if (!Settings.allowCreeperGriefing && e.getDamager().getType().equals(EntityType.CREEPER)) {
        // Now we have to check what the target was
        Creeper creeper = (Creeper) e.getDamager();
        // plugin.getLogger().info("DEBUG: entity being damaged is " + e.getEntity());
        if (creeper.getTarget() instanceof Player) {
            // plugin.getLogger().info("DEBUG: target is a player");
            Player target = (Player) creeper.getTarget();
            // Check if the target is on their own island or not
            if (!plugin.getGrid().locationIsOnIsland(target, e.getEntity().getLocation())) {
                // They are a visitor tsk tsk
                // plugin.getLogger().info("DEBUG: player is a visitor");
                e.setCancelled(true);
                return;
            }
        }
        // Check if this creeper was lit by a visitor
        if (litCreeper.contains(creeper.getUniqueId())) {
            if (DEBUG) {
                plugin.getLogger().info("DEBUG: preventing creeeper from damaging");
            }
            e.setCancelled(true);
            return;
        }
    }
    // Ops can do anything
    if (e.getDamager() instanceof Player) {
        Player p = (Player) e.getDamager();
        if (p.isOp() || VaultHelper.checkPerm(p, Settings.PERMPREFIX + "mod.bypassprotect")) {
            return;
        }
    }
    // Get the real attacker
    boolean flamingArrow = false;
    boolean projectile = false;
    Player attacker = null;
    if (e.getDamager() instanceof Player) {
        attacker = (Player) e.getDamager();
    } else if (e.getDamager() instanceof Projectile) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG: Projectile damage");
        projectile = true;
        // Find out who fired the arrow
        Projectile p = (Projectile) e.getDamager();
        if (DEBUG)
            plugin.getLogger().info("DEBUG: Shooter is " + p.getShooter().toString());
        if (p.getShooter() instanceof Player) {
            attacker = (Player) p.getShooter();
            if (p.getFireTicks() > 0) {
                flamingArrow = true;
            }
            // Check if this is a flaming arrow
            if (DEBUG)
                plugin.getLogger().info("DEBUG: fire ticks = " + p.getFireTicks() + " max = " + p.getMaxFireTicks());
        }
    }
    if (attacker == null) {
        // Not a player
        return;
    }
    // Self damage
    if (e.getEntity() instanceof Player && attacker.equals((Player) e.getEntity())) {
        if (DEBUG)
            plugin.getLogger().info("Self damage!");
        return;
    }
    if (DEBUG)
        plugin.getLogger().info("DEBUG: Another player");
    // Check to see if it's an item frame
    if (e.getEntity() instanceof ItemFrame || e.getEntityType().toString().endsWith("STAND")) {
        if (island != null && (island.getIgsFlag(SettingsFlag.BREAK_BLOCKS) || island.getMembers().contains(attacker.getUniqueId()))) {
            return;
        }
        // Else not allowed
        Util.sendMessage(attacker, ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).islandProtected);
        if (flamingArrow)
            e.getEntity().setFireTicks(0);
        if (projectile)
            e.getDamager().remove();
        e.setCancelled(true);
        return;
    }
    // Monsters being hurt
    if (e.getEntity() instanceof Monster || e.getEntity() instanceof Slime || e.getEntity() instanceof Squid) {
        // Normal island check
        if (island != null && island.getMembers().contains(attacker.getUniqueId())) {
            // Members always allowed
            return;
        }
        if (actionAllowed(attacker, e.getEntity().getLocation(), SettingsFlag.HURT_MONSTERS)) {
            // Check for visitors setting creepers alight using flint steel
            if (!Settings.allowCreeperGriefing && e.getEntity() instanceof Creeper) {
                for (ItemStack holding : Util.getPlayerInHandItems(attacker)) {
                    if (holding.getType().equals(Material.FLINT_AND_STEEL)) {
                        // Save this creeper for later when any damage caused by its explosion will be nullified
                        litCreeper.add(e.getEntity().getUniqueId());
                        if (DEBUG) {
                            plugin.getLogger().info("DEBUG: adding to lit creeper set");
                        }
                    }
                }
            }
            return;
        }
        // Not allowed
        Util.sendMessage(attacker, ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).islandProtected);
        if (flamingArrow)
            e.getEntity().setFireTicks(0);
        if (projectile)
            e.getDamager().remove();
        e.setCancelled(true);
        return;
    }
    // Mobs being hurt
    if (e.getEntity() instanceof Animals || e.getEntity() instanceof IronGolem || e.getEntity() instanceof Snowman || e.getEntity() instanceof Villager) {
        if (island != null && (island.getIgsFlag(SettingsFlag.HURT_MOBS) || island.getMembers().contains(attacker.getUniqueId()))) {
            return;
        }
        if (DEBUG)
            plugin.getLogger().info("DEBUG: Mobs not allowed to be hurt. Blocking");
        // Else not allowed
        Util.sendMessage(attacker, ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).islandProtected);
        if (flamingArrow)
            e.getEntity().setFireTicks(0);
        if (projectile)
            e.getDamager().remove();
        e.setCancelled(true);
        return;
    }
    // Establish whether PVP is allowed or not.
    boolean pvp = false;
    if ((inNether && island != null && island.getIgsFlag(SettingsFlag.NETHER_PVP) || (!inNether && island != null && island.getIgsFlag(SettingsFlag.PVP)))) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG: PVP allowed");
        pvp = true;
    }
    // Players being hurt PvP
    if (e.getEntity() instanceof Player) {
        if (pvp) {
            return;
        } else {
            Util.sendMessage(attacker, ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).targetInNoPVPArea);
            if (flamingArrow)
                e.getEntity().setFireTicks(0);
            if (projectile)
                e.getDamager().remove();
            e.setCancelled(true);
            return;
        }
    }
}
Also used : Player(org.bukkit.entity.Player) Creeper(org.bukkit.entity.Creeper) ItemFrame(org.bukkit.entity.ItemFrame) IronGolem(org.bukkit.entity.IronGolem) Slime(org.bukkit.entity.Slime) Island(com.wasteofplastic.askyblock.Island) Projectile(org.bukkit.entity.Projectile) Animals(org.bukkit.entity.Animals) Squid(org.bukkit.entity.Squid) Monster(org.bukkit.entity.Monster) Villager(org.bukkit.entity.Villager) Snowman(org.bukkit.entity.Snowman) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 10 with Monster

use of org.bukkit.entity.Monster in project askyblock by tastybento.

the class IslandGuard method onFishing.

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onFishing(PlayerFishEvent e) {
    if (DEBUG) {
        plugin.getLogger().info("Player fish event " + e.getEventName());
        plugin.getLogger().info("Player fish event " + e.getCaught());
    }
    if (e.getCaught() == null)
        return;
    Player p = e.getPlayer();
    if (!inWorld(p)) {
        return;
    }
    if (p.isOp() || VaultHelper.checkPerm(p, Settings.PERMPREFIX + "mod.bypassprotect")) {
        // You can do anything if you are Op of have the bypass
        return;
    }
    // Handle rods
    Island island = plugin.getGrid().getProtectedIslandAt(e.getCaught().getLocation());
    // PVP check
    if (e.getCaught() instanceof Player) {
        // Check if this is the player who is holding the rod
        if (e.getCaught().equals(e.getPlayer())) {
            if (DEBUG)
                plugin.getLogger().info("DEBUG: player cught themselves!");
            return;
        }
        if (island == null && (e.getCaught().getWorld().getEnvironment().equals(Environment.NORMAL) && !Settings.defaultWorldSettings.get(SettingsFlag.PVP)) || ((e.getCaught().getWorld().getEnvironment().equals(Environment.NETHER) && !Settings.defaultWorldSettings.get(SettingsFlag.NETHER_PVP)))) {
            Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).targetInNoPVPArea);
            e.setCancelled(true);
            e.getHook().remove();
            return;
        }
        if (island != null && ((e.getCaught().getWorld().getEnvironment().equals(Environment.NORMAL) && !island.getIgsFlag(SettingsFlag.PVP)) || (e.getCaught().getWorld().getEnvironment().equals(Environment.NETHER) && !island.getIgsFlag(SettingsFlag.NETHER_PVP)))) {
            Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).targetInNoPVPArea);
            e.setCancelled(true);
            e.getHook().remove();
            return;
        }
    }
    if (!plugin.getGrid().playerIsOnIsland(e.getPlayer())) {
        if (e.getCaught() instanceof Animals) {
            if (island == null && !Settings.defaultWorldSettings.get(SettingsFlag.HURT_MOBS)) {
                Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
                e.setCancelled(true);
                e.getHook().remove();
                return;
            }
            if (island != null) {
                if ((!island.getIgsFlag(SettingsFlag.HURT_MOBS) && !island.getMembers().contains(p.getUniqueId()))) {
                    Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
                    e.setCancelled(true);
                    e.getHook().remove();
                    return;
                }
            }
        }
        // Monster protection
        if (e.getCaught() instanceof Monster || e.getCaught() instanceof Squid || e.getCaught() instanceof Slime) {
            if (island == null && !Settings.defaultWorldSettings.get(SettingsFlag.HURT_MONSTERS)) {
                Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
                e.setCancelled(true);
                e.getHook().remove();
                return;
            }
            if (island != null) {
                if ((!island.getIgsFlag(SettingsFlag.HURT_MONSTERS) && !island.getMembers().contains(p.getUniqueId()))) {
                    Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
                    e.setCancelled(true);
                    e.getHook().remove();
                    return;
                }
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) Animals(org.bukkit.entity.Animals) Squid(org.bukkit.entity.Squid) Monster(org.bukkit.entity.Monster) Slime(org.bukkit.entity.Slime) Island(com.wasteofplastic.askyblock.Island) 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