Search in sources :

Example 41 with Projectile

use of org.bukkit.entity.Projectile in project acidisland 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 || !Settings.visitorDamagePrevention.contains(e.getCause()) || !(e.getEntity() instanceof Player) || !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 42 with Projectile

use of org.bukkit.entity.Projectile in project Denizen-For-Bukkit by DenizenScript.

the class ShootCommand method arrowDamage.

@EventHandler
public void arrowDamage(EntityDamageByEntityEvent event) {
    // Get the damager
    Entity arrow = event.getDamager();
    // First, quickly confirm it's a projectile (relevant at all)
    if (!(arrow instanceof Projectile)) {
        return;
    }
    // Second, more slowly check if we shot it
    if (!arrows.containsKey(arrow.getUniqueId())) {
        return;
    }
    // Replace its entry with the hit entity.
    arrows.remove(arrow.getUniqueId());
    arrows.put(arrow.getUniqueId(), new dEntity(event.getEntity()));
}
Also used : net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) Entity(org.bukkit.entity.Entity) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 43 with Projectile

use of org.bukkit.entity.Projectile in project EliteMobs by MagmaGuy.

the class AttackBlinding method attackBlinding.

@EventHandler
public void attackBlinding(EntityDamageByEntityEvent event) {
    Entity damager = event.getDamager();
    Entity damagee = event.getEntity();
    if (damager.hasMetadata(powerMetadata)) {
        if (damagee instanceof Player) {
            Player player = (Player) damagee;
            player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 20 * 5, 3));
        }
    } else if (damager instanceof Projectile && damagee instanceof Player) {
        if (ProjectileMetadataDetector.projectileMetadataDetector((Projectile) damager, powerMetadata)) {
            Player player = (Player) damagee;
            player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 20 * 5, 3));
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) PotionEffect(org.bukkit.potion.PotionEffect) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 44 with Projectile

use of org.bukkit.entity.Projectile in project EliteMobs by MagmaGuy.

the class AttackPoison method onHit.

@EventHandler
public void onHit(EntityDamageByEntityEvent event) {
    Entity damager = event.getDamager();
    Entity damagee = event.getEntity();
    if (damager.hasMetadata(powerMetadata) && damagee instanceof LivingEntity) {
        ((LivingEntity) damagee).addPotionEffect(new PotionEffect(PotionEffectType.POISON, 50, 1));
    }
    if (damager instanceof Projectile) {
        if (ProjectileMetadataDetector.projectileMetadataDetector((Projectile) damager, powerMetadata)) {
            ((LivingEntity) damagee).addPotionEffect(new PotionEffect(PotionEffectType.POISON, 50, 1));
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) PotionEffect(org.bukkit.potion.PotionEffect) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 45 with Projectile

use of org.bukkit.entity.Projectile in project EliteMobs by MagmaGuy.

the class AttackFreeze method attackFreeze.

@EventHandler
public void attackFreeze(EntityDamageByEntityEvent event) {
    Entity damager = event.getDamager();
    Entity damagee = event.getEntity();
    Block block = damagee.getLocation().getBlock();
    Material originalMaterial = block.getType();
    if (!originalMaterial.equals(Material.AIR)) {
        return;
    }
    if (damagee.hasMetadata(MetadataHandler.FROZEN_COOLDOWN)) {
        return;
    }
    //if a block spawned by the plugin is already in place, skip effect
    if (block.hasMetadata("TemporaryBlock")) {
        return;
    }
    if (damager.hasMetadata(powerMetadata)) {
        processID = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {

            int counter = 0;

            @Override
            public void run() {
                iceEffectApplier(counter, damagee, block);
                counter++;
            }
        }, 1, 1);
    }
    if (damager instanceof Projectile) {
        if (ProjectileMetadataDetector.projectileMetadataDetector((Projectile) damager, powerMetadata)) {
            processID = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {

                int counter = 0;

                @Override
                public void run() {
                    iceEffectApplier(counter, damagee, block);
                    counter++;
                }
            }, 1, 1);
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) Block(org.bukkit.block.Block) Material(org.bukkit.Material) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Projectile (org.bukkit.entity.Projectile)87 EventHandler (org.bukkit.event.EventHandler)56 Player (org.bukkit.entity.Player)45 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