コード例 #1
0
ファイル: PlayerData.java プロジェクト: sumdream/SkillAPI
  /**
   * Binds a skill to a material for the player. The bind will not work if the skill was already
   * bound to the material.
   *
   * @param mat material to bind the skill to
   * @param skill skill to bind to the material
   * @return true if was able to bind the skill, false otherwise
   */
  public boolean bind(Material mat, PlayerSkill skill) {
    // Special cases
    if (mat == null || (skill != null && skill.getPlayerData() != this)) {
      return false;
    }

    PlayerSkill bound = getBoundSkill(mat);
    if (bound != skill) {
      // Apply the binding
      if (skill == null) {
        binds.remove(mat);
      } else {
        binds.put(mat, skill);
      }

      // Update the old skill's bind
      if (bound != null) {
        bound.setBind(null);
      }

      // Update the new skill's bind
      if (skill != null) {
        skill.setBind(mat);
      }

      return true;
    }

    // The skill was already bound
    else {
      return false;
    }
  }