コード例 #1
0
ファイル: PlayerData.java プロジェクト: sumdream/SkillAPI
  /**
   * Resets the class data for the owner under the given group. This will remove the profession
   * entirely, leaving no remaining data until the player professes again to a starting class.
   *
   * @param group group to reset
   */
  public void reset(String group) {
    stopPassives(getPlayer());
    clearBonuses();
    PlayerClass playerClass = classes.remove(group);
    if (playerClass != null) {
      // Remove skills
      RPGClass data = playerClass.getData();
      for (Skill skill : data.getSkills()) {
        skills.remove(skill.getName());
        combos.removeSkill(skill);
      }

      // Update GUI features
      if (getPlayer() != null) {
        ClassBoardManager.clear(new VersionPlayer(getPlayer()));
      }

      // Call the event
      Bukkit.getPluginManager().callEvent(new PlayerClassChangeEvent(playerClass, data, null));
    }

    // Restore default class if applicable
    GroupSettings settings = SkillAPI.getSettings().getGroupSettings(group);
    RPGClass rpgClass = settings.getDefault();
    if (rpgClass != null && settings.getPermission() == null) {
      setClass(rpgClass);
    }
    updateHealthAndMana(player.getPlayer());
  }
コード例 #2
0
ファイル: PlayerData.java プロジェクト: sumdream/SkillAPI
 /**
  * Gives levels to the player for all classes matching the experience source
  *
  * @param amount amount of levels to give
  * @param source source of the levels
  */
 public void giveLevels(int amount, ExpSource source) {
   for (PlayerClass playerClass : classes.values()) {
     RPGClass data = playerClass.getData();
     if (data.receivesExp(source)) {
       int exp = 0;
       int count = 0;
       int temp = amount;
       while (temp > 0) {
         temp--;
         exp += data.getRequiredExp(playerClass.getLevel() + count++);
       }
       playerClass.giveExp(exp, source);
     }
   }
   updateHealthAndMana(getPlayer());
 }
コード例 #3
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;
  }
コード例 #4
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());
  }
コード例 #5
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;
    }
  }
コード例 #6
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();
   }
 }
コード例 #7
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);
 }