/** * 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 max health to the player. This does not carry over to other accounts and will reset when * SkillAPI is disabled. This does however carry over through death and professions. This will * accept negative values. * * @param amount amount of bonus health to give */ public void addMaxHealth(double amount) { bonusHealth += amount; Player player = getPlayer(); if (player != null) { VersionManager.setMaxHealth(player, player.getMaxHealth() + amount); } }
/** * Sends a message using the provided filters to a list of players represented by their IDs * * @param key key for the language message * @param targetIds ids of the recipients of the message * @param filterType type of built-in filter to use * @param filters custom filters to use */ public void sendMessage( String key, Collection<UUID> targetIds, FilterType filterType, CustomFilter... filters) { List<String> lines = getMessage(key, true, filterType, filters); if (lines == null || !VersionManager.isUUID()) return; for (UUID id : targetIds) { Player target = Bukkit.getPlayer(id); if (target != null) { for (String line : lines) { target.sendMessage(line); } } } }
/** * Executes the command * * @param command owning command * @param plugin plugin reference * @param sender sender of the command * @param args arguments */ @Override public void execute( ConfigurableCommand command, Plugin plugin, CommandSender sender, String[] args) { // Needs two arguments if (args.length < 2) { command.displayHelp(sender); } // Switch accounts if valid number else { OfflinePlayer player = VersionManager.getOfflinePlayer(args[0], false); if (player == null) { command.sendMessage(sender, NOT_PLAYER, "&4That is not a valid player name"); return; } PlayerAccounts accounts = SkillAPI.getPlayerAccountData(player); try { int id = Integer.parseInt(args[1]); if (accounts.getAccountLimit() >= id && id > 0) { accounts.setAccount(id); command.sendMessage( sender, CHANGED, ChatColor.GOLD + "{player}'s" + ChatColor.DARK_GREEN + " active account has been changed", Filter.PLAYER.setReplacement(player.getName())); if (player.isOnline()) { command.sendMessage( (Player) player, TARGET, ChatColor.DARK_GREEN + "Your account has been forced to " + ChatColor.GOLD + "Account #{account}", RPGFilter.ACCOUNT.setReplacement(id + "")); } return; } } catch (Exception ex) { // Invalid ID } command.sendMessage(sender, NOT_ACCOUNT, ChatColor.RED + "That is not a valid account ID"); } }
/** * 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); } } }