/** * 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())); } }
tmhor.setDomesticity(h.getDomestication()); tmhor.setJumpStrength(h.getJumpStrength()); double mh = h.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); tmhor.setHorseHealth(mh); tmhor.setHealth(h.getHealth()); tmhor.setSpeed(h.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).getBaseValue()); attribute.setBaseValue(tmhor.getHorseHealth()); equine.setHealth(tmhor.getHealth()); Inventory inv = equine.getInventory(); ee.setStyle(tmhor.getHorseStyle()); equine.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).setBaseValue(tmhor.getSpeed()); equine.setTamed(true); equine.setOwner(p);
@EventHandler(priority = EventPriority.HIGHEST) public void onPlayerQuit(PlayerQuitEvent e){ Player player = e.getPlayer(); AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED); double baseValue = attribute.getBaseValue(); if(baseValue != 4){ //If basevalue is not 1.9 default, set it back attribute.setBaseValue(4); player.saveData(); } }
@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 void setMaxHealth(double health) { getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(health); if (this.health > health) { this.health = health; } }
public static PVPMode getPVPMode(Player player){ Objects.requireNonNull(player, "player cannot be null!"); return player.getAttribute(Attribute.GENERIC_ATTACK_SPEED).getBaseValue() == 4 ? PVPMode.NEW_PVP : PVPMode.OLD_PVP; }
public void activateAttributes() { double healthScale = getDouble("health_scale"); if (healthScale > 0) { Player player = mage.getPlayer(); if (player != null) { player.setHealthScale(healthScale); } } Collection<EntityAttributeModifier> modifiers = getAttributeModifiers(); if (modifiers == null) return; LivingEntity entity = mage.getLivingEntity(); if (entity == null) return; for (EntityAttributeModifier modifier : modifiers) { AttributeInstance attribute = entity.getAttribute(modifier.attribute); // Only do this once, it's really here to clean up attributes that may have gotten stuck on server crash if (!checkedAttributes) { Collection<AttributeModifier> existingModifiers = attribute.getModifiers(); for (AttributeModifier existing : existingModifiers) { if (existing.getName().equalsIgnoreCase(modifier.modifier.getName())) { mage.getController().getLogger().warning("Removed duplicate attribute modifier " + modifier.modifier.getName() + ", was this leftover from a server crash?"); attribute.removeModifier(existing); break; } } } attribute.addModifier(modifier.modifier); } checkedAttributes = true; }
@Test public void getAttribute_HealthAttribute_IsMaximumHealth() { assertEquals(20.0, player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getDefaultValue(), 0); }
/** * The first modifier with the given id that can be found, or null if none * is found. * * @param attrInst * @param id * @return */ private AttributeModifier getModifier(final AttributeInstance attrInst, final UUID id) { for (final AttributeModifier mod : attrInst.getModifiers()) { if (id.equals(mod.getUniqueId())) { return mod; } } return null; }
tmhor.setAge(horse.getAge()); tmhor.setBaby(!horse.isAdult()); double mh = horse.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); tmhor.setHorseHealth(mh); tmhor.setHealth(horse.getHealth()); tmhor.setDomesticity(horse.getDomestication()); tmhor.setJumpStrength(horse.getJumpStrength()); tmhor.setSpeed(horse.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).getBaseValue()); tmlla.setAge(llama.getAge()); tmlla.setBaby(!llama.isAdult()); double llmh = llama.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); tmlla.setHorseHealth(llmh); tmlla.setHealth(llama.getHealth()); tmlla.setDomesticity(llama.getDomestication()); tmlla.setJumpStrength(llama.getJumpStrength()); tmlla.setSpeed(llama.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).getBaseValue()); attribute.setBaseValue(e.getHorseHealth()); equine.setHealth(e.getHealth()); String name = e.getName(); equine.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).setBaseValue(e.getSpeed()); equine.setRemoveWhenFarAway(false); }); attribute.setBaseValue(ll.getHorseHealth());
/** * Gives an increased max health reward to a player. * * @param player * @param amount * @return the reward text to display to the player */ @SuppressWarnings("deprecation") private String rewardMaxHealth(Player player, int amount) { if (serverVersion >= 9) { AttributeInstance playerAttribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH); playerAttribute.setBaseValue(playerAttribute.getBaseValue() + amount); } else { player.setMaxHealth(player.getMaxHealth() + amount); } return ChatColor.translateAlternateColorCodes('&', StringUtils.replaceOnce(langIncreaseMaxHealthRewardReceived, "AMOUNT", Integer.toString(amount))); }
public void applyAttributes(LivingEntity entity) { if (attributes != null) { for (Map.Entry<Attribute, Double> entry : attributes.entrySet()) { AttributeInstance attribute = entity.getAttribute(entry.getKey()); if (attribute != null) { attribute.setBaseValue(entry.getValue()); } } } }
oldFoodLevel = player.getFoodLevel(); if (is1_9) { oldMaxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue();
public void storePlayerData(){ ItemStack[] storedItems = player.getInventory().getContents(); ItemStack[] storedArmour = player.getInventory().getArmorContents(); int food = player.getFoodLevel(); double health = player.getHealth(); float saturation = player.getSaturation(); lastScoreboard = player.getScoreboard(); GameMode lastGM = player.getGameMode(); float exp = player.getExp(); if (exp < 0){ Minigames.log.warning("Player Experience was less that 0: " + player.getDisplayName()+ " " + player.getExp()); exp = 0; } int level = player.getLevel(); player.setSaturation(15); player.setFoodLevel(20); player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getDefaultValue()); player.getInventory().clear(); player.getInventory().setArmorContents(null); player.setLevel(0); player.setExp(0); oply = new OfflineMinigamePlayer(getPlayer().getUniqueId().toString(), storedItems, storedArmour, food, health, saturation, lastGM, exp, level, null); player.updateInventory(); }
tmlla.setAge(ll.getAge()); tmlla.setBaby(!ll.isAdult()); double mh = ll.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); tmlla.setHorseHealth(mh); tmlla.setHealth(ll.getHealth()); tmlla.setDomesticity(ll.getDomestication()); tmlla.setJumpStrength(ll.getJumpStrength()); tmlla.setSpeed(ll.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).getBaseValue()); attribute.setBaseValue(tmlla.getHorseHealth()); String name = tmlla.getName(); if (name != null && !name.isEmpty()) { player.updateInventory(); llama.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).setBaseValue(tmlla.getSpeed()); ent.remove(); break;
@Override public double getMaxHealth() { return getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); }
private void checkAttackSpeed(Player player){ World world = player.getWorld(); //If module is disabled, set attack speed to 1.9 default double attackSpeed = Config.moduleEnabled("disable-attack-cooldown", world) ? module().getDouble("generic-attack-speed") : 4; AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED); double baseValue = attribute.getBaseValue(); if(baseValue != attackSpeed){ attribute.setBaseValue(attackSpeed); player.saveData(); } }
player.setExp(data.getOldExp()); if (is1_9) { player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(data.getOldMaxHealth()); player.setHealth(data.getOldHealth() <= data.getOldMaxHealth() ? data.getOldHealth() : data.getOldMaxHealth()); } else {
@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(); }
double baseValue = attribute.getBaseValue(); String message = "&1[OCM] &aAttack cooldown "; attribute.setBaseValue(GAS); p.saveData(); Messenger.send(p, message);