Exemplo n.º 1
0
  /**
   * Shows the skill tree for the player. If the player has multiple trees, this will show the list
   * of skill trees they can view.
   *
   * @param player player to show the skill tree for
   * @return true if able to show the player, false otherwise
   */
  public boolean showSkills(Player player) {
    // Cannot show an invalid player, and cannot show no skills
    if (player == null || classes.size() == 0 || skills.size() == 0) {
      return false;
    }

    // Show skill tree of only class
    if (classes.size() == 1) {
      PlayerClass playerClass = classes.get(classes.keySet().toArray(new String[1])[0]);
      if (playerClass.getData().getSkills().size() == 0) {
        return false;
      }

      player.openInventory(
          ((InventoryTree) playerClass.getData().getSkillTree()).getInventory(this));
      return true;
    }

    // Show list of classes that have skill trees
    else {
      Inventory inv =
          InventoryManager.createInventory(
              TreeListener.CLASS_LIST_KEY, (classes.size() + 8) / 9, player.getName());
      for (PlayerClass c : classes.values()) {
        inv.addItem(c.getData().getIcon());
      }
      player.openInventory(inv);
      return true;
    }
  }
Exemplo n.º 2
0
  /**
   * Handles attribute menu interaction
   *
   * @param event event details
   */
  @EventHandler
  public void onClick(InventoryClickEvent event) {
    // Class selection
    if (InventoryManager.isMatching(event.getInventory(), MENU_KEY)) {
      // Do nothing when clicking outside the inventory
      if (event.getSlot() == -999) {
        return;
      }

      boolean top = event.getRawSlot() < event.getView().getTopInventory().getSize();
      AttributeManager manager = SkillAPI.getAttributeManager();

      // Interact with the skill tree when clicking in the top region
      if (top) {
        if (event.getSlot() < manager.getKeys().size() || event.getCursor() != null) {
          event.setCancelled(true);

          PlayerData data = SkillAPI.getPlayerData((Player) event.getWhoClicked());
          if (event.isRightClick() && SkillAPI.getSettings().isAttributesDowngrade()) {
            data.refundAttribute(manager.getKeys().toArray()[event.getSlot()].toString());
          } else if (event.isLeftClick()) {

            Object[] keys = manager.getKeys().toArray();
            data.upAttribute(keys[event.getSlot()].toString());
          }
          data.openAttributeMenu();
        }
      }

      // Do not allow shift clicking items into the inventory
      else if (event.isShiftClick()) {
        event.setCancelled(true);
      }
    }
  }
Exemplo n.º 3
0
 /** Opens the attribute menu */
 public void openAttributeMenu() {
   Player player = getPlayer();
   if (SkillAPI.getSettings().isAttributesEnabled() && player != null) {
     AttributeManager manager = SkillAPI.getAttributeManager();
     Inventory inv =
         InventoryManager.createInventory(
             AttributeListener.MENU_KEY,
             (manager.getKeys().size() + 8) / 9,
             "Attributes (" + attribPoints + " points)");
     int i = 0;
     for (String key : manager.getKeys()) {
       ItemStack icon = manager.getAttribute(key).getIcon().clone();
       ItemMeta meta = icon.getItemMeta();
       meta.setDisplayName(meta.getDisplayName().replace("{amount}", "" + getAttribute(key)));
       icon.setItemMeta(meta);
       inv.setItem(i++, icon);
     }
     player.openInventory(inv);
   }
 }