/** * Heals an entity by a specific amount. * * @param target the entity to heal * @param amount the amount of health to regain * @param reason the reason supplied to the {@link EntityRegainHealthEvent} */ public static void heal(LivingEntity target, double amount, EntityRegainHealthEvent.RegainReason reason) { if (target.isDead()) { return; // too late! } final double maxHealth = target.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); final double currentHealth = target.getHealth(); if (currentHealth >= maxHealth) { return; } EntityRegainHealthEvent event = new EntityRegainHealthEvent(target, amount, reason); EventFactory.getInstance().callEvent(event); if (!event.isCancelled()) { target.setHealth(Math.min(maxHealth, currentHealth + event.getAmount())); } }
public AwardCombatXpTask(McMMOPlayer mcMMOPlayer, PrimarySkillType primarySkillType, double baseXp, LivingEntity target, XPGainReason xpGainReason) { this.mcMMOPlayer = mcMMOPlayer; this.primarySkillType = primarySkillType; this.baseXp = baseXp; this.target = target; this.xpGainReason = xpGainReason; baseHealth = target.getHealth(); }
/** * Get the current health of this MABoss * @return the current health of the boss */ public double getHealth() { return entity.getHealth(); }
@Override public double getHealth() { return le.getHealth(); }
@Override public double getBalance(Mage mage, CasterProperties caster) { double balance = 0; LivingEntity living = mage.getLivingEntity(); if (living != null) { balance = living.getHealth(); } return balance; }
@Override public boolean has(Mage mage, CasterProperties caster, double amount) { LivingEntity living = mage.getLivingEntity(); return living != null && living.getHealth() >= amount; }
@Override public void run() { double health = target.getHealth(); double damage = baseHealth - health; // May avoid negative xp, we don't know what other plugins do with the entity health if (damage <= 0) { return; } // Don't reward the player for overkills if (health < 0) { damage += health; } mcMMOPlayer.beginXpGain(primarySkillType, (int) (damage * baseXp), xpGainReason, XPGainSource.SELF); } }
/** * Get the health for an entity (LivingEntity). * * @param entity * @return * @throws RuntimeException, * in case of an IncompatibleClassChangeError without success on * recovery attempts. */ public static double getHealth(final LivingEntity entity) { try{ return entity.getHealth(); } catch(IncompatibleClassChangeError e) { return getDoubleOrInt(entity, "getHealth", e); } }
@Override public boolean give(Mage mage, CasterProperties caster, double amount) { LivingEntity living = mage.getLivingEntity(); if (living != null) { double maxHealth = CompatibilityUtils.getMaxHealth(living); if (living.getHealth() >= maxHealth) { return false; } living.setHealth(Math.min(maxHealth, living.getHealth() + amount)); return true; } return false; } }
@Override public void deduct(Mage mage, CasterProperties caster, double amount) { LivingEntity living = mage.getLivingEntity(); if (living != null) { living.setHealth(Math.max(0, living.getHealth() - amount)); } }
public static void dealNoInvulnerabilityTickDamage(LivingEntity target, double damage, Entity attacker) { if (target.isDead()) { return; } double incDmg = callFakeDamageEvent(attacker, target, DamageCause.CUSTOM, damage); double newHealth = Math.max(0, target.getHealth() - incDmg); target.setHealth(newHealth); }
@SuppressWarnings("unchecked") public static void addDamageToEntity(LivingEntity damager, LivingEntity victim, double damage) { Map<UUID, Double> damageMap; if (victim.hasMetadata("DamageCount")) { for (MetadataValue value : victim.getMetadata("DamageCount")) { if (value.getOwningPlugin().getName().equals("MyPet")) { damageMap = (Map<UUID, Double>) value.value(); if (damageMap.containsKey(damager)) { double oldDamage = damageMap.get(damager); damageMap.put(damager.getUniqueId(), victim.getHealth() < damage ? victim.getHealth() + oldDamage : damage + oldDamage); } else { damageMap.put(damager.getUniqueId(), victim.getHealth() < damage ? victim.getHealth() : damage); } break; } } } else { damageMap = new WeakHashMap<>(); damageMap.put(damager.getUniqueId(), victim.getHealth() < damage ? victim.getHealth() : damage); victim.setMetadata("DamageCount", new FixedMetadataValue(MyPetApi.getPlugin(), damageMap)); } }
@Override public void kill() { le.setLastDamageCause(new EntityDamageEvent(le, EntityDamageEvent.DamageCause.CUSTOM, le.getHealth())); le.setHealth(0D); }
private void applyHealing(final LivingEntity livingEntity) { if (livingEntity.getHealth() < livingEntity.getMaxHealth()) { livingEntity.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, this.potDuration, this.power)); AirAbility.breakBreathbendingHold(livingEntity); this.healing = true; this.healingSelf = false; } }
@Override public SpellResult perform(CastContext context) { Entity target = context.getTargetEntity(); if (target == null || !(target instanceof LivingEntity)) { return SpellResult.NO_TARGET; } if (health <= 0) { return SpellResult.FAIL; } LivingEntity li = (LivingEntity)target; if (li.getHealth() > health) { li.setHealth(health); } CompatibilityUtils.setMaxHealth(li, health); if (li instanceof Player && healthScale > 0) { Player player = (Player)li; player.setHealthScale(healthScale); } return SpellResult.CAST; }
/** * Handle the Beast Lore ability. * * @param target The entity to examine */ public void beastLore(LivingEntity target) { Player player = getPlayer(); Tameable beast = (Tameable) target; String message = LocaleLoader.getString("Combat.BeastLore") + " "; if (beast.isTamed() && beast.getOwner() != null) { message = message.concat(LocaleLoader.getString("Combat.BeastLoreOwner", beast.getOwner().getName()) + " "); } message = message.concat(LocaleLoader.getString("Combat.BeastLoreHealth", target.getHealth(), target.getMaxHealth())); player.sendMessage(message); }
private void giveHP(final LivingEntity livingEntity) { if (!livingEntity.isDead() && livingEntity.getHealth() < livingEntity.getMaxHealth()) { this.applyHealing(livingEntity); } else { this.healing = false; } for (final PotionEffect effect : livingEntity.getActivePotionEffects()) { if (ElementalAbility.isNegativeEffect(effect.getType())) { livingEntity.removePotionEffect(effect.getType()); } } }
@EventHandler(priority=EventPriority.MONITOR) public void onKill(SkillDamageEvent event) { if (event.isCancelled()) { return; } if (!(event.getDamager() instanceof Player)) { return; } Player player = (Player) event.getDamager(); if (event.getTarget().getHealth() > event.getDamage()) { return; } MobKillNotifier.addKill(player, event.getTarget()); }
private static void processSwordCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event) { if (event.getCause() == DamageCause.THORNS) { return; } McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); SwordsManager swordsManager = mcMMOPlayer.getSwordsManager(); double initialDamage = event.getDamage(); Map<DamageModifier, Double> modifiers = getModifiers(event); if (swordsManager.canActivateAbility()) { mcMMOPlayer.checkAbilityActivation(PrimarySkillType.SWORDS); } if(target.getHealth() - event.getFinalDamage() >= 1) { if (swordsManager.canUseRupture()) { swordsManager.ruptureCheck(target); } } if (swordsManager.canUseSerratedStrike()) { swordsManager.serratedStrikes(target, initialDamage, modifiers); } startGainXp(mcMMOPlayer, target, PrimarySkillType.SWORDS); }
@Override public PowerResult<Double> hit(Player player, ItemStack stack, LivingEntity entity, double damage, EntityDamageByEntityEvent event) { if (damage < minDamage) return PowerResult.noop(); if (!checkCooldown(this, player, cooldown, true, true)) return PowerResult.cd(); if (!getItem().consumeDurability(stack, cost)) return PowerResult.cost(); if (entity.hasPotionEffect(PotionEffectType.DAMAGE_RESISTANCE)) { PotionEffect e = entity.getPotionEffect(PotionEffectType.DAMAGE_RESISTANCE); if (e.getAmplifier() >= 4) return PowerResult.noop(); } Context.instance().putExpiringSeconds(player.getUniqueId(), "realdamage.target", entity, 3); double health = entity.getHealth(); double newHealth = health - realDamage; newHealth = max(newHealth, 0.1);//Bug workaround newHealth = min(newHealth, entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); entity.setHealth(newHealth); return PowerResult.ok(damage); }