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
}
}
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);
}
}
}
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);
}
}
}
}
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:
}
}
}
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);
}
}
}
Aggregations