Search in sources :

Example 11 with Projectile

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

the class ProjectileDispenseBehavior method dispenseStack.

@Override
protected ItemStack dispenseStack(GlowBlock block, ItemStack stack) {
    GlowWorld world = block.getWorld();
    Vector position = BlockDispenser.getDispensePosition(block);
    BlockFace face = BlockDispenser.getFacing(block);
    Projectile entity = getProjectileEntity(world, position);
    entity.setVelocity(new Vector(face.getModX(), face.getModY() + 0.1f, face.getModZ()).multiply(6));
    stack.setAmount(stack.getAmount() - 1);
    if (stack.getAmount() < 1) {
        return null;
    }
    return stack;
}
Also used : BlockFace(org.bukkit.block.BlockFace) GlowWorld(net.glowstone.GlowWorld) Vector(org.bukkit.util.Vector) Projectile(org.bukkit.entity.Projectile)

Example 12 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 13 with Projectile

use of org.bukkit.entity.Projectile in project Towny by ElgarL.

the class TownyEntityListener method onEntityCombustByEntityEvent.

/**
	 * Prevent fire arrows and charges igniting players when PvP is disabled
	 * 
	 * Can also prevent tnt from destroying armorstands
	 * 
	 * @param event
	 * @throws NotRegisteredException 
	 */
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityCombustByEntityEvent(EntityCombustByEntityEvent event) throws NotRegisteredException {
    if (plugin.isError()) {
        event.setCancelled(true);
        return;
    }
    Entity combuster = event.getCombuster();
    Entity defender = event.getEntity();
    LivingEntity attacker;
    if (combuster instanceof Projectile) {
        Object source = ((Projectile) combuster).getShooter();
        if (!(source instanceof LivingEntity)) {
            // TODO: prevent damage from dispensers
            return;
        } else {
            attacker = (LivingEntity) source;
        }
        // There is an attacker and Not war time.
        if ((attacker != null) && (!TownyUniverse.isWarTime())) {
            if (CombatUtil.preventDamageCall(plugin, attacker, defender)) {
                // Remove the projectile here so no
                // other events can fire to cause damage
                combuster.remove();
                event.setCancelled(true);
            }
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 14 with Projectile

use of org.bukkit.entity.Projectile in project Towny by ElgarL.

the class TownyEntityListener method onHangingBreak.

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onHangingBreak(HangingBreakEvent event) {
    if (plugin.isError()) {
        event.setCancelled(true);
        return;
    }
    TownyWorld townyWorld = null;
    String worldName = null;
    Entity hanging = event.getEntity();
    try {
        worldName = hanging.getWorld().getName();
        townyWorld = TownyUniverse.getDataSource().getWorld(worldName);
        if (!townyWorld.isUsingTowny())
            return;
    } catch (NotRegisteredException e1) {
        // event.setCancelled(true);
        return;
    }
    if (event instanceof HangingBreakByEntityEvent) {
        HangingBreakByEntityEvent evt = (HangingBreakByEntityEvent) event;
        Object remover = evt.getRemover();
        /*
			 * Check if this has a shooter.
			 */
        if (remover instanceof Projectile) {
            remover = ((Projectile) remover).getShooter();
        }
        if (remover instanceof Player) {
            Player player = (Player) remover;
            // Get destroy permissions (updates if none exist)
            boolean bDestroy = PlayerCacheUtil.getCachePermission(player, hanging.getLocation(), 321, (byte) 0, TownyPermission.ActionType.DESTROY);
            // Allow the removal if we are permitted
            if (bDestroy)
                return;
            /*
				 * Fetch the players cache
				 */
            PlayerCache cache = plugin.getCache(player);
            event.setCancelled(true);
            if (cache.hasBlockErrMsg())
                TownyMessaging.sendErrorMsg(player, cache.getBlockErrMsg());
        } else {
            // Explosions are blocked in this plot
            if (!locationCanExplode(townyWorld, hanging.getLocation()))
                event.setCancelled(true);
        }
    } else {
        switch(event.getCause()) {
            case EXPLOSION:
                if (!locationCanExplode(townyWorld, event.getEntity().getLocation()))
                    event.setCancelled(true);
                break;
            default:
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) HangingBreakByEntityEvent(org.bukkit.event.hanging.HangingBreakByEntityEvent) Player(org.bukkit.entity.Player) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) PlayerCache(com.palmergames.bukkit.towny.object.PlayerCache) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 15 with Projectile

use of org.bukkit.entity.Projectile in project Towny by ElgarL.

the class TownyEntityMonitorListener method onEntityDeath.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntityDeath(EntityDeathEvent event) {
    Entity defenderEntity = event.getEntity();
    TownyWorld World = null;
    try {
        World = TownyUniverse.getDataSource().getWorld(defenderEntity.getLocation().getWorld().getName());
        if (!World.isUsingTowny())
            return;
    } catch (NotRegisteredException e) {
        // World not registered with Towny.
        return;
    }
    // Was this a player death?
    if (defenderEntity instanceof Player) {
        // Killed by another entity?
        if (defenderEntity.getLastDamageCause() instanceof EntityDamageByEntityEvent) {
            EntityDamageByEntityEvent damageEvent = (EntityDamageByEntityEvent) defenderEntity.getLastDamageCause();
            Entity attackerEntity = damageEvent.getDamager();
            Player defenderPlayer = (Player) defenderEntity;
            Player attackerPlayer = null;
            Resident attackerResident = null;
            Resident defenderResident = null;
            try {
                defenderResident = TownyUniverse.getDataSource().getResident(defenderPlayer.getName());
            } catch (NotRegisteredException e) {
                return;
            }
            // Was this a missile?
            if (attackerEntity instanceof Projectile) {
                Projectile projectile = (Projectile) attackerEntity;
                if (projectile.getShooter() instanceof Player) {
                    attackerPlayer = (Player) projectile.getShooter();
                    try {
                        attackerResident = TownyUniverse.getDataSource().getResident(attackerPlayer.getName());
                    } catch (NotRegisteredException e) {
                    }
                }
            } else if (attackerEntity instanceof Player) {
                // This was a player kill
                attackerPlayer = (Player) attackerEntity;
                try {
                    attackerResident = TownyUniverse.getDataSource().getResident(attackerPlayer.getName());
                } catch (NotRegisteredException e) {
                }
            }
            /*
				 * If attackerPlayer or attackerResident are null at this point
				 * it was a natural death, not PvP.
				 */
            deathPayment(attackerPlayer, defenderPlayer, attackerResident, defenderResident);
            wartimeDeathPoints(attackerPlayer, defenderPlayer, attackerResident, defenderResident);
            if (TownySettings.isRemovingOnMonarchDeath())
                monarchDeath(attackerPlayer, defenderPlayer, attackerResident, defenderResident);
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) 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