Skip to content

Commit

Permalink
Re-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 8274bd9 commit 2ad9b93
Showing 1 changed file with 2 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
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;
import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
Expand All @@ -16,7 +16,6 @@
import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.object.TownBlockType;
import com.palmergames.bukkit.towny.utils.CombatUtil;
import com.palmergames.bukkit.towny.utils.MinecraftVersion;
import com.palmergames.bukkit.util.BukkitTools;

public class HealthRegenTimerTask extends TownyTimerTask {
Expand Down Expand Up @@ -78,7 +77,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;
Expand All @@ -96,12 +95,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 2ad9b93

Please sign in to comment.