Пример #1
0
  /**
   * Professes the player into the class if they are able to. This will reset the class data if the
   * group options are set to reset upon profession. Otherwise, all skills, experience, and levels
   * of the current class under the group will be retained and carried over into the new profession.
   *
   * @param rpgClass class to profess into
   * @return true if successfully professed, false otherwise
   */
  public boolean profess(RPGClass rpgClass) {
    if (rpgClass != null && canProfess(rpgClass)) {
      // Reset data if applicable
      if (SkillAPI.getSettings().getGroupSettings(rpgClass.getGroup()).isProfessReset()) {
        reset(rpgClass.getGroup());
      }

      // Inherit previous class data if any
      PlayerClass current = classes.get(rpgClass.getGroup());
      RPGClass previous;
      if (current == null) {
        previous = null;
        current = new PlayerClass(this, rpgClass);
        classes.put(rpgClass.getGroup(), current);
      } else {
        previous = current.getData();
        current.setClassData(rpgClass);
      }

      // Add skills
      for (Skill skill : rpgClass.getSkills()) {
        if (!skills.containsKey(skill.getKey())) {
          skills.put(skill.getKey(), new PlayerSkill(this, skill, current));
          combos.addSkill(skill);
        }
      }

      Bukkit.getPluginManager()
          .callEvent(new PlayerClassChangeEvent(current, previous, current.getData()));
      updateHealthAndMana(getPlayer());
      updateScoreboard();
      return true;
    } else {
      return false;
    }
  }