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;
}
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()));
}
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