From e5b0f06a8fb674702b26acb4104c78578da9d6ff Mon Sep 17 00:00:00 2001 From: ASangarin Date: Sun, 11 Oct 2020 17:00:40 +0200 Subject: [PATCH] !added health bar placeholder --- .../comp/placeholder/RPGPlaceholders.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/Indyuce/mmocore/comp/placeholder/RPGPlaceholders.java b/src/main/java/net/Indyuce/mmocore/comp/placeholder/RPGPlaceholders.java index d92fb2a0..15c37194 100644 --- a/src/main/java/net/Indyuce/mmocore/comp/placeholder/RPGPlaceholders.java +++ b/src/main/java/net/Indyuce/mmocore/comp/placeholder/RPGPlaceholders.java @@ -1,6 +1,5 @@ package net.Indyuce.mmocore.comp.placeholder; -import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.OfflinePlayer; @@ -62,11 +61,25 @@ public class RPGPlaceholders extends PlaceholderExpansion { else if (identifier.equals("combat")) return String.valueOf(PlayerData.get(player).isInCombat()); - else if (identifier.equals("health")) { - Validate.isTrue(player.isOnline(), "Player must be online"); + else if (identifier.equals("health") && player.isOnline()) { return StatType.MAX_HEALTH.format(player.getPlayer().getHealth()); } + else if (identifier.equals("max_health") && player.isOnline()) { + return StatType.MAX_HEALTH.format(player.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); + } + + else if(identifier.equals("health_bar") && player.isOnline()) { + StringBuilder format = new StringBuilder(); + double ratio = 20 * player.getPlayer().getHealth() + / player.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); + for (double j = 1; j < 20; j++) + format.append((ratio >= j ? ChatColor.RED + : ratio >= j - .5 ? ChatColor.DARK_RED : ChatColor.DARK_GRAY) + + AltChar.listSquare); + return format.toString(); + } + else if (identifier.equals("class")) return PlayerData.get(player).getProfess().getName(); @@ -89,11 +102,6 @@ public class RPGPlaceholders extends PlaceholderExpansion { return "" + PlayerData.get(player).getCollectionSkills() .getLevel(identifier.substring(11).replace(" ", "-").replace("_", "-").toLowerCase()); - else if (identifier.equals("max_health")) { - Validate.isTrue(player.isOnline(), "Player must be online"); - return StatType.MAX_HEALTH.format(player.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); - } - else if (identifier.equals("experience")) return "" + PlayerData.get(player).getExperience();