Search in sources :

Example 66 with Projectile

use of org.bukkit.entity.Projectile in project modules-extra by CubeEngine.

the class ListenerVehicle method onVehicleDestroy.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onVehicleDestroy(final VehicleDestroyEvent event) {
    Entity causer;
    if (event.getAttacker() != null) {
        if (event.getAttacker() instanceof Player) {
            causer = event.getAttacker();
        } else if (event.getAttacker() instanceof Projectile) {
            ProjectileSource shooter = ((Projectile) event.getAttacker()).getShooter();
            if (shooter instanceof Player) {
                causer = (Player) shooter;
            } else if (shooter instanceof Entity) {
                causer = (Entity) shooter;
            } else {
                // TODO other ProjectileSources
                return;
            }
        } else {
            causer = event.getAttacker();
        }
    } else if (event.getVehicle().getPassenger() instanceof Player) {
        causer = event.getVehicle().getPassenger();
    } else {
        // TODO why?
        return;
    }
    if (causer instanceof Player) {
        VehicleBreak action = this.newAction(VehicleBreak.class, event.getVehicle().getWorld());
        if (action != null) {
            action.setLocation(event.getVehicle().getLocation());
            action.setVehicle(event.getVehicle());
            action.setPlayer((Player) causer);
            this.logAction(action);
        }
    } else {
    // TODO EntityVehicleBreak
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.player.Player) ProjectileSource(org.bukkit.projectiles.ProjectileSource) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 67 with Projectile

use of org.bukkit.entity.Projectile in project modules-extra by CubeEngine.

the class ListenerDeath method onEntityDeath.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntityDeath(EntityDeathEvent event) {
    // TODO handle when there is no reference on lookup of dependent actions
    DeathKill killAction = this.newAction(DeathKill.class, event.getEntity().getWorld());
    if (killAction != null) {
        // TODO check config for killer type
        killAction.setLocation(event.getEntity().getLocation());
        EntityDamageEvent cause = event.getEntity().getLastDamageCause();
        if (cause == null) {
            killAction.otherKiller = DamageCause.CUSTOM;
        } else if (cause instanceof EntityDamageByEntityEvent) {
            Entity damager = ((EntityDamageByEntityEvent) cause).getDamager();
            if (damager instanceof Player) {
                killAction.playerKiller = new PlayerSection((Player) damager);
            } else if (damager instanceof Projectile) {
                killAction.projectile = true;
                if (((Projectile) damager).getShooter() instanceof Entity) {
                    if (((Projectile) damager).getShooter() instanceof Player) {
                        killAction.playerKiller = new PlayerSection((Player) ((Projectile) damager).getShooter());
                    } else {
                        killAction.entityKiller = new EntitySection((Entity) ((Projectile) damager).getShooter());
                    }
                } else {
                    killAction.entityKiller = new EntitySection(damager);
                }
            } else {
                killAction.entityKiller = new EntitySection(damager);
            }
        } else {
            killAction.otherKiller = cause.getCause();
        }
        this.logAction(killAction);
    }
    Reference<DeathKill> reference = this.reference(killAction);
    LivingEntity killed = event.getEntity();
    if (killed instanceof Player) {
        DeathPlayer action = this.newAction(DeathPlayer.class, killed.getWorld());
        if (action != null) {
            action.killer = reference;
            action.setPlayer((Player) killed);
            this.logAction(action);
        }
        if (this.isActive(DeathDrop.class, event.getEntity().getWorld())) {
            Reference<DeathPlayer> deathRef = this.reference(action);
            for (ItemStack itemStack : event.getDrops()) {
                PlayerDeathDrop dropAction = newAction(PlayerDeathDrop.class);
                dropAction.item = itemStack;
                dropAction.death = deathRef;
                this.logAction(dropAction);
            }
        }
        return;
    }
    Class<? extends EntityDeathAction> actionType;
    if (killed instanceof Wither || killed instanceof EnderDragon) {
        actionType = DeathBoss.class;
    } else if (killed instanceof Animals) {
        if (killed instanceof Tameable && ((Tameable) killed).isTamed()) {
            actionType = DeathPet.class;
        } else {
            actionType = DeathAnimal.class;
        }
    } else if (killed instanceof Villager) {
        actionType = DeathNpc.class;
    } else if (killed instanceof Monster) {
        actionType = DeathMonster.class;
    } else {
        actionType = DeathOther.class;
    }
    EntityDeathAction action = this.newAction(actionType, killed.getWorld());
    if (action != null) {
        action.setKilled(killed);
        action.setLocation(killed.getLocation());
        action.killer = reference;
        this.logAction(action);
    }
    Reference<EntityDeathAction> deathRef = this.reference(action);
    if (this.isActive(DeathDrop.class, event.getEntity().getWorld())) {
        for (ItemStack itemStack : event.getDrops()) {
            DeathDrop dropAction = newAction(DeathDrop.class);
            dropAction.item = itemStack;
            dropAction.death = deathRef;
            this.logAction(dropAction);
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.spongepowered.api.entity.Entity) PlayerSection(org.cubeengine.module.log.action.block.player.ActionPlayerBlock.PlayerSection) LivingEntity(org.bukkit.entity.LivingEntity) EnderDragon(org.bukkit.entity.EnderDragon) Monster(org.bukkit.entity.Monster) Villager(org.bukkit.entity.Villager) EntitySection(org.cubeengine.module.log.action.block.entity.ActionEntityBlock.EntitySection) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) Wither(org.bukkit.entity.Wither) Player(org.spongepowered.api.entity.player.Player) Tameable(org.bukkit.entity.Tameable) Projectile(org.bukkit.entity.Projectile) Animals(org.bukkit.entity.Animals) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) ItemStack(org.spongepowered.api.item.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 68 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 69 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 70 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)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