protected void b(float f) { if (f > 1.0F) { this.makeSound("mob.horse.land", 0.4F, 1.0F); } int i = MathHelper.f(f * 0.5F - 3.0F); if (i > 0) { // CraftBukkit start - fire EntityDamageEvent EntityDamageEvent event = CraftEventFactory.callEntityDamageEvent( null, this, EntityDamageEvent.DamageCause.FALL, i); if (!event.isCancelled()) { float damage = (float) event.getDamage(); if (damage > 0) { this.getBukkitEntity().setLastDamageCause(event); this.damageEntity(DamageSource.FALL, damage); } } if (this.passenger != null) { EntityDamageEvent passengerEvent = CraftEventFactory.callEntityDamageEvent( null, this.passenger, EntityDamageEvent.DamageCause.FALL, i); if (!passengerEvent.isCancelled() && this.passenger != null) { // Check again in case of plugin float damage = (float) passengerEvent.getDamage(); if (damage > 0) { this.passenger.getBukkitEntity().setLastDamageCause(passengerEvent); this.passenger.damageEntity(DamageSource.FALL, damage); } } // CraftBukkit end } Block block = this.world.getType( MathHelper.floor(this.locX), MathHelper.floor(this.locY - 0.2D - (double) this.lastYaw), MathHelper.floor(this.locZ)); if (block.getMaterial() != Material.AIR) { StepSound stepsound = block.stepSound; this.world.makeSound( this, stepsound.getStepSound(), stepsound.getVolume1() * 0.5F, stepsound.getVolume2() * 0.75F); } } }
@EventHandler public void onEntityDamage(EntityDamageEvent event) { if (event.isCancelled()) { return; } Entity entity = event.getEntity(); if (!(entity instanceof Player)) { return; } if (instance.getCitizensCommunicator().isNPC(entity, instance) || Utils.getInstance().isUnrestricted((Player) entity) || CombatTagComunicator.isNPC(entity)) { return; } Player player = (Player) entity; String name = player.getName().toLowerCase(); if (PlayerCache.getInstance().isAuthenticated(name)) { return; } if (!data.isAuthAvailable(name)) { if (!Settings.isForcedRegistrationEnabled) { return; } } player.setFireTicks(0); event.setCancelled(true); }
@EventHandler(priority = EventPriority.HIGHEST) public void onEntityDamageEvent(EntityDamageEvent event) { if (event.isCancelled()) { return; } if (!(event.getEntity() instanceof Player)) { return; } Player p = (Player) event.getEntity(); ItemStack iimh = p.getEquipment().getItemInMainHand(); Tier t = iimh != null ? TierUtil.getTierFromItemStack(iimh) : null; if (t != null && t.isInfiniteDurability()) { p.getEquipment().getItemInMainHand().setDurability((short) 0); } for (ItemStack is : p.getEquipment().getArmorContents()) { if (is == null || is.getType() == Material.AIR) { continue; } t = TierUtil.getTierFromItemStack(is); if (t == null) { continue; } if (t.isInfiniteDurability()) { is.setDurability((short) 0); } } }
@EventHandler(priority = EventPriority.MONITOR) public void onEntityDamage(EntityDamageEvent event) { if (event.isCancelled()) { return; } Entity p2 = event.getEntity(); db.i( "onEntityDamage: cause: " + event.getCause().name() + " : " + event.getEntity().toString()); if ((p2 == null) || (!(p2 instanceof Player))) { return; } Arena arena = Arenas.getArenaByPlayer((Player) p2); if (arena == null) { // defender no arena player => out return; } Player defender = (Player) p2; ArenaPlayer apDefender = ArenaPlayer.parsePlayer(defender); if (arena.REALEND_ID != -1 || (!apDefender.getStatus().equals(Status.EMPTY) && !apDefender.getStatus().equals(Status.FIGHT))) { event.setCancelled(true); return; } }
@EventHandler(priority = EventPriority.HIGH) public void onEntityDamage(EntityDamageEvent event_) { // If the event is cancelled, then we want to return. if (event_.isCancelled() == true) return; // Block damage in creative world. WorldConfig wm = new WorldConfig(); if (!wm.getIsRpg(event_.getEntity().getWorld().getName())) return; // Store event. event = event_; // Set defaults. setGlobalDefaults(); // Always set event damage to 0. event.setDamage(0); boolean dealEnviromentalDamage = false; // For entity damage events we want to handle the attck normally. if (event instanceof EntityDamageByEntityEvent) { Entity damager = ((EntityDamageByEntityEvent) event).getDamager(); if (damager.getType() == EntityType.WITHER) dealEnviromentalDamage = true; else if (damager.getType() == EntityType.WITHER_SKULL) dealEnviromentalDamage = true; else if (damager.getType() == EntityType.SPLASH_POTION) dealEnviromentalDamage = true; else if (damager.getType() == EntityType.PRIMED_TNT) dealEnviromentalDamage = true; else entityAttack((EntityDamageByEntityEvent) event, -1); } else dealEnviromentalDamage = true; // Else we want to deal the damage to the player/mob as though not from an entity. if (dealEnviromentalDamage == true) { // If the defender is a player, then we attacker player defender. if (event.getEntity() instanceof Player) { Player player = (Player) event.getEntity(); // Prevent damage done to already dead players if (FC_Rpg.rpgEntityManager.getRpgPlayer(player).playerConfig.getIsActive() == true) { if (FC_Rpg.rpgEntityManager.getRpgPlayer(player).getIsAlive() == false) return; } // Prepare the defender. prepareDefender(player); double damage = getEnviromentalDamage(player); if (damage == 0) return; // Attack the player with enviromental damage. edm.attackPlayerDefender( rpgDefender, null, null, damage, damageType, event.getCause().toString()); } else { // If the event entity is a livingentity and the damage isn't fall damage, then nuke. if (event.getCause() != DamageCause.FALL && event.getEntity() instanceof LivingEntity) edm.nukeMob((LivingEntity) event.getEntity()); } } }
@EventHandler public void onEntityDamage(EntityDamageEvent event) { if (!(event.isCancelled()) && ((event.getCause().equals(DamageCause.ENTITY_EXPLOSION)) || (event.getCause().equals(DamageCause.BLOCK_EXPLOSION))) && (event.getEntity() instanceof Player)) { Player player = (Player) event.getEntity(); Hero hero = plugin.getCharacterManager().getHero(player); if (hero.hasEffect("BlastResistance")) { int level = hero.getSkillLevel(this.skill); double amount = (SkillConfigManager.getUseSetting( hero, this.skill, Setting.AMOUNT.node(), 0.25, false) + (SkillConfigManager.getUseSetting( hero, this.skill, "amount-increase", 0.0, false) * level)); if (hst != null) amount += (SkillConfigManager.getUseSetting(hero, skill, "hst-amount", 0.0, false) * (hst.getSkillLevel(hero, skill) - 1)); amount = amount > 0 ? amount : 0; event.setDamage((int) (event.getDamage() * (1 - amount))); } } }
public static EventData getEventData(EntityDamageEvent event) { if (event == null) return null; DamageType damageElement = DamageType.get(event.getCause()); Entity attacker = null; Projectile projectile = null; Entity target = event.getEntity(); World world = target.getWorld(); if (event instanceof EntityDamageByEntityEvent) { EntityDamageByEntityEvent event_EE = (EntityDamageByEntityEvent) event; Entity damager = event_EE.getDamager(); if (damager instanceof Projectile) { projectile = (Projectile) damager; attacker = projectile.getShooter(); } else { attacker = damager; } } return myInfo.makeData( attacker, projectile, target, world, damageElement, event.getDamage(), event.isCancelled()); }
@EventHandler(priority = EventPriority.LOWEST) public void onEntityDamage(EntityDamageEvent event) { if (event.getEntity() instanceof SpoutPlayer) { event.setCancelled( event.isCancelled() || !((SpoutPlayer) event.getEntity()).isPreCachingComplete()); } }
// Damage Hook public void onEntityDamage(EntityDamageEvent event) { // No point in running if this has been stopped if (event.isCancelled()) { return; } // Is this a player? if (event.getEntity() instanceof Player) { Player player = (Player) event.getEntity(); PotionEntry entry = getPlugin().BuffList.get(player); // Elixir of Obsidian Skin if (entry != null && entry.HasBuff.get(Name) != null && entry.HasBuff.get(Name)) { // Halve all damages that have sources. // (Note, this means that direct damage through plugins // and such are left alone) if (event.getCause() != null) { int damage = event.getDamage(); damage = (int) (damage * 0.5); damage = Math.max(damage, 1); event.setDamage(damage); } } } }
// Non-Living Entities such as EntityEnderCrystal need to call this public static boolean handleNonLivingEntityDamageEvent( Entity entity, DamageSource source, int damage) { if (!(source instanceof EntityDamageSource)) { return false; } EntityDamageEvent event = handleEntityDamageEvent(entity, source, damage); return event.isCancelled() || event.getDamage() == 0; }
public void onEntityDamage(EntityDamageEvent event) { if (event.isCancelled()) return; if (event.getEntity() instanceof Player) { String playerName = ((Player) event.getEntity()).getName(); if (AdminHandler.isGod(playerName)) event.setCancelled(true); } }
@EventHandler public void onEntityDamage(EntityDamageEvent event) { Heroes.debug.startTask("HeroesSkillListener"); if ((event.isCancelled()) || (!(event instanceof EntityDamageByEntityEvent))) { Heroes.debug.stopTask("HeroesSkillListener"); return; } Entity projectile = ((EntityDamageByEntityEvent) event).getDamager(); if ((!(projectile instanceof Arrow)) || (!(((Projectile) projectile).getShooter() instanceof Player))) { Heroes.debug.stopTask("HeroesSkillListener"); return; } Player player = (Player) ((Projectile) projectile).getShooter(); Hero hero = SkillExplodingArrow.this.plugin.getCharacterManager().getHero(player); if (!hero.hasEffect("ExplodingArrowBuff")) { Heroes.debug.stopTask("HeroesSkillListener"); return; } int radius = (int) Math.pow( SkillConfigManager.getUseSetting(hero, this.skill, "radius", 5, false), 2.0D); float damage = SkillConfigManager.getUseSetting(hero, this.skill, "DAMAGE", 5, false); float blockdamage = damage; int block_dmg = SkillConfigManager.getUseSetting(hero, this.skill, "block-dmg", 0, false); if (block_dmg == 0) { blockdamage = 0.0F; for (Entity t_entity : player.getWorld().getEntities()) { if ((t_entity instanceof Player)) { Player heroes = (Player) t_entity; if (heroes.getLocation().distanceSquared(projectile.getLocation()) <= radius) SkillExplodingArrow.damageEntity( heroes, player, (int) damage, EntityDamageEvent.DamageCause.ENTITY_EXPLOSION); } else if ((t_entity instanceof Creature)) { Creature mob = (Creature) t_entity; if (t_entity.getLocation().distanceSquared(projectile.getLocation()) <= radius) { SkillExplodingArrow.damageEntity( mob, player, (int) damage, EntityDamageEvent.DamageCause.ENTITY_EXPLOSION); } } } } projectile.getWorld().createExplosion(projectile.getLocation(), blockdamage); Heroes.debug.stopTask("HeroesSkillListener"); }
/* (non-Javadoc) * @see org.bukkit.event.entity.EntityListener#onEntityDamage(org.bukkit.event.entity.EntityDamageEvent) */ @Override public void onEntityDamage(EntityDamageEvent event) { if (!event.isCancelled() && (event.getCause().equals(DamageCause.FIRE) || event.getCause().equals(DamageCause.FIRE_TICK) || event.getCause().equals(DamageCause.LAVA))) { if (event.getEntity() instanceof Player) { Player p = (Player) event.getEntity(); if (ConfigManager.getPortalMaterial().equals(Material.STATIONARY_LAVA)) { Location current = p.getLocation(); Stargate closest = Stargate.FindClosestStargate(current); if (closest != null) { double blockDistanceSquared = Stargate.distanceSquaredToClosestGateBlock(current, closest); if (closest.Active && ((blockDistanceSquared <= closest.GateShape.woosh_depth_squared && closest.GateShape.woosh_depth != 0) || blockDistanceSquared <= 16)) { WormholeXTreme.thisPlugin.prettyLog( Level.FINE, false, "Blocked Gate: \"" + closest.Name + "\" Proximity Event: \"" + event.getCause().toString() + "\" On: \"" + p.getName() + "\" Distance Squared: \"" + blockDistanceSquared + "\""); event.setCancelled(true); p.setFireTicks(0); } else if (!closest.Active && blockDistanceSquared <= 4) { WormholeXTreme.thisPlugin.prettyLog( Level.FINE, false, "Blocked Gate: \"" + closest.Name + "\" Proximity Event: \"" + event.getCause().toString() + "\" On: \"" + p.getName() + "\" Distance Squared: \"" + blockDistanceSquared + "\""); event.setCancelled(true); p.setFireTicks(0); } } } } } }
@EventHandler(priority = EventPriority.HIGHEST) public void onEntityDamage(EntityDamageEvent event) { if (!ModDamage.isEnabled || event.isCancelled()) return; if (!event.isCancelled() && (event.getEntity() instanceof LivingEntity)) { EventData data = getEventData(event); if (data != null) { runRoutines(data); int newDamage = data.get(Integer.class, data.start + 5); event.setCancelled(data.get(Boolean.class, data.start + data.objects.length - 1)); if (event.getDamage() != newDamage && newDamage <= 0) event.setCancelled(true); event.setDamage(newDamage); } else PluginConfiguration.log.severe( "[" + Bukkit.getPluginManager().getPlugin("ModDamage").getDescription().getName() + "] Error! Unhandled damage event. Is Bukkit and ModDamage up-to-date?"); } }
@SuppressWarnings("deprecation") @EventHandler() public void onEntityDamage(EntityDamageEvent event) { if (event.isCancelled()) return; Entity victim = event.getEntity(); // Apply Wolf Armor or Invincibiliy JailPrisoner prisoner = Jail.guards.get(victim); JailZone jail = prisoner != null ? prisoner.getJail() : null; if (prisoner != null) { if (jail.getSettings().getBoolean(Setting.GuardInvincibility)) { event.setCancelled(true); return; } int newArmor = (int) (event.getDamage() - (event.getDamage() * jail.getSettings().getInt(Setting.GuardArmor) / 100)); if (newArmor <= 0) newArmor = 1; event.setDamage(newArmor); if (event instanceof EntityDamageByEntityEvent) { EntityDamageByEntityEvent eventD = (EntityDamageByEntityEvent) event; if (eventD.getDamager() instanceof LivingEntity) prisoner.getPossibleGuardTargets().add((LivingEntity) eventD.getDamager()); } } if (!(event instanceof EntityDamageByEntityEvent)) return; EntityDamageByEntityEvent newevent = (EntityDamageByEntityEvent) event; Entity damager = newevent.getDamager(); prisoner = Jail.guards.get(damager); jail = prisoner != null ? prisoner.getJail() : null; // Apply Wolf damage and damage speed change if (prisoner != null) { if (new Random().nextInt(100) > jail.getSettings().getInt(Setting.GuardAttackSpeedPercent)) { event.setCancelled(true); return; } event.setDamage(jail.getSettings().getInt(Setting.GuardDamage)); } jail = JailZoneManager.getJail(victim.getLocation()); if (jail != null && jail.getSettings().getBoolean(Setting.EnablePVPProtection) && victim instanceof Player && damager instanceof Player) { event.setCancelled(true); return; } }
public void onEntityDamage(EntityDamageEvent event) { if (event.isCancelled()) return; if (!Whitelist.worldCheck(event.getEntity().getWorld())) return; if (!(event.getEntity() instanceof Player)) return; if (!Whitelist.hasLevel((Player) event.getEntity(), plugin.thisPlug)) return; if (event.getCause() != DamageCause.FALL) return; Player p = (Player) event.getEntity(); int lvl = LevelFunctions.getLevel(p, plugin.thisPlug); int damageReduction = (int) ((lvl / 10) * plugin.LCConfiguration.fdMultiplier); if (event.getDamage() <= damageReduction) { event.setDamage(0); } else { event.setDamage(event.getDamage() - damageReduction); } }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onEntityDamage(EntityDamageEvent event) { if (event.isCancelled()) return; Log.logInfo("OnEntityDamage (victim: " + event.getEntity().toString() + ")", EXTREME); // Check if the damager is a player - if so, weapon is the held tool if (event instanceof EntityDamageByEntityEvent) { EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event; if (e.getEntity() == null) { Log.logInfo("EntityDamageByEntity but .getEntity() is null?"); return; } } OccurredEvent drop = new OccurredEvent(event, "hit"); parent.sectionManager.performDrop(drop); }
protected void b(float f) { super.b(f); MobEffect mobeffect = this.getEffect(MobEffectList.JUMP); float f1 = mobeffect != null ? (float) (mobeffect.getAmplifier() + 1) : 0.0F; // CraftBukkit start float i = MathHelper.f(f - 3.0F - f1); if (i > 0) { EntityDamageEvent event = CraftEventFactory.callEntityDamageEvent( null, this, EntityDamageEvent.DamageCause.FALL, i); if (event.isCancelled()) { return; } i = (float) event.getDamage(); if (i > 0) { this.getBukkitEntity().setLastDamageCause(event); } } // CraftBukkit end if (i > 0) { if (i > 4) { this.makeSound("damage.fallbig", 1.0F, 1.0F); } else { this.makeSound("damage.fallsmall", 1.0F, 1.0F); } this.damageEntity(DamageSource.FALL, (float) i); int j = this.world.getTypeId( MathHelper.floor(this.locX), MathHelper.floor(this.locY - 0.20000000298023224D - (double) this.height), MathHelper.floor(this.locZ)); if (j > 0) { StepSound stepsound = Block.byId[j].stepSound; this.makeSound( stepsound.getStepSound(), stepsound.getVolume1() * 0.5F, stepsound.getVolume2() * 0.75F); } } }
// Damage Hook public void onEntityDamage(EntityDamageEvent event) { // No point in running if this has been stopped if (event.isCancelled()) { return; } // Check if Firetouch user hit another entity ElixirMod plugin = getPlugin(); if (event instanceof EntityDamageByEntityEvent) { Entity damager = ((EntityDamageByEntityEvent) event).getDamager(); Entity damagee = event.getEntity(); // Check if damager is a player if (damager instanceof Player) { Player player = (Player) damager; PotionEntry entry = plugin.BuffList.get(player); // See if that player has Firetouch if (entry != null) { if (entry.HasBuff.get(Name) != null && entry.HasBuff.get(Name)) { // Check if we can ignite with any damage, else unarmed only boolean canIgnite = false; if (unarmedOnly) { if (((Player) damager).getItemInHand().getTypeId() == 0) { canIgnite = true; } } else { canIgnite = true; } if (canIgnite) { // If target is on fire, ignore, else ignite if (damagee.getFireTicks() <= 0) { // Chance ignite int chance = 1 + (int) (Math.random() * (100 - 1)); if (chance <= igniteChance) { damagee.setFireTicks(igniteLength * 20); } } } } } } } }
@Override public void onEntityDamage(EntityDamageEvent event) { if (event.isCancelled()) { return; } // Check if the event is about a player that is drowning if (event.getCause() == EntityDamageEvent.DamageCause.DROWNING && event.getEntity() instanceof CraftPlayer) { final CraftPlayer player = (CraftPlayer) event.getEntity(); // Check if user got unlimited air node if (PermissionsHandler.hasPermission(player, Gills.getConfig().unlimitedAirNode)) { updatePlayerAirBubbles(player); event.setCancelled(true); return; } // Check if user access to gills if (!PermissionsHandler.hasPermission(player, Gills.getConfig().userNode)) { return; } int depth = getDepth(player); // Check itemsets for (GillsItemSet itemSet : Gills.getConfig().itemSets) { if (PermissionsHandler.hasPermission(player, itemSet.getNode()) && itemSet.isTargetDepth(depth) && itemSet.isTargetAltitude(player.getLocation().getBlockY()) && itemSet.isWorldAllowed(player.getLocation().getWorld().getName()) && itemSet.gotRequiredItems(player)) { // Check is inside itemSet itemSet.consumeRequiredItems(player); updatePlayerAirBubbles(player); event.setCancelled(true); return; } } } }
@Override public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { throw new NotEnoughArgumentsException(); } for (Player matchPlayer : server.matchPlayer(args[0])) { final EntityDamageEvent ede = new EntityDamageEvent(matchPlayer, sender instanceof Player && ((Player)sender).getName().equals(matchPlayer.getName()) ? EntityDamageEvent.DamageCause.SUICIDE : EntityDamageEvent.DamageCause.CUSTOM, Short.MAX_VALUE); server.getPluginManager().callEvent(ede); if (ede.isCancelled() && !sender.hasPermission("essentials.kill.force")) { continue; } matchPlayer.damage(Short.MAX_VALUE); sender.sendMessage(_("kill", matchPlayer.getDisplayName())); } }
protected void a(int i) { if (!this.bD) { // CraftBukkit start if (this instanceof EntityLiving) { CraftServer server = ((WorldServer) this.world).getServer(); org.bukkit.entity.Entity damagee = this.getBukkitEntity(); DamageCause damageType = EntityDamageEvent.DamageCause.FIRE; int damageDone = i; EntityDamageEvent event = new EntityDamageEvent(damagee, damageType, damageDone); server.getPluginManager().callEvent(event); if (event.isCancelled()) { return; } i = event.getDamage(); } // CraftBukkit end this.damageEntity((Entity) null, i); } }
@EventHandler public void entityDamageEvent(EntityDamageEvent e) { if (e.isCancelled()) return; if (!Minegusta.getServer().containsWorld(e.getEntity().getWorld())) return; DwarfPower arrowWeakness = DwarfPower.arrowWeaknesBoost(e); ElfPower fireWeakness = ElfPower.fireDamage(e); EnderbornPower fallDamage = EnderbornPower.fallDamageBoost(e); if (arrowWeakness.isProjectile() && arrowWeakness.isPlayer() && arrowWeakness.isDwarf() && arrowWeakness.canPVP()) { arrowWeakness.applyProjectileWeakness(); } if (fireWeakness.isFireDamage() && fireWeakness.isPlayer() && fireWeakness.isElf()) { fireWeakness.applyFireDamage(); } if (fallDamage.isPlayer() && fallDamage.entityIsEnderBorn() && fallDamage.isFallDamage()) { fallDamage.cancelFallDamae(); } }
@EventHandler public void onEntityDamage(EntityDamageEvent event) { if (event.isCancelled()) { return; } LivingEntity attacker = null; Entity defender = event.getEntity(); if (event.getCause() == EntityDamageEvent.DamageCause.ENTITY_ATTACK) { EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event; if ((e.getDamager() instanceof LivingEntity)) attacker = (LivingEntity) e.getDamager(); } else if (event.getCause() == EntityDamageEvent.DamageCause.PROJECTILE) { EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event; Projectile arrow = (Projectile) e.getDamager(); if ((arrow.getShooter() instanceof LivingEntity)) { attacker = arrow.getShooter(); } } if (((attacker instanceof Player)) && ((defender instanceof LivingEntity)) && (!attacker.equals(defender))) { perPlayer per = (perPlayer) data.get(attacker); if (per != null) per.setTarget((LivingEntity) defender); } }
/** * In this entity-damage-listener we will cancel fall damage and suffocation damage for vampires. * We will also modify the damage dealt. */ @EventHandler(priority = EventPriority.HIGH) public void onEntityDamageHigh(EntityDamageEvent event) { if (event.isCancelled()) return; // Define local fields Entity damagee; Player pDamagee; VPlayer vpDamagee; EntityDamageByEntityEvent edbeEvent; Entity damager; Player pDamager; VPlayer vpDamager; damagee = event.getEntity(); // If the damagee is a player if (damagee instanceof Player) { pDamagee = (Player) damagee; vpDamagee = VPlayers.i.get(pDamagee); // Vampires can not drown or take fall damage or starve if (vpDamagee.isVampire() && Conf.vampiresCantTakeDamageFrom.contains(event.getCause())) { event.setCancelled(true); return; } } // For further interest this must be a close combat attack by another entity if (event.getCause() != DamageCause.ENTITY_ATTACK) return; if (!(event instanceof EntityDamageByEntityEvent)) return; edbeEvent = (EntityDamageByEntityEvent) event; damager = edbeEvent.getDamager(); // For further interest that attacker must be a player. if (!(damager instanceof Player)) return; pDamager = (Player) damager; vpDamager = VPlayers.i.get(pDamager); // The damage will be modified under certain circumstances. float damage = event.getDamage(); // Modify damage if damager is a vampire if (vpDamager.isVampire()) { damage *= vpDamager.getDamageDealtFactor(); } // Modify damage if damagee is a vampire if (damagee instanceof Player) { pDamagee = (Player) damagee; vpDamagee = VPlayers.i.get(pDamagee); if (vpDamagee.isVampire()) { Material itemMaterial = pDamager.getItemInHand().getType(); if (Conf.woodMaterials.contains(itemMaterial)) { damage = Conf.damageReceivedWood; // Just as much as a diamond sword. vpDamagee.msg(Lang.messageWoodCombatWarning, Txt.getMaterialName(itemMaterial)); } else { damage *= vpDamagee.getDamageReceivedFactor(); } } } event.setDamage(Math.round(damage)); }
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onPlayerDamage(EntityDamageEvent event) { if (event.getEntity() instanceof Player) { Player player = (Player) event.getEntity(); BendingPlayer bender = BendingPlayer.getBendingPlayer(player); String ability = bender.getAbility(); if (event.getCause() == DamageCause.FALL) { BendingPassiveAbility ab = null; if (bender != null && bender.isBender(BendingElement.EARTH)) { ab = new EarthPassive( AbilityManager.getManager().getRegisteredAbility(EarthPassive.NAME), player); if (ab.start()) { AbilityManager.getManager().addInstance(ab); player.setFallDistance(0); event.setDamage(0); event.setCancelled(true); return; } if (MetalWire.hasNoFallDamage(player)) { player.setFallDistance(0); event.setDamage(0); event.setCancelled(true); return; } } if (bender != null && bender.isBender(BendingElement.AIR) && EntityTools.canBendPassive(player, BendingElement.AIR)) { if (AirBurst.NAME.equals(ability)) { BendingActiveAbility burst = AbilityManager.getManager().buildAbility(AirBurst.NAME, player); if (burst.canBeInitialized()) { burst.fall(); if (burst.getState() != BendingAbilityState.START && burst.getState() != BendingAbilityState.ENDED) { AbilityManager.getManager().addInstance(burst); } } } player.setFallDistance(0); event.setDamage(0); event.setCancelled(true); return; } if (!event.isCancelled() && EntityTools.isBender(player, BendingElement.WATER)) { ab = new WaterPassive( AbilityManager.getManager().getRegisteredAbility(WaterPassive.NAME), player); AbilityManager.getManager().addInstance(ab); if (ab.start()) { player.setFallDistance(0); event.setDamage(0); event.setCancelled(true); return; } } if (!event.isCancelled() && bender.isBender(BendingElement.MASTER) && EntityTools.canBendPassive(player, BendingElement.MASTER)) { event.setDamage((int) (event.getDamage() * (Settings.MASTER_FALL_REDUCTION / 100.))); if (event.getEntity().getFallDistance() < 10) { event.setCancelled(true); return; } } if (!event.isCancelled() && EntityTools.isFallImmune(player)) { event.setCancelled(true); return; } } if (EntityTools.canBendPassive(player, BendingElement.FIRE) && EntityTools.isBender(player, BendingElement.FIRE) && ((event.getCause() == DamageCause.FIRE) || (event.getCause() == DamageCause.FIRE_TICK))) { event.setCancelled(!Enflamed.canBurn(player)); } if (EntityTools.isBender(player, BendingElement.EARTH) && ((event.getCause() == DamageCause.SUFFOCATION) && TempBlock.isTempBlock(player.getEyeLocation().getBlock()))) { event.setDamage(0); event.setCancelled(true); } if (bender != null) { Map<Object, BendingAbility> instances = AbilityManager.getManager().getInstances(AvatarShield.NAME); if (instances.containsKey(player)) { AvatarShield ab = (AvatarShield) instances.get(player); if (ab.hit()) { event.setCancelled(true); } } } } }
@EventHandler(priority = EventPriority.NORMAL) public void onEntityDamage(EntityDamageEvent event) { if (event.isCancelled()) return; Entity ent = event.getEntity(); boolean tamedWolf = ent instanceof Wolf ? ((Wolf) ent).isTamed() : false; ClaimedResidence area = Residence.getResidenceManager().getByLoc(ent.getLocation()); /* Living Entities */ if (event instanceof EntityDamageByEntityEvent) { EntityDamageByEntityEvent attackevent = (EntityDamageByEntityEvent) event; Entity damager = attackevent.getDamager(); ClaimedResidence srcarea = null; if (damager != null) srcarea = Residence.getResidenceManager().getByLoc(damager.getLocation()); boolean srcpvp = true; if (srcarea != null) srcpvp = srcarea.getPermissions().has("pvp", true); ent = attackevent.getEntity(); if ((ent instanceof Player || tamedWolf) && (damager instanceof Player || (damager instanceof Arrow && (((Arrow) damager).getShooter() instanceof Player)))) { Player attacker = null; if (damager instanceof Player) attacker = (Player) damager; else if (damager instanceof Arrow) attacker = (Player) ((Arrow) damager).getShooter(); if (!srcpvp) { attacker.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NoPVPZone")); event.setCancelled(true); return; } /* Check for Player vs Player */ if (area == null) { /* World PvP */ if (!Residence.getWorldFlags().getPerms(damager.getWorld().getName()).has("pvp", true)) { attacker.sendMessage( ChatColor.RED + Residence.getLanguage().getPhrase("WorldPVPDisabled")); event.setCancelled(true); } } else { /* Normal PvP */ if (!area.getPermissions().has("pvp", true)) { attacker.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NoPVPZone")); event.setCancelled(true); } } return; } else if ((ent instanceof Player || tamedWolf) && (damager instanceof Creeper)) { if (area == null) { if (!Residence.getWorldFlags() .getPerms(damager.getWorld().getName()) .has("creeper", true)) { event.setCancelled(true); } } else { if (!area.getPermissions().has("creeper", true)) { event.setCancelled(true); } } } } if (area == null) { if (!Residence.getWorldFlags().getPerms(ent.getWorld().getName()).has("damage", true) && (ent instanceof Player || tamedWolf)) { event.setCancelled(true); } } else { if (!area.getPermissions().has("damage", true) && (ent instanceof Player || tamedWolf)) { event.setCancelled(true); } } if (event.isCancelled()) { /* Put out a fire on a player */ if ((ent instanceof Player || tamedWolf) && (event.getCause() == EntityDamageEvent.DamageCause.FIRE || event.getCause() == EntityDamageEvent.DamageCause.FIRE_TICK)) { ent.setFireTicks(0); } } }
@EventHandler(priority = EventPriority.MONITOR) public void onEntityDamage(EntityDamageEvent event) { if (event.isCancelled() == false && !worlds.contains(event.getEntity().getWorld().getName())) { Entity attacker = null; Projectile projectile = null; if (event instanceof EntityDamageByEntityEvent) { EntityDamageByEntityEvent ed = (EntityDamageByEntityEvent) event; attacker = ed.getDamager(); // handle arrow attacks if (ed.getDamager() instanceof Projectile) { projectile = ((Projectile) attacker); attacker = projectile.getShooter(); } } Entity entity = event.getEntity(); if (entity instanceof ComplexEntityPart) { entity = ((ComplexEntityPart) entity).getParent(); } int damage = event.getDamage(); DamageCause cause = event.getCause(); // if the player gets attacked if (entity instanceof Player) { // global damage count playerStatManager .getPlayerBlob(((Player) entity).getName()) .getStat("damagetaken", "total") .incrementStat(damage); // handle projectiles if (projectile != null) { playerStatManager .getPlayerBlob(((Player) entity).getName()) .getStat( "damagetaken", projectile.getType().toString().toLowerCase().replace("_", "")) .incrementStat(damage); } playerStatManager .getPlayerBlob(((Player) entity).getName()) .getStat("damagetaken", cause.toString().toLowerCase().replace("_", "")) .incrementStat(damage); // pvp damage if (attacker instanceof Player) { playerStatManager .getPlayerBlob(((Player) entity).getName()) .getStat("damagetaken", "player") .incrementStat(damage); playerStatManager .getPlayerBlob(((Player) attacker).getName()) .getStat("damagedealt", "player") .incrementStat(damage); // mob damage } else if (attacker != null) { playerStatManager .getPlayerBlob(((Player) entity).getName()) .getStat("damagetaken", attacker.getType().toString().toLowerCase().replace("_", "")) .incrementStat(damage); } } else { if (attacker instanceof Player) { // global damage dealt playerStatManager .getPlayerBlob(((Player) attacker).getName()) .getStat("damagedealt", "total") .incrementStat(damage); playerStatManager .getPlayerBlob(((Player) attacker).getName()) .getStat("damagedealt", cause.toString().toLowerCase().replace("_", "")) .incrementStat(damage); playerStatManager .getPlayerBlob(((Player) attacker).getName()) .getStat("damagedealt", entity.getType().toString().toLowerCase().replace("_", "")) .incrementStat(damage); } } } }
public boolean damageEntity(DamageSource damagesource, float f) { if (this.isInvulnerable()) { return false; } else if (this.world.isStatic) { return false; } else { this.aV = 0; if (this.getHealth() <= 0.0F) { return false; } else if (damagesource.m() && this.hasEffect(MobEffectList.FIRE_RESISTANCE)) { return false; } else { if ((damagesource == DamageSource.ANVIL || damagesource == DamageSource.FALLING_BLOCK) && this.getEquipment(4) != null) { this.getEquipment(4).damage((int) (f * 4.0F + this.random.nextFloat() * f * 2.0F), this); f *= 0.75F; } this.aG = 1.5F; boolean flag = true; // CraftBukkit start EntityDamageEvent event = CraftEventFactory.handleEntityDamageEvent(this, damagesource, f); if (event != null) { if (event.isCancelled()) { return false; } f = (float) event.getDamage(); } // CraftBukkit end if ((float) this.noDamageTicks > (float) this.maxNoDamageTicks / 2.0F) { if (f <= this.lastDamage) { return false; } this.d(damagesource, f - this.lastDamage); this.lastDamage = f; flag = false; } else { this.lastDamage = f; this.ax = this.getHealth(); this.noDamageTicks = this.maxNoDamageTicks; this.d(damagesource, f); this.hurtTicks = this.az = 10; } this.aA = 0.0F; Entity entity = damagesource.getEntity(); if (entity != null) { if (entity instanceof EntityLiving) { this.b((EntityLiving) entity); } if (entity instanceof EntityHuman) { this.lastDamageByPlayerTime = 100; this.killer = (EntityHuman) entity; } else if (entity instanceof EntityWolf) { EntityWolf entitywolf = (EntityWolf) entity; if (entitywolf.isTamed()) { this.lastDamageByPlayerTime = 100; this.killer = null; } } } if (flag) { this.world.broadcastEntityEffect(this, (byte) 2); if (damagesource != DamageSource.DROWN) { this.K(); } if (entity != null) { double d0 = entity.locX - this.locX; double d1; for (d1 = entity.locZ - this.locZ; d0 * d0 + d1 * d1 < 1.0E-4D; d1 = (Math.random() - Math.random()) * 0.01D) { d0 = (Math.random() - Math.random()) * 0.01D; } this.aA = (float) (Math.atan2(d1, d0) * 180.0D / 3.1415927410125732D) - this.yaw; this.a(entity, f, d0, d1); } else { this.aA = (float) ((int) (Math.random() * 2.0D) * 180); } } if (this.getHealth() <= 0.0F) { if (flag) { this.makeSound(this.aP(), this.ba(), this.bb()); } this.die(damagesource); } else if (flag) { this.makeSound(this.aO(), this.ba(), this.bb()); } return true; } } }
/** * In this entity-damage-listener we will obtain blood, risk infections and break truce. Those * things does never cancel or alter an event so they belong at monitor level. */ @EventHandler(priority = EventPriority.MONITOR) public void onEntityDamageMonitor(EntityDamageEvent event) { if (event.isCancelled()) return; // For further interest this must be a close combat attack by another entity if (event.getCause() != DamageCause.ENTITY_ATTACK && event.getCause() != DamageCause.PROJECTILE) return; if (!(event instanceof EntityDamageByEntityEvent)) return; // Define local fields Entity damagee = event.getEntity(); Creature cDamagee; Player pDamagee; VPlayer vpDamagee; EntityDamageByEntityEvent edbeEvent = (EntityDamageByEntityEvent) event; Entity damager = edbeEvent.getDamager(); Player pDamager; VPlayer vpDamager; // Consider the damager to be the shooter if this is a projectile if (damager instanceof Projectile) { damager = ((Projectile) damager).getShooter(); } // For further interest that attacker must be a player. if (!(damager instanceof Player)) return; pDamager = (Player) damager; vpDamager = VPlayers.i.get(pDamager); if (vpDamager.isVampire()) { if (damagee instanceof Player) { // A True Blood vampire attacked a normal player. There is risk for infection. pDamagee = (Player) damagee; vpDamagee = VPlayers.i.get(pDamagee); vpDamagee.infectionContractRisk(vpDamager); // There will also be blood! if (pDamagee.getHealth() > 0) { int damage = event.getDamage(); if (pDamagee.getHealth() < damage) { damage = pDamagee.getHealth(); } vpDamager.foodAdd(damage * Conf.foodPerDamageFromPlayer); vpDamager.healthAdd(damage * Conf.healthPerDamageFromPlayer); } } else if (damagee instanceof Creature) { // A vampire attacked a creature cDamagee = (Creature) damagee; CreatureType creatureType = EntityUtil.creatureTypeFromEntity(damagee); // Obtain blood? if (Conf.foodPerDamageFromCreature.containsKey(creatureType) && cDamagee.getHealth() > 0) { int damage = event.getDamage(); if (cDamagee.getHealth() < damage) { damage = cDamagee.getHealth(); } vpDamager.foodAdd(damage * Conf.foodPerDamageFromCreature.get(creatureType)); vpDamager.healthAdd(damage * Conf.healthPerDamageFromCreature.get(creatureType)); } // Break truce if (Conf.creatureTypeTruceMonsters.contains(creatureType)) { vpDamager.truceBreak(); } } } else if (damagee instanceof Player) { pDamagee = (Player) damagee; vpDamagee = VPlayers.i.get(pDamagee); if (vpDamagee.isVampire()) { vpDamager.infectionContractRisk(vpDamager); } } }