Example #1
0
  /**
   * Updates the player's max health and mana using class data.
   *
   * @param player player to update the health and mana for
   */
  public void updateHealthAndMana(Player player) {
    if (player == null) {
      return;
    }

    // Update maxes
    double health = bonusHealth;
    maxMana = bonusMana;
    for (PlayerClass c : classes.values()) {
      health += c.getHealth();
      maxMana += c.getMana();
    }
    if (health == bonusHealth) {
      health += SkillAPI.getSettings().getDefaultHealth();
    }
    if (health == 0) {
      health = 20;
    }
    if (SkillAPI.getSettings().isModifyHealth()) VersionManager.setMaxHealth(player, health);
    mana = Math.min(mana, maxMana);

    // Health scaling is available starting with 1.6.2
    if (SkillAPI.getSettings().isModifyHealth()
        && VersionManager.isVersionAtLeast(VersionManager.V1_6_2)) {
      if (SkillAPI.getSettings().isOldHealth()) {
        player.setHealthScaled(true);
        player.setHealthScale(20);
      } else {
        player.setHealthScaled(false);
      }
    }
  }
Example #2
0
 /**
  * Gives the player attribute points without costing attribute points.
  *
  * @param key attribute to give points for
  * @param amount amount to give
  */
 public void giveAttribute(String key, int amount) {
   key = key.toLowerCase();
   int current = getAttribute(key);
   int max = SkillAPI.getAttributeManager().getAttribute(key).getMax();
   amount = Math.min(amount, max - current);
   if (amount > 0) {
     attributes.put(key, current + amount);
   }
 }