コード例 #1
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);
      }
    }
  }
コード例 #2
0
ファイル: PlayerData.java プロジェクト: sumdream/SkillAPI
 /**
  * Scales a dynamic skill's value using global modifiers
  *
  * @param component component holding the value
  * @param key key of the value
  * @param value unmodified value
  * @param self whether or not the player is the target
  * @return the modified value
  */
 public double scaleDynamic(EffectComponent component, String key, double value, boolean self) {
   AttributeManager manager = SkillAPI.getAttributeManager();
   if (manager == null) return value;
   for (String attr : manager.getKeys()) {
     int amount = getAttribute(attr);
     if (amount > 0) {
       value = manager.getAttribute(attr).modify(component, key, self, value, amount);
     }
   }
   return value;
 }
コード例 #3
0
ファイル: PlayerData.java プロジェクト: sumdream/SkillAPI
 /**
  * Scales a stat value using the player's attributes
  *
  * @param stat stat key
  * @param value base value
  * @return modified value
  */
 public double scaleStat(String stat, double value) {
   AttributeManager manager = SkillAPI.getAttributeManager();
   if (manager == null) return value;
   for (String key : manager.getKeys()) {
     int amount = getAttribute(key);
     if (amount > 0) {
       value = manager.getAttribute(key).modifyStat(stat, value, amount);
     }
   }
   return value;
 }
コード例 #4
0
ファイル: PlayerData.java プロジェクト: sumdream/SkillAPI
 /** 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);
   }
 }