/** * 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())); } }
@Override public double getMaxHealth() { return getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); }
@Override public PowerResult<Void> fire(Player player, ItemStack stack, LivingEntity entity, Double damage) { if (random.nextInt(chance) == 0 && damage != null) { if (!getItem().consumeDurability(stack, cost)) return PowerResult.cost(); player.setHealth(Math.max(Math.min(player.getHealth() + damage * factor, player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()), 0.01)); return PowerResult.ok(); } return PowerResult.noop(); }
@Override public double getSpeedAttributeMultiplier(final Player player) { final AttributeInstance attrInst = player.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED); final double val = attrInst.getValue() / attrInst.getBaseValue(); final AttributeModifier mod = getModifier(attrInst, AttribUtil.ID_SPRINT_BOOST); return mod == null ? val : (val / getMultiplier(mod)); }
@Override public PowerResult<Double> hit(Player player, ItemStack stack, LivingEntity entity, double damage, EntityDamageByEntityEvent event) { if (!player.isSprinting()) return PowerResult.noop(); double originDamage = damage; damage = damage * (1 + percentage / 100.0); damage = damage + damage * (player.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).getValue() / 0.13 - 1) * (speedPercentage / 100.0); damage = Math.max(Math.min(damage, cap), originDamage); event.setDamage(damage); if (damage > originDamage) { player.playSound(player.getLocation(), Sound.BLOCK_ANVIL_LAND, 0.1f, 0.1f); } return PowerResult.ok(damage); } }
@EventHandler (priority = EventPriority.HIGHEST) public static void onEntityDamage(EntityDamageEvent e){ Entity entity = e.getEntity(); if(!(entity instanceof LivingEntity)) return; LivingEntity le = (LivingEntity) entity; double armourDamageReduction = e.getDamage(EntityDamageEvent.DamageModifier.ARMOR); double armourPoints = le.getAttribute(Attribute.GENERIC_ARMOR).getValue(); double newReduction = armourPoints * 0.04 * - (e.getDamage() + e.getDamage(EntityDamageEvent.DamageModifier.BLOCKING)); //todo don't hardcode this value e.setDamage (EntityDamageEvent.DamageModifier.ARMOR, newReduction); INSTANCE.debug("Armour points: " + armourPoints + " Reduction: " + armourDamageReduction + " After: " + newReduction, le); }
@EventHandler(priority = EventPriority.HIGHEST) public void onRegen(EntityRegainHealthEvent e){ if(e.getEntityType() != EntityType.PLAYER || e.getRegainReason() != EntityRegainHealthEvent.RegainReason.SATIATED){ return; } final Player p = (Player) e.getEntity(); if(!isEnabled(p.getWorld())) return; e.setCancelled(true); long currentTime = System.currentTimeMillis() / 1000; long lastHealTime = getLastHealTime(p); if(currentTime - lastHealTime < module().getLong("frequency")) return; double maxHealth = p.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); if(p.getHealth() < maxHealth){ p.setHealth(MathHelper.clamp(p.getHealth() + module().getInt("amount"), 0.0, maxHealth)); healTimes.put(p.getUniqueId(), currentTime); disableSpartanRegenCheck(p); } final float previousExhaustion = p.getExhaustion(); final float exhaustionToApply = (float) module().getDouble("exhaustion"); Bukkit.getScheduler().runTaskLater(plugin, () -> { //This is because bukkit doesn't stop the exhaustion change when cancelling the event p.setExhaustion(previousExhaustion + exhaustionToApply); debug("Exhaustion before: " + previousExhaustion + " Now: " + p.getExhaustion() + " Saturation: " + p.getSaturation(), p); }, 1L); }
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> { double mh = scanned.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); double health = scanned.getHealth() / mh * scanned.getHealthScale(); float hunger = (scanned.getFoodLevel() / 20F) * 100;
double mh = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); player.setHealth(mh / 10.0d); if (inv) {
@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); }
public void revertToCheckpoint(MinigamePlayer player) { RevertCheckpointEvent event = new RevertCheckpointEvent(player); Bukkit.getServer().getPluginManager().callEvent(event); if(!event.isCancelled()){ player.teleport(player.getCheckpoint()); player.addRevert(); player.sendInfoMessage(MinigameUtils.getLang("player.checkpoint.revert")); // Reset the player's health and extinguish flames when they revert Player p = player.getPlayer(); if ((p != null) && (p.isOnline())) { p.setFireTicks(0); p.setHealth(p.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); p.setFoodLevel(20); p.setSaturation(20f); p.setRemainingAir(p.getMaximumAir()); } } }
double mh = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); player.setHealth(mh / 10.0d); if (inv) {
@Override public PowerResult<Void> tick(Player player, ItemStack stack) { if (!checkCooldownByString(this, player, "potiontick." + effect.getName(), interval, false, true)) return PowerResult.cd(); if (!getItem().consumeDurability(stack, cost)) return PowerResult.cost(); double health = player.getHealth(); boolean hasEffect = false; for (PotionEffect potionEffect : player.getActivePotionEffects()) { if (potionEffect.getType().equals(effect)) { hasEffect = true; if (clear) { player.removePotionEffect(effect); } else if (potionEffect.getDuration() <= 5 || potionEffect.getAmplifier() < amplifier) player.addPotionEffect(new PotionEffect(effect, duration, amplifier, true), true); break; } } if (!hasEffect && !clear) { player.addPotionEffect(new PotionEffect(effect, duration, amplifier, true), true); } if (effect.equals(PotionEffectType.HEALTH_BOOST) && health > 0) { health = min(health, player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); player.setHealth(health); } return PowerResult.ok(); }
tmhor.setAge(horse.getAge()); tmhor.setBaby(!horse.isAdult()); double mh = horse.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); tmhor.setHorseHealth(mh); tmhor.setHealth(horse.getHealth()); tmlla.setAge(llama.getAge()); tmlla.setBaby(!llama.isAdult()); double llmh = llama.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); tmlla.setHorseHealth(llmh); tmlla.setHealth(llama.getHealth());
tmhor.setDomesticity(h.getDomestication()); tmhor.setJumpStrength(h.getJumpStrength()); double mh = h.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); tmhor.setHorseHealth(mh); tmhor.setHealth(h.getHealth());
event.setCancelled(true); try { player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); } catch (LinkageError e) { player.setHealth(player.getMaxHealth());
tmlla.setAge(ll.getAge()); tmlla.setBaby(!ll.isAdult()); double mh = ll.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); tmlla.setHorseHealth(mh); tmlla.setHealth(ll.getHealth());