Skip to content

Commit

Permalink
Fix max health attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Warriorrrr committed Nov 19, 2024
1 parent 2721ebf commit a941abc
Showing 1 changed file with 2 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.get(NamespacedKey.minecraft("max_health"))).getValue();

// Shrink gained to fit below the maxHP.
final double gained = futureHP > maxHP ? 1.0 - (futureHP - maxHP) : 1.0;
Expand All @@ -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");
}
}

0 comments on commit a941abc

Please sign in to comment.