/**
   * 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);
      }
    }
  }
 /** Updates the cooldowns on skill bars each second */
 @Override
 public void run() {
   for (Player player : Bukkit.getServer().getOnlinePlayers()) {
     PlayerData data = SkillAPI.getPlayerData(player);
     if (data.hasClass()) {
       data.getSkillBar().updateCooldowns();
     }
   }
 }
  /**
   * Updates the stats of a player based on their current attributes
   *
   * @param data player to update
   */
  public static void updatePlayer(PlayerData data) {
    Player player = data.getPlayer();
    if (player != null) {
      double change = updateStat(data, AttributeManager.HEALTH, player.getMaxHealth());
      data.addMaxHealth(change);

      change = updateStat(data, AttributeManager.MANA, data.getMaxMana());
      data.addMaxMana(change);
    }
  }
 private static double updateStat(PlayerData data, String key, double value) {
   Player player = data.getPlayer();
   if (player != null) {
     String mapKey = player.getName() + ":" + key;
     double current = bonuses.containsKey(mapKey) ? bonuses.remove(mapKey) : 0;
     double updated = data.scaleStat(key, value - current) - value + current;
     bonuses.put(mapKey, updated);
     return updated - current;
   }
   return 0;
 }
  /**
   * Apply skill damage/defense attribute buffs
   *
   * @param event event details
   */
  @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
  public void onSkillDamage(SkillDamageEvent event) {
    // Skill Damage
    if (event.getDamager() instanceof Player) {
      Player player = (Player) event.getDamager();
      PlayerData data = SkillAPI.getPlayerData(player);

      double newAmount = data.scaleStat(AttributeManager.PHYSICAL_DAMAGE, event.getDamage());
      event.setDamage(newAmount);
    }

    // Skill Defense
    if (event.getTarget() instanceof Player) {
      Player player = (Player) event.getTarget();
      PlayerData data = SkillAPI.getPlayerData(player);

      double newAmount = data.scaleStat(AttributeManager.PHYSICAL_DEFENSE, event.getDamage());
      event.setDamage(newAmount);
    }
  }
Exemple #6
0
 /** Checks all players for mana regeneration each interval */
 public void run() {
   for (Player player : plugin.getServer().getOnlinePlayers()) {
     PlayerData data = SkillAPI.getPlayerData(player);
     data.regenMana();
   }
 }