Search in sources :

Example 46 with Projectile

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

the class AttackFire method attackFire.

@EventHandler
public void attackFire(EntityDamageByEntityEvent event) {
    Entity damager = event.getDamager();
    Entity damagee = event.getEntity();
    if (damager.hasMetadata(powerMetadata)) {
        damagee.setFireTicks(40);
    }
    if (damager instanceof Projectile) {
        if (ProjectileMetadataDetector.projectileMetadataDetector((Projectile) damager, powerMetadata)) {
            damagee.setFireTicks(40);
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 47 with Projectile

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

the class AttackPush method attackPush.

@EventHandler
public void attackPush(EntityDamageByEntityEvent event) {
    Entity damager = event.getDamager();
    Entity damagee = event.getEntity();
    if (damager.hasMetadata(powerMetadata)) {
        int pushbackStrength = 2;
        Vector pushbackDirection = damagee.getLocation().toVector().subtract(damager.getLocation().toVector());
        Vector pushbackApplied = pushbackDirection.normalize().multiply(pushbackStrength);
        damagee.setVelocity(pushbackApplied);
    }
    if (damager instanceof Projectile) {
        if (ProjectileMetadataDetector.projectileMetadataDetector(((Projectile) damager), powerMetadata)) {
            int pushbackStrength = 2;
            Vector pushbackDirection = damagee.getLocation().toVector().subtract(damager.getLocation().toVector());
            Vector pushbackApplied = pushbackDirection.normalize().multiply(pushbackStrength);
            damagee.setVelocity(pushbackApplied);
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) Vector(org.bukkit.util.Vector) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 48 with Projectile

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

the class AttackWeakness method attackWeakness.

@EventHandler
public void attackWeakness(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.WEAKNESS, 20 * 3, 0));
        }
    } else if (damager instanceof Projectile && damagee instanceof Player) {
        if (ProjectileMetadataDetector.projectileMetadataDetector((Projectile) damager, powerMetadata)) {
            Player player = (Player) damagee;
            player.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 20 * 3, 0));
        }
    }
}
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 49 with Projectile

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

the class AttackWither 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.WITHER, 50, 1));
    }
    if (damager instanceof Projectile) {
        if (ProjectileMetadataDetector.projectileMetadataDetector((Projectile) damager, powerMetadata)) {
            ((LivingEntity) damagee).addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 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 50 with Projectile

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

the class RPEntityListener method entityFire.

@EventHandler(priority = EventPriority.HIGHEST)
public void entityFire(EntityCombustByEntityEvent e) {
    Entity e1 = e.getEntity();
    Entity e2 = e.getCombuster();
    if (e2 == null) {
        return;
    }
    RedProtect.get().logger.debug("EntityCombustByEntityEvent - Is EntityCombustByEntityEvent event.");
    if (e2 instanceof Projectile) {
        Projectile a = (Projectile) e2;
        if (a.getShooter() instanceof Entity) {
            e2 = (Entity) a.getShooter();
        }
        a = null;
        if (e2 == null) {
            return;
        }
    }
    Region r1 = RedProtect.get().rm.getTopRegion(e1.getLocation());
    Region r2 = RedProtect.get().rm.getTopRegion(e2.getLocation());
    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) {
                if (r2 != null) {
                    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 : Golem(org.bukkit.entity.Golem) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) Animals(org.bukkit.entity.Animals) Explosive(org.bukkit.entity.Explosive) Hanging(org.bukkit.entity.Hanging) Monster(org.bukkit.entity.Monster) Villager(org.bukkit.entity.Villager) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) 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