/** * Updates the player's max health and mana using class data. * * @param player player to update the health and mana for */ public void updateHealthAndMana(Player player) { if (player == null) { return; } // Update maxes double health = bonusHealth; maxMana = bonusMana; for (PlayerClass c : classes.values()) { health += c.getHealth(); maxMana += c.getMana(); } if (health == bonusHealth) { health += SkillAPI.getSettings().getDefaultHealth(); } if (health == 0) { health = 20; } if (SkillAPI.getSettings().isModifyHealth()) VersionManager.setMaxHealth(player, health); mana = Math.min(mana, maxMana); // Health scaling is available starting with 1.6.2 if (SkillAPI.getSettings().isModifyHealth() && VersionManager.isVersionAtLeast(VersionManager.V1_6_2)) { if (SkillAPI.getSettings().isOldHealth()) { player.setHealthScaled(true); player.setHealthScale(20); } else { player.setHealthScaled(false); } } }
/** * Gives the player attribute points without costing attribute points. * * @param key attribute to give points for * @param amount amount to give */ public void giveAttribute(String key, int amount) { key = key.toLowerCase(); int current = getAttribute(key); int max = SkillAPI.getAttributeManager().getAttribute(key).getMax(); amount = Math.min(amount, max - current); if (amount > 0) { attributes.put(key, current + amount); } }
/** * Casts a skill for the player. In order to cast the skill, the player must be online, have the * skill unlocked, have enough mana, have the skill off cooldown, and have a proper target if * applicable. * * @param skill skill to cast * @return true if successfully cast the skill, false otherwise */ public boolean cast(PlayerSkill skill) { // Invalid skill if (skill == null) { throw new IllegalArgumentException("Skill cannot be null"); } SkillStatus status = skill.getStatus(); int level = skill.getLevel(); double cost = skill.getData().getManaCost(level); // Not unlocked if (level <= 0) { return false; } // On Cooldown if (status == SkillStatus.ON_COOLDOWN) { SkillAPI.getLanguage() .sendMessage( ErrorNodes.COOLDOWN, getPlayer(), FilterType.COLOR, RPGFilter.COOLDOWN.setReplacement(skill.getCooldown() + ""), RPGFilter.SKILL.setReplacement(skill.getData().getName())); } // Not enough mana else if (status == SkillStatus.MISSING_MANA) { SkillAPI.getLanguage() .sendMessage( ErrorNodes.MANA, getPlayer(), FilterType.COLOR, RPGFilter.SKILL.setReplacement(skill.getData().getName()), RPGFilter.MANA.setReplacement(getMana() + ""), RPGFilter.COST.setReplacement((int) Math.ceil(cost) + ""), RPGFilter.MISSING.setReplacement((int) Math.ceil(cost - getMana()) + "")); } // Skill Shots else if (skill.getData() instanceof SkillShot) { Player p = getPlayer(); PlayerCastSkillEvent event = new PlayerCastSkillEvent(this, skill, p); Bukkit.getPluginManager().callEvent(event); // Make sure it isn't cancelled if (!event.isCancelled()) { try { if (((SkillShot) skill.getData()).cast(p, level)) { skill.startCooldown(); if (SkillAPI.getSettings().isShowSkillMessages()) { skill.getData().sendMessage(p, SkillAPI.getSettings().getMessageRadius()); } if (SkillAPI.getSettings().isManaEnabled()) { useMana(cost, ManaCost.SKILL_CAST); } return true; } } catch (Exception ex) { Bukkit.getLogger() .severe( "Failed to cast skill - " + skill.getData().getName() + ": Internal skill error"); ex.printStackTrace(); } } } // Target Skills else if (skill.getData() instanceof TargetSkill) { Player p = getPlayer(); LivingEntity target = TargetHelper.getLivingTarget(p, skill.getData().getRange(level)); // Must have a target if (target == null) { return false; } PlayerCastSkillEvent event = new PlayerCastSkillEvent(this, skill, p); Bukkit.getPluginManager().callEvent(event); // Make sure it isn't cancelled if (!event.isCancelled()) { try { if (((TargetSkill) skill.getData()) .cast(p, target, level, !SkillAPI.getSettings().canAttack(p, target))) { skill.startCooldown(); if (SkillAPI.getSettings().isShowSkillMessages()) { skill.getData().sendMessage(p, SkillAPI.getSettings().getMessageRadius()); } if (SkillAPI.getSettings().isManaEnabled()) { useMana(cost, ManaCost.SKILL_CAST); } return true; } } catch (Exception ex) { Bukkit.getLogger() .severe( "Failed to cast skill - " + skill.getData().getName() + ": Internal skill error"); ex.printStackTrace(); } } } return false; }