use of org.bukkit.event.entity.EntityDamageByEntityEvent in project Denizen-For-Bukkit by DenizenScript.
the class EntityKilledScriptEvent method onEntityKilled.
@EventHandler(priority = EventPriority.HIGH)
public void onEntityKilled(EntityDamageEvent event) {
entity = new EntityTag(event.getEntity());
// Check for possibility of death first
if (entity.isValid() && entity.isLivingEntity()) {
if (event.getFinalDamage() < entity.getLivingEntity().getHealth()) {
return;
}
} else {
return;
}
final_damage = new ElementTag(event.getFinalDamage());
cause = new ElementTag(CoreUtilities.toLowerCase(event.getCause().name()));
damager = null;
projectile = null;
if (event instanceof EntityDamageByEntityEvent) {
damager = new EntityTag(((EntityDamageByEntityEvent) event).getDamager());
if (damager.isProjectile()) {
projectile = damager;
if (damager.hasShooter()) {
damager = damager.getShooter();
}
}
}
this.event = event;
fire(event);
}
use of org.bukkit.event.entity.EntityDamageByEntityEvent in project Denizen-For-Bukkit by DenizenScript.
the class EntityDeathScriptEvent method onEntityDeath.
@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
LivingEntity livingEntity = event.getEntity();
EntityTag.rememberEntity(livingEntity);
entity = new EntityTag(livingEntity);
cause = null;
damager = null;
EntityDamageEvent lastDamage = entity.getBukkitEntity().getLastDamageCause();
if (lastDamage != null) {
cause = new ElementTag(event.getEntity().getLastDamageCause().getCause().toString());
if (lastDamage instanceof EntityDamageByEntityEvent) {
EntityTag damageEntity = new EntityTag(((EntityDamageByEntityEvent) lastDamage).getDamager());
EntityTag shooter = damageEntity.getShooter();
if (shooter != null) {
damager = shooter;
} else {
damager = damageEntity;
}
} else if (livingEntity.getKiller() != null) {
damager = new EntityTag(livingEntity.getKiller());
}
}
cancelled = false;
this.event = event;
fire(event);
EntityTag.forgetEntity(livingEntity);
}
use of org.bukkit.event.entity.EntityDamageByEntityEvent 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);
}
}
}
use of org.bukkit.event.entity.EntityDamageByEntityEvent in project Glowstone by GlowstoneMC.
the class GlowLivingEntity method damage.
@Override
public void damage(double amount, Entity source, @NotNull DamageCause cause) {
// invincibility timer
if (noDamageTicks > 0 || health <= 0 || !canTakeDamage(cause) || isInvulnerable()) {
return;
} else {
noDamageTicks = maximumNoDamageTicks;
}
// fire resistance
if (hasPotionEffect(PotionEffectType.FIRE_RESISTANCE)) {
if (source instanceof Fireball) {
return;
} else {
switch(cause) {
case FIRE:
case FIRE_TICK:
case HOT_FLOOR:
case LAVA:
return;
default:
}
}
}
// armor damage protection
// formula source: http://minecraft.gamepedia.com/Armor#Damage_Protection
double defensePoints = getAttributeManager().getPropertyValue(Key.KEY_ARMOR);
double toughness = getAttributeManager().getPropertyValue(Key.KEY_ARMOR_TOUGHNESS);
amount = amount * (1 - Math.min(20.0, Math.max(defensePoints / 5.0, defensePoints - amount / (2.0 + toughness / 4.0))) / 25);
// fire event
EntityDamageEvent event = EventFactory.getInstance().onEntityDamage(source == null ? new EntityDamageEvent(this, cause, amount) : new EntityDamageByEntityEvent(source, this, cause, amount));
if (event.isCancelled()) {
return;
}
// apply damage
amount = event.getFinalDamage();
lastDamage = amount;
if (isPlayerHit(source)) {
playerDamageTick = ticksLived;
if (health - amount <= 0) {
killer = determinePlayer(source);
if (killer != null) {
killer.incrementStatistic(Statistic.KILL_ENTITY, getType());
}
}
}
setHealth(health - amount);
playEffectKnownAndSelf(EntityEffect.HURT);
if (cause == DamageCause.ENTITY_ATTACK && source != null) {
Vector distance = RayUtil.getRayBetween(getLocation(), ((LivingEntity) source).getEyeLocation());
Vector rayLength = RayUtil.getVelocityRay(distance).normalize();
Vector currentVelocity = getVelocity();
currentVelocity.add(rayLength.multiply(((amount + 1) / 2d)));
setVelocity(currentVelocity);
}
// play sounds, handle death
if (health > 0) {
Sound hurtSound = getHurtSound();
if (hurtSound != null && !isSilent()) {
world.playSound(location, hurtSound, getSoundVolume(), getSoundPitch());
}
}
setLastDamager(source);
}
use of org.bukkit.event.entity.EntityDamageByEntityEvent in project Glowstone by GlowstoneMC.
the class GlowItemFrame method entityInteract.
// //////////////////////////////////////////////////////////////////////////
// Overrides
@Override
public boolean entityInteract(GlowPlayer player, InteractEntityMessage message) {
if (message.getAction() == Action.INTERACT.ordinal() && message.getHandSlot() == EquipmentSlot.HAND) {
if (InventoryUtil.isEmpty(getItem())) {
ItemStack isInHand = player.getItemInHand();
if (isInHand != null) {
setItem(isInHand);
if (player.getGameMode() != GameMode.CREATIVE) {
int amount = player.getItemInHand().getAmount();
isInHand.setAmount(amount - 1);
if (isInHand.getAmount() <= 0) {
isInHand = null;
}
player.setItemInHand(isInHand);
}
}
} else {
int rot = (getRotation().ordinal() + 1) % 8;
setRotation(Rotation.values()[rot]);
}
}
if (message.getAction() == Action.ATTACK.ordinal()) {
if (isEmpty()) {
if (EventFactory.getInstance().callEvent(new HangingBreakByEntityEvent(this, player)).isCancelled()) {
return false;
}
if (player.getGameMode() != GameMode.CREATIVE) {
world.dropItemNaturally(location, new ItemStack(Material.ITEM_FRAME));
}
remove();
} else {
if (EventFactory.getInstance().callEvent(new EntityDamageByEntityEvent(player, this, DamageCause.ENTITY_ATTACK, 0)).isCancelled()) {
return false;
}
if (player.getGameMode() != GameMode.CREATIVE) {
world.dropItemNaturally(location, getItem().clone());
}
setItem(InventoryUtil.createEmptyStack());
}
}
return true;
}
Aggregations