From 38f9b6df64f83106d812a3d09bddd750b4535557 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Mon, 13 Nov 2023 11:28:32 +0000 Subject: [PATCH] Added %health_percent% placeholder --- .../ecomobs/mob/placeholder/MobPlaceholders.kt | 2 ++ .../impl/MobPlaceholderHealthPercent.kt | 14 ++++++++++++++ .../src/main/resources/mobs/_example.yml | 4 +++- 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/mob/placeholder/impl/MobPlaceholderHealthPercent.kt diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/mob/placeholder/MobPlaceholders.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/mob/placeholder/MobPlaceholders.kt index 00c4441..8f28bb2 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/mob/placeholder/MobPlaceholders.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/mob/placeholder/MobPlaceholders.kt @@ -14,6 +14,7 @@ import com.willfp.ecomobs.mob.event.impl.MobEventRangedAttack import com.willfp.ecomobs.mob.event.impl.MobEventSpawn import com.willfp.ecomobs.mob.event.impl.MobEventTakeDamage import com.willfp.ecomobs.mob.placeholder.impl.MobPlaceholderHealth +import com.willfp.ecomobs.mob.placeholder.impl.MobPlaceholderHealthPercent import com.willfp.ecomobs.mob.placeholder.impl.MobPlaceholderMaxHealth import com.willfp.ecomobs.mob.placeholder.impl.MobPlaceholderTime @@ -21,6 +22,7 @@ object MobPlaceholders : Registry() { init { register(MobPlaceholderHealth) register(MobPlaceholderMaxHealth) + register(MobPlaceholderHealthPercent) register(MobPlaceholderTime) } } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/mob/placeholder/impl/MobPlaceholderHealthPercent.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/mob/placeholder/impl/MobPlaceholderHealthPercent.kt new file mode 100644 index 0000000..3fd50db --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/mob/placeholder/impl/MobPlaceholderHealthPercent.kt @@ -0,0 +1,14 @@ +package com.willfp.ecomobs.mob.placeholder.impl + +import com.willfp.eco.util.toNiceString +import com.willfp.ecomobs.mob.LivingMob +import com.willfp.ecomobs.mob.placeholder.MobPlaceholder + +object MobPlaceholderHealthPercent : MobPlaceholder("health_percent") { + override fun getValue(mob: LivingMob): String { + val health = mob.entity.health + val maxHealth = mob.entity.getAttribute(org.bukkit.attribute.Attribute.GENERIC_MAX_HEALTH)?.value ?: return "0" + + return (health / maxHealth * 100).toNiceString() + } +} diff --git a/eco-core/core-plugin/src/main/resources/mobs/_example.yml b/eco-core/core-plugin/src/main/resources/mobs/_example.yml index 1695e16..81f3f7a 100644 --- a/eco-core/core-plugin/src/main/resources/mobs/_example.yml +++ b/eco-core/core-plugin/src/main/resources/mobs/_example.yml @@ -11,7 +11,8 @@ mob: zombie attack-damage:90 movement-speed:1.5 follow-range:16 health:1200 # The ID of the mob category, handles spawning. category: common -# Supported placeholders: %health%, %time% (formats as minutes:seconds, eg 1:56) +# Supported placeholders: +# %health%, %max_health%, %health_percent%, %time% (formats as minutes:seconds, eg 1:56) display-name: "&cNecrotic Soldier &7| &c%health%♥ &7| &e%time%" # If the mob you're using supports equipment, you can specify the items in each slot. @@ -53,6 +54,7 @@ custom-ai: # Effects are done from the player's perspective: to treat the player as the victim, # either use self_as_victim in args, or use player_as_victim in mutators. +# You can use display name placeholders in effects effects: # Effects ran when the mob spawns spawn: [ ]