Search in sources :

Example 81 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 82 with Projectile

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

the class FrostCone method createSnowball.

private static Snowball createSnowball(EliteEntity eliteEntity, Location location) {
    Projectile snowball = EliteProjectile.create(EntityType.SNOWBALL, eliteEntity.getLivingEntity(), getShotVector(eliteEntity, location), false);
    ProjectileTagger.tagProjectileWithCustomDamage(snowball, 2);
    snowball.getPersistentDataContainer().set(frostConeSnowballKey, PersistentDataType.STRING, "true");
    Bukkit.getScheduler().runTaskLater(MetadataHandler.PLUGIN, snowball::remove, 20L * 3);
    return (Snowball) snowball;
}
Also used : Snowball(org.bukkit.entity.Snowball) Projectile(org.bukkit.entity.Projectile) EliteProjectile(com.magmaguy.elitemobs.combatsystem.EliteProjectile)

Example 83 with Projectile

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

the class PlayerDamagedByEliteMobHandler method secondaryEnchantmentDamageReduction.

private double secondaryEnchantmentDamageReduction(Player player, EntityDamageByEntityEvent event) {
    double totalReductionLevel = 0;
    for (ItemStack itemStack : player.getInventory().getArmorContents()) {
        if (itemStack == null || itemStack.getItemMeta() == null)
            continue;
        if (event.getDamager() instanceof Projectile)
            totalReductionLevel += ItemTagger.getEnchantment(itemStack.getItemMeta(), Enchantment.PROTECTION_ENVIRONMENTAL.getKey());
    }
    totalReductionLevel = totalReductionLevel / 4 / 10;
    return totalReductionLevel;
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) Projectile(org.bukkit.entity.Projectile)

Example 84 with Projectile

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

the class EliteProjectile method create.

public static Projectile create(EntityType entityType, Entity shooter, Entity victim, Vector shotVector, boolean gravity) {
    Location projectileLocation = generateLocation(shooter, victim);
    Projectile projectile = (Projectile) projectileLocation.getWorld().spawnEntity(projectileLocation, entityType);
    projectile.setShooter((ProjectileSource) shooter);
    projectile.setVelocity(shotVector);
    projectile.setGravity(gravity);
    EntityTracker.registerProjectileEntity(projectile);
    return projectile;
}
Also used : Location(org.bukkit.Location) Projectile(org.bukkit.entity.Projectile)

Example 85 with Projectile

use of org.bukkit.entity.Projectile in project Glowstone by GlowstoneMC.

the class GlowEntity method pulsePhysics.

protected void pulsePhysics() {
    // The pending location and the block at that location
    Location pendingLocation = location.clone().add(velocity);
    Block pendingBlock = pendingLocation.getBlock();
    if (pendingBlock.getType().isSolid()) {
        Location pendingLocationX = location.clone().add(velocity.getX(), 0, 0);
        if (pendingLocationX.getBlock().getType().isSolid()) {
            velocity.setX(0);
        }
        Location pendingLocationY = location.clone().add(0, velocity.getY(), 0);
        if (pendingLocationY.getBlock().getType().isSolid()) {
            velocity.setY(0);
        }
        Location pendingLocationZ = location.clone().add(0, 0, velocity.getZ());
        if (pendingLocationZ.getBlock().getType().isSolid()) {
            velocity.setZ(0);
        }
        if (this instanceof Projectile) {
            EventFactory.getInstance().callEvent(new ProjectileHitEvent((Projectile) this, pendingBlock));
        }
        collide(pendingBlock);
    } else {
        if (hasFriction()) {
            // apply friction and gravity
            if (location.getBlock().getType() == Material.WATER) {
                velocity.multiply(liquidDrag);
                velocity.setY(velocity.getY() + getGravityAccel().getY() / 4);
            } else if (location.getBlock().getType() == Material.LAVA) {
                velocity.multiply(liquidDrag - 0.3);
                velocity.setY(velocity.getY() + getGravityAccel().getY() / 4);
            } else {
                if (applyDragBeforeAccel) {
                    velocity.setY(airDrag * velocity.getY() + getGravityAccel().getY());
                } else {
                    velocity.setY(airDrag * (velocity.getY() + getGravityAccel().getY()));
                }
                if (isOnGround()) {
                    velocity.setX(velocity.getX() * slipMultiplier);
                    velocity.setY(0);
                    velocity.setZ(velocity.getZ() * slipMultiplier);
                } else {
                    velocity.setX(velocity.getX() * airDrag);
                    velocity.setZ(velocity.getZ() * airDrag);
                }
            }
        } else if (hasGravity() && !isOnGround()) {
            switch(location.getBlock().getType()) {
                case WATER:
                case LAVA:
                    velocity.setY(velocity.getY() + getGravityAccel().getY() / 4);
                    break;
                default:
                    velocity.setY(velocity.getY() + getGravityAccel().getY() / 4);
            }
        }
        setRawLocation(pendingLocation);
    }
}
Also used : ProjectileHitEvent(org.bukkit.event.entity.ProjectileHitEvent) Block(org.bukkit.block.Block) Location(org.bukkit.Location) Projectile(org.bukkit.entity.Projectile)

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