From 8db88f57c4ae44373c91820ec7d16b3925881c2d Mon Sep 17 00:00:00 2001 From: Warrior <50800980+Warriorrrr@users.noreply.github.com> Date: Tue, 19 Nov 2024 16:35:47 +0100 Subject: [PATCH] Fix max health attribute --- .../bukkit/towny/tasks/HealthRegenTimerTask.java | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/Towny/src/main/java/com/palmergames/bukkit/towny/tasks/HealthRegenTimerTask.java b/Towny/src/main/java/com/palmergames/bukkit/towny/tasks/HealthRegenTimerTask.java index 065f2f8b1d..4d22753e95 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/towny/tasks/HealthRegenTimerTask.java +++ b/Towny/src/main/java/com/palmergames/bukkit/towny/tasks/HealthRegenTimerTask.java @@ -6,6 +6,7 @@ import com.palmergames.bukkit.towny.object.TownBlock; import org.bukkit.NamespacedKey; +import org.bukkit.Registry; import org.bukkit.Server; import org.bukkit.attribute.Attribute; import org.bukkit.entity.Player; @@ -78,7 +79,7 @@ private void evaluateHealth(Player player) { // Heal 1 HP while in town. final double currentHP = player.getHealth(); final double futureHP = currentHP + 1; - final double maxHP = player.getAttribute(getMaxHealthAttribute()).getValue(); + final double maxHP = player.getAttribute(Registry.ATTRIBUTE.getOrThrow(NamespacedKey.minecraft("max_health"))).getValue(); // Shrink gained to fit below the maxHP. final double gained = futureHP > maxHP ? 1.0 - (futureHP - maxHP) : 1.0; @@ -96,12 +97,4 @@ private void tryIncreaseHealth(Player player, double currentHealth, double maxHe player.setHealth(Math.min(maxHealth, event.getAmount() + currentHealth)); } - - @SuppressWarnings("deprecation") - private Attribute getMaxHealthAttribute() { - if (MinecraftVersion.CURRENT_VERSION.isNewerThanOrEquals(MinecraftVersion.MINECRAFT_1_21_3)) - return Attribute.MAX_HEALTH; - else - return Attribute.valueOf("GENERIC_MAX_HEALTH"); - } }