Java Code Examples for org.bukkit.event.entity.EntityDamageEvent.DamageCause#ENTITY_ATTACK
The following examples show how to use
org.bukkit.event.entity.EntityDamageEvent.DamageCause#ENTITY_ATTACK .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QAListener.java From QualityArmory with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("deprecation") @EventHandler public void onHit(EntityDamageByEntityEvent e) { if (e.isCancelled()) return; if (e.getDamager() instanceof Player) { Player d = (Player) e.getDamager(); if ((e.getCause() == DamageCause.ENTITY_ATTACK || e.getCause() == DamageCause.ENTITY_SWEEP_ATTACK)) { if (QualityArmory.isMisc(d.getItemInHand())) { CustomBaseObject aa = QualityArmory.getMisc(d.getItemInHand()); if (aa instanceof MeleeItems) { DEBUG("Setting damage for " + aa.getName() + " to be equal to " + ((MeleeItems) aa).getDamage() + ". was " + e.getDamage()); e.setDamage(((MeleeItems) aa).getDamage()); } if (aa.getSoundOnHit() != null) { e.getEntity().getWorld().playSound(e.getEntity().getLocation(), aa.getSoundOnHit(), 1, 1); } } } if (QualityArmory.isGun(d.getItemInHand()) || QualityArmory.isIronSights(d.getItemInHand())) DEBUG("The player " + e.getEntity().getName() + " was Hit with a gun! Damage=" + e.getDamage()); } }
Example 2
Source File: SlimefunBootsListener.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
private void stomp(EntityDamageEvent e) { Player p = (Player) e.getEntity(); p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ZOMBIE_BREAK_WOODEN_DOOR, 1F, 2F); p.setVelocity(new Vector(0.0, 0.7, 0.0)); for (Entity n : p.getNearbyEntities(4, 4, 4)) { if (n instanceof LivingEntity && !n.getUniqueId().equals(p.getUniqueId())) { Vector velocity = n.getLocation().toVector().subtract(p.getLocation().toVector()).normalize().multiply(1.4); n.setVelocity(velocity); if (!(n instanceof Player) || (p.getWorld().getPVP() && SlimefunPlugin.getProtectionManager().hasPermission(p, n.getLocation(), ProtectableAction.PVP))) { EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(p, n, DamageCause.ENTITY_ATTACK, e.getDamage() / 2); Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) ((LivingEntity) n).damage(e.getDamage() / 2); } } } for (BlockFace face : BlockFace.values()) { Block b = p.getLocation().getBlock().getRelative(BlockFace.DOWN).getRelative(face); p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType()); } }
Example 3
Source File: TalismanListener.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onDamageGet(EntityDamageEvent e) { if (e.getEntity() instanceof Player) { if (e.getCause() == DamageCause.LAVA) { Talisman.checkFor(e, SlimefunItems.TALISMAN_LAVA); } if (e.getCause() == DamageCause.DROWNING) { Talisman.checkFor(e, SlimefunItems.TALISMAN_WATER); } if (e.getCause() == DamageCause.FALL) { Talisman.checkFor(e, SlimefunItems.TALISMAN_ANGEL); } if (e.getCause() == DamageCause.FIRE) { Talisman.checkFor(e, SlimefunItems.TALISMAN_FIRE); } if (e.getCause() == DamageCause.ENTITY_ATTACK) { Talisman.checkFor(e, SlimefunItems.TALISMAN_KNIGHT); Talisman.checkFor(e, SlimefunItems.TALISMAN_WARRIOR); } if (e.getCause() == DamageCause.PROJECTILE && ((EntityDamageByEntityEvent) e).getDamager() instanceof Projectile) { Projectile projectile = (Projectile) ((EntityDamageByEntityEvent) e).getDamager(); if (Talisman.checkFor(e, SlimefunItems.TALISMAN_WHIRLWIND)) { returnProjectile((Player) e.getEntity(), projectile); } } } }
Example 4
Source File: SeismicAxe.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
private void pushEntity(Player p, Entity entity) { Vector vector = entity.getLocation().toVector().subtract(p.getLocation().toVector()).normalize(); vector.multiply(STRENGTH); vector.setY(0.9); entity.setVelocity(vector); if (entity.getType() != EntityType.PLAYER || p.getWorld().getPVP()) { EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(p, entity, DamageCause.ENTITY_ATTACK, 6D); Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) { ((LivingEntity) entity).damage(DAMAGE); } } }
Example 5
Source File: Game.java From HeavySpleef with GNU General Public License v3.0 | 5 votes |
public void onEntityDamageEvent(EntityDamageEvent event, SpleefPlayer damaged) { boolean disableDamage = getPropertyValue(GameProperty.DISABLE_DAMAGE); if (event.getCause() != DamageCause.ENTITY_ATTACK && disableDamage) { event.setCancelled(true); } }
Example 6
Source File: NPCEntity.java From NPCFactory with MIT License | 4 votes |
@Override public boolean damageEntity(DamageSource source, float damage) { if(godmode || noDamageTicks > 0) { return false; } DamageCause cause = null; org.bukkit.entity.Entity bEntity = null; if(source instanceof EntityDamageSource) { Entity damager = source.getEntity(); cause = DamageCause.ENTITY_ATTACK; if(source instanceof EntityDamageSourceIndirect) { damager = ((EntityDamageSourceIndirect) source).getProximateDamageSource(); if(damager.getBukkitEntity() instanceof ThrownPotion) { cause = DamageCause.MAGIC; } else if(damager.getBukkitEntity() instanceof Projectile) { cause = DamageCause.PROJECTILE; } } bEntity = damager.getBukkitEntity(); } else if(source == DamageSource.FIRE) cause = DamageCause.FIRE; else if(source == DamageSource.STARVE) cause = DamageCause.STARVATION; else if(source == DamageSource.WITHER) cause = DamageCause.WITHER; else if(source == DamageSource.STUCK) cause = DamageCause.SUFFOCATION; else if(source == DamageSource.DROWN) cause = DamageCause.DROWNING; else if(source == DamageSource.BURN) cause = DamageCause.FIRE_TICK; else if(source == CraftEventFactory.MELTING) cause = DamageCause.MELTING; else if(source == CraftEventFactory.POISON) cause = DamageCause.POISON; else if(source == DamageSource.MAGIC) { cause = DamageCause.MAGIC; } else if(source == DamageSource.OUT_OF_WORLD) { cause = DamageCause.VOID; } if(cause != null) { NPCDamageEvent event = new NPCDamageEvent(this, bEntity, cause, (double) damage); Bukkit.getPluginManager().callEvent(event); if(!event.isCancelled()) { return super.damageEntity(source, (float) event.getDamage()); } else { return false; } } if(super.damageEntity(source, damage)) { if(bEntity != null) { Entity e = ((CraftEntity) bEntity).getHandle(); double d0 = e.locX - this.locX; double d1; for(d1 = e.locZ - this.locZ; d0 * d0 + d1 * d1 < 0.0001D; d1 = (Math.random() - Math.random()) * 0.01D) { d0 = (Math.random() - Math.random()) * 0.01D; } a(e, damage, d0, d1); } return true; } else { return false; } }