コード例 #1
0
ファイル: PlayerData.java プロジェクト: sumdream/SkillAPI
 /**
  * Checks whether or not the player can profess into the given class. This checks to make sure the
  * player is currently professed as the parent of the given class and is high enough of a level to
  * do so.
  *
  * @param rpgClass class to check
  * @return true if can profess, false otherwise
  */
 public boolean canProfess(RPGClass rpgClass) {
   if (rpgClass.isNeedsPermission()) {
     Player p = getPlayer();
     if (p == null
         || (!p.hasPermission(Permissions.CLASS)
             && !p.hasPermission(
                 Permissions.CLASS + "." + rpgClass.getName().toLowerCase().replace(" ", "-")))) {
       return false;
     }
   }
   if (classes.containsKey(rpgClass.getGroup())) {
     PlayerClass current = classes.get(rpgClass.getGroup());
     return rpgClass.getParent() == current.getData()
         && current.getData().getMaxLevel() <= current.getLevel();
   } else {
     return !rpgClass.hasParent();
   }
 }
コード例 #2
0
ファイル: PlayerData.java プロジェクト: sumdream/SkillAPI
  /**
   * Sets the professed class for the player for the corresponding group. This will not save any
   * skills, experience, or levels of the previous class if there was any. The new class will start
   * at level 1 with 0 experience.
   *
   * @param rpgClass class to assign to the player
   * @return the player-specific data for the new class
   */
  public PlayerClass setClass(RPGClass rpgClass) {
    PlayerClass c = classes.remove(rpgClass.getGroup());
    if (c != null) {
      for (Skill skill : c.getData().getSkills()) {
        skills.remove(skill.getName().toLowerCase());
        combos.removeSkill(skill);
      }
    }

    PlayerClass classData = new PlayerClass(this, rpgClass);
    classes.put(rpgClass.getGroup(), classData);

    // Add in missing skills
    for (Skill skill : rpgClass.getSkills()) {
      giveSkill(skill, classData);
    }

    updateHealthAndMana(getPlayer());
    updateScoreboard();
    return classes.get(rpgClass.getGroup());
  }
コード例 #3
0
ファイル: PlayerData.java プロジェクト: sumdream/SkillAPI
  /**
   * 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;
    }
  }
コード例 #4
0
ファイル: PlayerData.java プロジェクト: sumdream/SkillAPI
  /**
   * Checks whether or not the player is professed as the class or any of its children.
   *
   * @param rpgClass class to check
   * @return true if professed as the class or one of its children, false otherwise
   */
  public boolean isClass(RPGClass rpgClass) {
    if (rpgClass == null) {
      return false;
    }

    PlayerClass pc = classes.get(rpgClass.getGroup());
    if (pc == null) return false;

    RPGClass temp = pc.getData();
    while (temp != null) {
      if (temp == rpgClass) {
        return true;
      }
      temp = temp.getParent();
    }

    return false;
  }
コード例 #5
0
ファイル: PlayerData.java プロジェクト: sumdream/SkillAPI
 /**
  * Checks whether or not the player is professed as the class without checking child classes.
  *
  * @param rpgClass class to check
  * @return true if professed as the specific class, false otherwise
  */
 public boolean isExactClass(RPGClass rpgClass) {
   if (rpgClass == null) return false;
   PlayerClass c = classes.get(rpgClass.getGroup());
   return (c != null) && (c.getData() == rpgClass);
 }