diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/actionbar/ActionBarHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/actionbar/ActionBarHandler.kt index 8490789..e98df95 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/actionbar/ActionBarHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/actionbar/ActionBarHandler.kt @@ -4,11 +4,15 @@ import com.willfp.eco.core.EcoPlugin import com.willfp.eco.core.data.keys.PersistentDataKey import com.willfp.eco.core.data.keys.PersistentDataKeyType import com.willfp.eco.core.data.profile +import com.willfp.eco.core.placeholder.InjectablePlaceholder +import com.willfp.eco.core.placeholder.PlaceholderInjectable +import com.willfp.eco.core.placeholder.PlayerStaticPlaceholder import com.willfp.eco.core.placeholder.context.placeholderContext import com.willfp.eco.util.containsIgnoreCase import com.willfp.eco.util.namespacedKeyOf import org.bukkit.Bukkit import org.bukkit.GameMode +import org.bukkit.attribute.Attribute import org.bukkit.entity.Player import org.bukkit.event.EventHandler import org.bukkit.event.Listener @@ -106,7 +110,8 @@ class ActionBarHandler( plugin.configYml .getFormattedString( "persistent-action-bar.format", placeholderContext( - player = player + player = player, + injectable = PlayerHealthInjectable ) ) ) @@ -119,4 +124,27 @@ class ActionBarHandler( } } } + + private object PlayerHealthInjectable : PlaceholderInjectable { + private val injections = listOf( + PlayerStaticPlaceholder( + "health" + ) { it.health.toInt().toString() }, + PlayerStaticPlaceholder( + "max_health" + ) { it.getAttribute(Attribute.GENERIC_MAX_HEALTH)?.value?.toInt()?.toString() ?: "20" }, + ) + + override fun getPlaceholderInjections(): List { + return injections + } + + override fun addInjectablePlaceholder(p0: Iterable) { + return + } + + override fun clearInjectedPlaceholders() { + return + } + } } diff --git a/eco-core/core-plugin/src/main/resources/config.yml b/eco-core/core-plugin/src/main/resources/config.yml index 13a25bb..eafeef4 100644 --- a/eco-core/core-plugin/src/main/resources/config.yml +++ b/eco-core/core-plugin/src/main/resources/config.yml @@ -249,10 +249,10 @@ persistent-action-bar: # If a player's health should be scaled to always display as 10 hearts. scale-health: true # The format - format: "&cā¤ &f%player_health_rounded%&8/&f%player_max_health_rounded% &#e884b0šŸ›” &f%ecoskills_defense% &8| &#db0000šŸ—” &f%ecoskills_strength% &8| (ffe6✦ &f%ecoskills_speed%" + format: "&cā¤ &f%health%&8/&f%max_health% &#e884b0šŸ›” &f%ecoskills_defense% &8| &#db0000šŸ—” &f%ecoskills_strength% &8| (ffe6✦ &f%ecoskills_speed%" # Optional format if mana is being used. - # format: "&cā¤ &f%player_health_rounded%&8/&f%player_max_health_rounded% &f%ecoskills_mana%&8/&f%ecoskills_mana_limit% (ffe6🌊" + # format: "&cā¤ &f%health%&8/&f%max_health% &f%ecoskills_mana%&8/&f%ecoskills_mana_limit% (ffe6🌊" # The worlds that the action bar should be disabled in. disabled-in-worlds: [ ]