Search in sources :

Example 16 with Projectile

use of org.bukkit.entity.Projectile in project Jobs by GamingMesh.

the class JobsPaymentListener method onEntityDeath.

@EventHandler(priority = EventPriority.MONITOR)
public void onEntityDeath(EntityDeathEvent event) {
    // Entity that died must be living
    if (!(event.getEntity() instanceof LivingEntity))
        return;
    LivingEntity lVictim = (LivingEntity) event.getEntity();
    // mob spawner, no payment or experience
    if (lVictim.hasMetadata(mobSpawnerMetadata)) {
        lVictim.removeMetadata(mobSpawnerMetadata, plugin);
        return;
    }
    // make sure plugin is enabled
    if (!plugin.isEnabled())
        return;
    if (event.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent) {
        EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event.getEntity().getLastDamageCause();
        org.bukkit.entity.Player pDamager = null;
        if (e.getDamager() instanceof org.bukkit.entity.Player) {
            pDamager = (org.bukkit.entity.Player) e.getDamager();
        } else if (e.getDamager() instanceof Projectile && ((Projectile) e.getDamager()).getShooter() instanceof org.bukkit.entity.Player) {
            pDamager = (org.bukkit.entity.Player) ((Projectile) e.getDamager()).getShooter();
        } else if (e.getDamager() instanceof Tameable) {
            Tameable t = (Tameable) e.getDamager();
            if (t.isTamed() && t.getOwner() instanceof org.bukkit.entity.Player) {
                pDamager = (org.bukkit.entity.Player) t.getOwner();
            }
        }
        if (pDamager != null) {
            // check if in creative
            if (pDamager.getGameMode().equals(GameMode.CREATIVE) && !ConfigManager.getJobsConfiguration().payInCreative())
                return;
            if (!Jobs.getPermissionHandler().hasWorldPermission(pDamager, pDamager.getLocation().getWorld().getName()))
                return;
            // restricted area multiplier
            double multiplier = ConfigManager.getJobsConfiguration().getRestrictedMultiplier(pDamager);
            // pay
            JobsPlayer jDamager = Jobs.getPlayerManager().getJobsPlayer(pDamager);
            Jobs.action(jDamager, new EntityActionInfo(lVictim.getType(), ActionType.KILL), multiplier);
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) Tameable(org.bukkit.entity.Tameable) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) Player(org.bukkit.entity.Player) EntityActionInfo(com.gamingmesh.jobs.actions.EntityActionInfo) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 17 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 18 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 19 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)

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

Aggregations

Projectile (org.bukkit.entity.Projectile)26 EventHandler (org.bukkit.event.EventHandler)19 Entity (org.bukkit.entity.Entity)18 Player (org.bukkit.entity.Player)14 LivingEntity (org.bukkit.entity.LivingEntity)9 PotionEffect (org.bukkit.potion.PotionEffect)6 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)4 ProjectileLaunchEvent (org.bukkit.event.entity.ProjectileLaunchEvent)4 Test (org.junit.Test)4 TownyWorld (com.palmergames.bukkit.towny.object.TownyWorld)3 EntityDamageByEntityEvent (org.bukkit.event.entity.EntityDamageByEntityEvent)3 PlayerCache (com.palmergames.bukkit.towny.object.PlayerCache)2 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)2 net.aufdemrand.denizen.objects.dPlayer (net.aufdemrand.denizen.objects.dPlayer)2 Material (org.bukkit.Material)2 Block (org.bukkit.block.Block)2 ProjectileSource (org.bukkit.projectiles.ProjectileSource)2 Vector (org.bukkit.util.Vector)2 EntityActionInfo (com.gamingmesh.jobs.actions.EntityActionInfo)1 JobsPlayer (com.gamingmesh.jobs.container.JobsPlayer)1