/** * 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(); } } }
/** * 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); } }
/** * Cancels firing a bow with a disabled weapon * * @param event event details */ @EventHandler public void onShoot(EntityShootBowEvent event) { if (event.getEntity() instanceof Player) { if (InventoryTask.cannotUse( SkillAPI.getPlayerData((Player) event.getEntity()), event.getBow())) { SkillAPI.getLanguage() .sendMessage(ErrorNodes.CANNOT_USE, event.getEntity(), FilterType.COLOR); event.setCancelled(true); } } }
/** * Cancels left clicks on disabled items * * @param event event details */ @EventHandler(priority = EventPriority.LOWEST) public void onAttack(EntityDamageByEntityEvent event) { if (event.getDamager() instanceof Player) { Player player = (Player) event.getDamager(); if (InventoryTask.cannotUse(SkillAPI.getPlayerData(player), player.getItemInHand())) { SkillAPI.getLanguage().sendMessage(ErrorNodes.CANNOT_USE, player, FilterType.COLOR); event.setCancelled(true); } } if (event.getEntity() instanceof Player && VersionManager.isVersionAtLeast(VersionManager.V1_9_0)) { Player player = (Player) event.getEntity(); if (event.getDamage(EntityDamageEvent.DamageModifier.BLOCKING) < 0 && InventoryTask.cannotUse( SkillAPI.getPlayerData(player), player.getInventory().getItemInMainHand())) { SkillAPI.getLanguage() .sendMessage(ErrorNodes.CANNOT_USE, event.getEntity(), FilterType.COLOR); event.setDamage(EntityDamageEvent.DamageModifier.BLOCKING, 0); } } }
/** * Gives players bonus stats on respawn * * @param event event details */ @EventHandler(priority = EventPriority.HIGH) public void onRespawn(PlayerRespawnEvent event) { updatePlayer(SkillAPI.getPlayerData(event.getPlayer())); }
/** Checks all players for mana regeneration each interval */ public void run() { for (Player player : plugin.getServer().getOnlinePlayers()) { PlayerData data = SkillAPI.getPlayerData(player); data.regenMana(); } }