// Boosts the player's health based on the configuration file's info. @EventHandler(priority = EventPriority.NORMAL) public void logIn(PlayerLoginEvent e) { Player p = e.getPlayer(); try { p.setMaxHealth(mobfighter.getConfig().getDouble("HealthBoost." + p.getDisplayName())); } // If the player isn't in the config file. catch (Exception ex) { p.resetMaxHealth(); } }
/** * @param player * @param level */ private void setPlayerHitpoints(Player player, int level) { final float maxHealth = 60; final float defaultHealth = 20; float hitpointScale = ((maxHealth - defaultHealth) / maxHealth); int additionalHitpoints = (int) (hitpointScale * level); player.setMaxHealth(defaultHealth + additionalHitpoints); player.setHealth(defaultHealth + additionalHitpoints); }
// Handles multiple instances of player clicks. @SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.HIGH) public void playerClick(PlayerInteractEvent event) { final Player player = event.getPlayer(); if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) { // Creative mode switch if (player.getItemInHand().getType().equals(Material.BRICK)) { // Bypass switch and level loss. if (mobfighter.getConfig().getList("Creative Immunity").contains(player.getDisplayName())) return; if (player.getLevel() >= 60) { player.setItemInHand(new ItemStack(Material.AIR)); player.setLevel(player.getLevel() - 60); player.setGameMode(GameMode.CREATIVE); } else player.sendMessage(ChatColor.RED + "You need to be at least level 60 to get creative!"); } // Health Boost, Stat Boost, and Crafting if (player.getItemInHand().getType().equals(Material.RED_MUSHROOM) && player.getItemInHand().getItemMeta().hasDisplayName() && player .getItemInHand() .getItemMeta() .getDisplayName() .equalsIgnoreCase(ChatColor.DARK_RED + "Health Boost")) { int amount = player.getItemInHand().getAmount(); player.setItemInHand(new ItemStack(Material.AIR)); while (amount > 0) // Add health and refunds the money spent buying it if the player has used 5 // already. { if (player.getMaxHealth() >= 40) { player.setMaxHealth(40); player.sendMessage(ChatColor.RED + "Your health is already boosted to the max!"); VaultEco.getEconomy() .depositPlayer( player, Double.parseDouble(EliteShop.shop.getString("RED_MUSHROOM"))); player.sendMessage( ChatColor.GREEN + "Refunded: $" + EliteShop.shop.getString("RED_MUSHROOM")); } else player.setMaxHealth(player.getMaxHealth() + 4); amount--; } if (player.getMaxHealth() > 20) // Sets max health in config and then reloads to apply. { mobfighter .getConfig() .set("HealthBoost." + player.getDisplayName(), player.getMaxHealth()); mobfighter.saveConfig(); } } else if (player.getItemInHand().getType().equals(Material.STONE_BUTTON) && player.getItemInHand().getItemMeta().hasDisplayName() && player .getItemInHand() .getItemMeta() .getDisplayName() .equalsIgnoreCase(ChatColor.GREEN + "Stat Boost")) { player.setItemInHand(new ItemStack(Material.AIR)); player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 0)); player.addPotionEffect( new PotionEffect(PotionEffectType.INCREASE_DAMAGE, Integer.MAX_VALUE, 0)); player.addPotionEffect( new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, 0)); player.addPotionEffect(new PotionEffect(PotionEffectType.SATURATION, Integer.MAX_VALUE, 0)); player.sendMessage(ChatColor.GREEN + "Stat Boost Activated!"); } else if (player.getItemInHand().getType().equals(Material.WORKBENCH)) { if (mobfighter.getConfig().getList("Creative Immunity").contains(player.getDisplayName())) return; player.sendMessage(ChatColor.GRAY + "Type: /craft"); } // Get special items for end-game armor set. if (player.getItemInHand().getType().equals(Material.SPONGE)) { player.getInventory().clear(); ItemStack coal = new ItemStack(Material.COAL, 64); ItemMeta meta = coal.getItemMeta(); meta.setDisplayName(ChatColor.LIGHT_PURPLE + "Undead Heart"); coal.setItemMeta(meta); int i = 0; while (i < 36) { player.getInventory().addItem(coal); i++; } player.updateInventory(); } // Opens the main shop by right-clicking the shop paper. if (player.getItemInHand().getType().equals(Material.PAPER)) player.openInventory(MainShop.getShop()); } // End of Right-click if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) { if (player.getItemInHand().getType().equals(Material.SPONGE)) { player.getInventory().clear(); ItemStack emerald = new ItemStack(Material.EMERALD, 64); ItemMeta meta = emerald.getItemMeta(); meta.setDisplayName(ChatColor.DARK_GREEN + "Tainted Soul"); emerald.setItemMeta(meta); int n = 0; while (n < 36) { player.getInventory().addItem(emerald); n++; } player.updateInventory(); } } }
// リスポーン体力調整グローバル public static void global_respawnhealth( Player pl, final Plugin plugin, final PlayerRespawnEvent event) { pl.setMaxHealth(100D); }