Search in sources :

Example 1 with Animals

use of org.bukkit.entity.Animals in project acidisland by tastybento.

the class EntityLimits method onAnimalSpawn.

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onAnimalSpawn(final CreatureSpawnEvent e) {
    // If not in the right world, return
    if (!IslandGuard.inWorld(e.getEntity())) {
        return;
    }
    // If not an animal
    if (!(e.getEntity() instanceof Animals) && !e.getEntityType().equals(EntityType.SQUID)) {
        return;
    }
    if (DEBUG2) {
        plugin.getLogger().info("Animal spawn event! " + e.getEventName());
        plugin.getLogger().info(e.getSpawnReason().toString());
        plugin.getLogger().info(e.getEntityType().toString());
    }
    // If there's no limit - leave it
    if (Settings.breedingLimit <= 0) {
        if (DEBUG2)
            plugin.getLogger().info("No limit on breeding or spawning");
        return;
    }
    // We only care about spawning and breeding
    if (e.getSpawnReason() != SpawnReason.SPAWNER && e.getSpawnReason() != SpawnReason.BREEDING && e.getSpawnReason() != SpawnReason.EGG && e.getSpawnReason() != SpawnReason.DISPENSE_EGG && e.getSpawnReason() != SpawnReason.SPAWNER_EGG && !e.getSpawnReason().name().contains("BABY")) {
        if (DEBUG2)
            plugin.getLogger().info("Not Spawner or breeding");
        return;
    }
    LivingEntity animal = e.getEntity();
    Island island = plugin.getGrid().getProtectedIslandAt(animal.getLocation());
    if (island == null) {
        // Animal is spawning outside of an island so ignore
        if (DEBUG2)
            plugin.getLogger().info("Outside island, so spawning is okay");
        return;
    }
    // Count how many animals are there and who is the most likely spawner if it was a player
    // This had to be reworked because the previous snowball approach doesn't work for large volumes
    List<Player> culprits = new ArrayList<Player>();
    boolean overLimit = false;
    int animals = 0;
    for (int x = island.getMinProtectedX() / 16; x <= (island.getMinProtectedX() + island.getProtectionSize() - 1) / 16; x++) {
        for (int z = island.getMinProtectedZ() / 16; z <= (island.getMinProtectedZ() + island.getProtectionSize() - 1) / 16; z++) {
            for (Entity entity : ASkyBlock.getIslandWorld().getChunkAt(x, z).getEntities()) {
                if (entity instanceof Animals || entity.getType().equals(EntityType.SQUID)) {
                    if (DEBUG2)
                        plugin.getLogger().info("DEBUG: Animal count is " + animals);
                    animals++;
                    if (animals >= Settings.breedingLimit) {
                        // Delete any extra animals
                        overLimit = true;
                        animal.remove();
                        if (DEBUG2)
                            plugin.getLogger().info("Over limit! >=" + Settings.breedingLimit);
                        e.setCancelled(true);
                    }
                } else if (entity instanceof Player && e.getSpawnReason() != SpawnReason.SPAWNER && e.getSpawnReason() != SpawnReason.DISPENSE_EGG) {
                    for (ItemStack itemInHand : Util.getPlayerInHandItems((Player) entity)) {
                        if (itemInHand != null) {
                            Material type = itemInHand.getType();
                            if (type == Material.EGG || type == Material.MONSTER_EGG || type == Material.WHEAT || type == Material.CARROT_ITEM || type == Material.SEEDS) {
                                if (DEBUG2)
                                    plugin.getLogger().info("Player used egg or did breeding ");
                                if (!culprits.contains((Player) entity)) {
                                    culprits.add(((Player) entity));
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (DEBUG2)
        plugin.getLogger().info("Counting nether");
    // Nether check
    if (Settings.createNether && Settings.newNether && ASkyBlock.getNetherWorld() != null) {
        for (int x = island.getMinProtectedX() / 16; x <= (island.getMinProtectedX() + island.getProtectionSize() - 1) / 16; x++) {
            for (int z = island.getMinProtectedZ() / 16; z <= (island.getMinProtectedZ() + island.getProtectionSize() - 1) / 16; z++) {
                for (Entity entity : ASkyBlock.getNetherWorld().getChunkAt(x, z).getEntities()) {
                    if (entity instanceof Animals || entity.getType().equals(EntityType.SQUID)) {
                        if (DEBUG2)
                            plugin.getLogger().info("DEBUG: Animal count is " + animals);
                        animals++;
                        if (animals >= Settings.breedingLimit) {
                            // Delete any extra animals
                            if (DEBUG2)
                                plugin.getLogger().info("Over limit! >=" + Settings.breedingLimit);
                            overLimit = true;
                            animal.remove();
                            e.setCancelled(true);
                        }
                    } else if (entity instanceof Player && e.getSpawnReason() != SpawnReason.SPAWNER && e.getSpawnReason() != SpawnReason.DISPENSE_EGG) {
                        for (ItemStack itemInHand : Util.getPlayerInHandItems(((Player) entity))) {
                            Material type = itemInHand.getType();
                            if (type == Material.EGG || type == Material.MONSTER_EGG || type == Material.WHEAT || type == Material.CARROT_ITEM || type == Material.SEEDS) {
                                if (!culprits.contains((Player) entity)) {
                                    culprits.add(((Player) entity));
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (overLimit) {
        if (e.getSpawnReason() != SpawnReason.SPAWNER) {
            plugin.getLogger().warning("Island at " + island.getCenter().getBlockX() + "," + island.getCenter().getBlockZ() + " hit the island animal breeding limit of " + Settings.breedingLimit);
            for (Player player : culprits) {
                Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).moblimitsError.replace("[number]", String.valueOf(Settings.breedingLimit)));
                plugin.getLogger().warning(player.getName() + " was trying to use " + Util.getPlayerInHandItems(player).toString());
            }
        }
    }
// plugin.getLogger().info("DEBUG: Animal count is " + animals);
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) Animals(org.bukkit.entity.Animals) ArrayList(java.util.ArrayList) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack) Island(com.wasteofplastic.acidisland.Island) EventHandler(org.bukkit.event.EventHandler)

Example 2 with Animals

use of org.bukkit.entity.Animals in project acidisland by tastybento.

the class IslandGuard method onPlayerHitEntity.

/**
 * Handles hitting minecarts or feeding animals
 * @param e - event
 */
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerHitEntity(PlayerInteractEntityEvent e) {
    Player p = e.getPlayer();
    if (DEBUG) {
        plugin.getLogger().info("Hit entity event " + e.getEventName());
    }
    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;
    }
    /*
         * Leashes are deal with mostly using the PlayerLeashEvent and PlayerUnleashEvent
         * however, skeleton and zombie horses cannot be leashed, so those should be exempted
         */
    if (Util.playerIsHolding(p, Material.LEASH) && e.getRightClicked() != null) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG: checking horse types");
        // Pre 1.11
        if (e.getRightClicked() instanceof Horse) {
            boolean skellyZombieHorse = false;
            if (DEBUG)
                plugin.getLogger().info("DEBUG: horse clicked ");
            Horse horse = (Horse) e.getRightClicked();
            if (DEBUG)
                plugin.getLogger().info("DEBUG: horse variant = " + horse.getVariant());
            if (horse.getVariant().equals(Variant.SKELETON_HORSE) || horse.getVariant().equals(Variant.UNDEAD_HORSE)) {
                if (DEBUG)
                    plugin.getLogger().info("DEBUG: skelly or zombie horse");
                skellyZombieHorse = true;
            }
            if (DEBUG)
                plugin.getLogger().info("DEBUG: Checking entity types :" + e.getRightClicked().getType().name());
            // For 1.11 onwards
            if (e.getRightClicked().getType().name().equals("ZOMBIE_HORSE") || e.getRightClicked().getType().name().equals("SKELETON_HORSE")) {
                skellyZombieHorse = true;
            }
            if (!skellyZombieHorse)
                return;
            if (DEBUG)
                plugin.getLogger().info("DEBUG: zombie horse or skelly horse");
        }
    }
    Island island = plugin.getGrid().getProtectedIslandAt(e.getPlayer().getLocation());
    if (!plugin.getGrid().playerIsOnIsland(e.getPlayer())) {
        // Handle village trading
        if (e.getRightClicked() != null && e.getRightClicked().getType().equals(EntityType.VILLAGER)) {
            if (island != null) {
                if (DEBUG) {
                    plugin.getLogger().info("DEBUG: island is not null");
                    plugin.getLogger().info("DEBUG: island is not spawn");
                    plugin.getLogger().info("DEBUG: villager trading is " + island.getIgsFlag(SettingsFlag.VILLAGER_TRADING));
                }
                if ((!island.getIgsFlag(SettingsFlag.VILLAGER_TRADING) && !island.getMembers().contains(p.getUniqueId()))) {
                    Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
                    e.setCancelled(true);
                    return;
                }
            }
        }
        // Handle name tags and dyes
        if (Util.playerIsHolding(p, Material.NAME_TAG) || Util.playerIsHolding(p, Material.INK_SACK)) {
            Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
            e.setCancelled(true);
            e.getPlayer().updateInventory();
            return;
        }
        // Handle cookies (to animals)
        if (Util.playerIsHolding(p, Material.COOKIE) && e.getRightClicked() 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);
                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);
                    return;
                }
            }
        }
        // Handle breeding
        if (e.getRightClicked() instanceof Animals) {
            for (ItemStack item : Util.getPlayerInHandItems(p)) {
                Material type = item.getType();
                if (type == Material.EGG || type == Material.WHEAT || type == Material.CARROT_ITEM || type == Material.SEEDS) {
                    if (island == null && !Settings.defaultWorldSettings.get(SettingsFlag.BREEDING)) {
                        Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
                        e.setCancelled(true);
                        return;
                    }
                    if (island != null) {
                        if ((!island.getIgsFlag(SettingsFlag.BREEDING) && !island.getMembers().contains(p.getUniqueId()))) {
                            Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
                            e.setCancelled(true);
                            return;
                        }
                    }
                }
            }
        }
        switch(e.getRightClicked().getType()) {
            case CREEPER:
                // This seems to be called when the player is in Creative mode...
                if (!Settings.allowCreeperGriefing) {
                    for (ItemStack item : Util.getPlayerInHandItems(e.getPlayer())) {
                        if (item != null && item.getType().equals(Material.FLINT_AND_STEEL)) {
                            if (!island.getMembers().contains(e.getPlayer().getUniqueId())) {
                                // Visitor
                                litCreeper.add(e.getRightClicked().getUniqueId());
                                if (DEBUG) {
                                    plugin.getLogger().info("DEBUG: visitor lit creeper");
                                }
                            }
                        }
                    }
                }
                break;
            case LLAMA:
            case SKELETON_HORSE:
            case ZOMBIE_HORSE:
            case HORSE:
                // plugin.getLogger().info("Horse riding");
                if (island == null && !Settings.defaultWorldSettings.get(SettingsFlag.HORSE_RIDING)) {
                    Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
                    e.setCancelled(true);
                    e.getPlayer().updateInventory();
                }
                if (island != null && !island.getIgsFlag(SettingsFlag.HORSE_RIDING)) {
                    Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
                    e.setCancelled(true);
                    e.getPlayer().updateInventory();
                }
                break;
            case ITEM_FRAME:
                // This is to place items in an item frame
                if (island == null && !Settings.defaultWorldSettings.get(SettingsFlag.PLACE_BLOCKS)) {
                    Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
                    e.setCancelled(true);
                }
                if (island != null) {
                    if (!island.getIgsFlag(SettingsFlag.PLACE_BLOCKS)) {
                        Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
                        e.setCancelled(true);
                    }
                }
                break;
            case MINECART_CHEST:
            case MINECART_FURNACE:
            case MINECART_HOPPER:
                // plugin.getLogger().info("Minecarts");
                if (island == null && !Settings.defaultWorldSettings.get(SettingsFlag.CHEST)) {
                    Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
                    e.setCancelled(true);
                }
                if (island != null) {
                    if (!island.getIgsFlag(SettingsFlag.CHEST)) {
                        Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
                        e.setCancelled(true);
                    }
                }
                break;
            default:
                break;
        }
    }
}
Also used : Player(org.bukkit.entity.Player) Animals(org.bukkit.entity.Animals) Horse(org.bukkit.entity.Horse) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack) Island(com.wasteofplastic.acidisland.Island) EventHandler(org.bukkit.event.EventHandler)

Example 3 with Animals

use of org.bukkit.entity.Animals in project acidisland 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.acidisland.Island) EventHandler(org.bukkit.event.EventHandler)

Example 4 with Animals

use of org.bukkit.entity.Animals in project MyPet by xXKeyleXx.

the class WorldGuardHook method canHurt.

@Override
public boolean canHurt(Player attacker, Entity defender) {
    if (customFlags) {
        try {
            Location location = defender.getLocation();
            RegionManager mgr = wgp.getRegionManager(location.getWorld());
            ApplicableRegionSet set = mgr.getApplicableRegions(location);
            StateFlag.State s;
            if (defender instanceof Animals) {
                s = set.queryState(null, DefaultFlag.DAMAGE_ANIMALS, DAMAGE_FLAG);
            } else {
                s = set.queryState(null, DAMAGE_FLAG);
            }
            return s == null || s == StateFlag.State.ALLOW;
        } catch (Throwable ignored) {
        }
    }
    return true;
}
Also used : Animals(org.bukkit.entity.Animals) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) StateFlag(com.sk89q.worldguard.protection.flags.StateFlag) Location(org.bukkit.Location) ApplicableRegionSet(com.sk89q.worldguard.protection.ApplicableRegionSet)

Example 5 with Animals

use of org.bukkit.entity.Animals in project acidisland 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.acidisland.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)

Aggregations

Animals (org.bukkit.entity.Animals)7 Island (com.wasteofplastic.acidisland.Island)6 Player (org.bukkit.entity.Player)6 EventHandler (org.bukkit.event.EventHandler)6 Monster (org.bukkit.entity.Monster)4 Slime (org.bukkit.entity.Slime)4 Squid (org.bukkit.entity.Squid)4 IronGolem (org.bukkit.entity.IronGolem)3 Snowman (org.bukkit.entity.Snowman)3 Villager (org.bukkit.entity.Villager)3 ItemStack (org.bukkit.inventory.ItemStack)3 Material (org.bukkit.Material)2 LivingEntity (org.bukkit.entity.LivingEntity)2 Projectile (org.bukkit.entity.Projectile)2 ApplicableRegionSet (com.sk89q.worldguard.protection.ApplicableRegionSet)1 StateFlag (com.sk89q.worldguard.protection.flags.StateFlag)1 RegionManager (com.sk89q.worldguard.protection.managers.RegionManager)1 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 Location (org.bukkit.Location)1