Search in sources :

Example 61 with Projectile

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

the class PlayerEvents method onVisitorGetDamage.

/**
 * Prevents visitors from getting damage if invinciblevisitors option is set to TRUE
 * @param e - event
 */
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onVisitorGetDamage(EntityDamageByEntityEvent e) {
    if (!Settings.invincibleVisitors)
        return;
    if (!Settings.visitorDamagePrevention.contains(e.getCause()))
        return;
    if (!(e.getEntity() instanceof Player))
        return;
    // This only handles entity attacks by other players
    if (!e.getCause().equals(DamageCause.ENTITY_ATTACK))
        return;
    Player p = (Player) e.getEntity();
    if (!IslandGuard.inWorld(p) || plugin.getGrid().locationIsOnIsland(p, p.getLocation()))
        return;
    // Find out who the attacker is
    Player attacker = null;
    if (e.getDamager() instanceof Player) {
        attacker = (Player) e.getDamager();
    }
    if (e.getDamager() instanceof Projectile) {
        Projectile projectile = (Projectile) e.getDamager();
        if (projectile.getShooter() instanceof Player) {
            attacker = (Player) projectile.getShooter();
        }
    }
    // If we cannot work out who is the attacker then just prevent the damage and return
    if (attacker == null) {
        e.setCancelled(true);
        return;
    }
    // Check if at spawn
    if (plugin.getGrid().isAtSpawn(e.getEntity().getLocation())) {
        // Check if PVP is allowed at spawn or not
        if ((e.getEntity().getWorld().getEnvironment().equals(Environment.NORMAL) && plugin.getGrid().getIslandAt(e.getEntity().getLocation()).getIgsFlag(SettingsFlag.PVP)) || (e.getEntity().getWorld().getEnvironment().equals(Environment.NETHER) && plugin.getGrid().getIslandAt(e.getEntity().getLocation()).getIgsFlag(SettingsFlag.NETHER_PVP))) {
            // Damage allowed
            return;
        }
        // PVP is not allowed
        attacker.sendMessage(ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).visitorsProtected);
        e.setCancelled(true);
    } else {
        // Not at spawn, protect visitor
        attacker.sendMessage(ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).visitorsProtected);
        e.setCancelled(true);
    }
}
Also used : Player(org.bukkit.entity.Player) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 62 with Projectile

use of org.bukkit.entity.Projectile 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)

Example 63 with Projectile

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

the class IslandGuard method onSplashPotionSplash.

/**
 * Checks for splash damage. If there is any to any affected entity and it's not allowed, it won't work on any of them.
 * @param e - event
 */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onSplashPotionSplash(final PotionSplashEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName());
        plugin.getLogger().info("splash entity = " + e.getEntity());
        plugin.getLogger().info("splash entity type = " + e.getEntityType());
        plugin.getLogger().info("splash affected entities = " + e.getAffectedEntities());
    // plugin.getLogger().info("splash hit entity = " + e.getHitEntity());
    }
    if (!IslandGuard.inWorld(e.getEntity().getLocation())) {
        return;
    }
    // Try to get the shooter
    Projectile projectile = (Projectile) e.getEntity();
    if (DEBUG)
        plugin.getLogger().info("splash shooter = " + projectile.getShooter());
    if (projectile.getShooter() != null && projectile.getShooter() instanceof Player) {
        Player attacker = (Player) projectile.getShooter();
        // Run through all the affected entities
        for (LivingEntity entity : e.getAffectedEntities()) {
            if (DEBUG)
                plugin.getLogger().info("DEBUG: affected splash entity = " + entity);
            // Self damage
            if (attacker.equals(entity)) {
                if (DEBUG)
                    plugin.getLogger().info("DEBUG: Self damage from splash potion!");
                continue;
            }
            Island island = plugin.getGrid().getIslandAt(entity.getLocation());
            boolean inNether = false;
            if (entity.getWorld().equals(ASkyBlock.getNetherWorld())) {
                inNether = true;
            }
            // Monsters being hurt
            if (entity instanceof Monster || entity instanceof Slime || entity instanceof Squid) {
                // Normal island check
                if (island != null && island.getMembers().contains(attacker.getUniqueId())) {
                    // Members always allowed
                    continue;
                }
                if (actionAllowed(attacker, entity.getLocation(), SettingsFlag.HURT_MONSTERS)) {
                    continue;
                }
                // Not allowed
                Util.sendMessage(attacker, ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).islandProtected);
                e.setCancelled(true);
                return;
            }
            // Mobs being hurt
            if (entity instanceof Animals || entity instanceof IronGolem || entity instanceof Snowman || entity instanceof Villager) {
                if (island != null && (island.getIgsFlag(SettingsFlag.HURT_MOBS) || island.getMembers().contains(attacker.getUniqueId()))) {
                    continue;
                }
                if (DEBUG)
                    plugin.getLogger().info("DEBUG: Mobs not allowed to be hurt. Blocking");
                Util.sendMessage(attacker, ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).islandProtected);
                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 (entity instanceof Player) {
                if (pvp) {
                    if (DEBUG)
                        plugin.getLogger().info("DEBUG: PVP allowed");
                    continue;
                } else {
                    if (DEBUG)
                        plugin.getLogger().info("DEBUG: PVP not allowed");
                    Util.sendMessage(attacker, ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).targetInNoPVPArea);
                    e.setCancelled(true);
                    return;
                }
            }
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) 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) IronGolem(org.bukkit.entity.IronGolem) Slime(org.bukkit.entity.Slime) Island(com.wasteofplastic.acidisland.Island) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 64 with Projectile

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

the class IslandGuard method onTNTPrimed.

/**
 * Trap TNT being primed by flaming arrows
 * @param e - event
 */
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onTNTPrimed(final EntityChangeBlockEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName());
        plugin.getLogger().info("DEBUG: block = " + e.getBlock().getType());
        plugin.getLogger().info("DEBUG: entity = " + e.getEntityType());
        plugin.getLogger().info("DEBUG: material changing to " + e.getTo());
    }
    if (actionAllowed(e.getEntity().getLocation(), SettingsFlag.FIRE)) {
        return;
    }
    if (e.getBlock() == null) {
        return;
    }
    // Check for TNT
    if (!e.getBlock().getType().equals(Material.TNT)) {
        // plugin.getLogger().info("DEBUG: not tnt");
        return;
    }
    // Check world
    if (!inWorld(e.getBlock())) {
        return;
    }
    // Check if this is on an island
    Island island = plugin.getGrid().getIslandAt(e.getBlock().getLocation());
    if (island == null || island.isSpawn()) {
        return;
    }
    // Stop TNT from being damaged if it is being caused by a visitor with a flaming arrow
    if (e.getEntity() instanceof Projectile) {
        // plugin.getLogger().info("DEBUG: projectile");
        Projectile projectile = (Projectile) e.getEntity();
        // Find out who fired it
        if (projectile.getShooter() instanceof Player) {
            // plugin.getLogger().info("DEBUG: player shot arrow. Fire ticks = " + projectile.getFireTicks());
            if (projectile.getFireTicks() > 0) {
                // plugin.getLogger().info("DEBUG: arrow on fire");
                Player shooter = (Player) projectile.getShooter();
                if (!plugin.getGrid().locationIsAtHome(shooter, true, e.getBlock().getLocation())) {
                    // Debounce event (it can be called twice for the same action)
                    if (!tntBlocks.contains(e.getBlock().getLocation())) {
                        Util.sendMessage(shooter, ChatColor.RED + plugin.myLocale(shooter.getUniqueId()).islandProtected);
                        tntBlocks.add(e.getBlock().getLocation());
                        plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {

                            @Override
                            public void run() {
                                tntBlocks.remove(e.getBlock().getLocation());
                            }
                        }, 20L);
                    }
                    // Remove the arrow
                    projectile.remove();
                    e.setCancelled(true);
                    return;
                }
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Island(com.wasteofplastic.acidisland.Island) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 65 with Projectile

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

the class IslandGuard1_9 method onLingeringPotionSplash.

@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onLingeringPotionSplash(final LingeringPotionSplashEvent e) {
    if (!IslandGuard.inWorld(e.getEntity().getLocation())) {
        return;
    }
    // Try to get the shooter
    Projectile projectile = (Projectile) e.getEntity();
    if (projectile.getShooter() != null && projectile.getShooter() instanceof Player) {
        UUID uuid = ((Player) projectile.getShooter()).getUniqueId();
        // Store it and remove it when the effect is gone
        thrownPotions.put(e.getAreaEffectCloud().getEntityId(), uuid);
        plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {

            @Override
            public void run() {
                thrownPotions.remove(e.getAreaEffectCloud().getEntityId());
            }
        }, e.getAreaEffectCloud().getDuration());
    }
}
Also used : Player(org.bukkit.entity.Player) UUID(java.util.UUID) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Projectile (org.bukkit.entity.Projectile)86 EventHandler (org.bukkit.event.EventHandler)55 Player (org.bukkit.entity.Player)44 Entity (org.bukkit.entity.Entity)37 LivingEntity (org.bukkit.entity.LivingEntity)28 ProjectileSource (org.bukkit.projectiles.ProjectileSource)18 EntityDamageByEntityEvent (org.bukkit.event.entity.EntityDamageByEntityEvent)13 Location (org.bukkit.Location)9 Animals (org.bukkit.entity.Animals)9 Monster (org.bukkit.entity.Monster)9 Vector (org.bukkit.util.Vector)9 Villager (org.bukkit.entity.Villager)8 ItemStack (org.bukkit.inventory.ItemStack)8 Hanging (org.bukkit.entity.Hanging)7 EntityDamageEvent (org.bukkit.event.entity.EntityDamageEvent)7 PotionEffect (org.bukkit.potion.PotionEffect)7 Block (org.bukkit.block.Block)6 Arrow (org.bukkit.entity.Arrow)6 Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)4 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)4