Skip to content

Commit

Permalink
Replace getOrThrow
Browse files Browse the repository at this point in the history
  • Loading branch information
Warriorrrr committed Nov 19, 2024
1 parent 2ad9b93 commit 6056735
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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 @@ -18,7 +19,11 @@
import com.palmergames.bukkit.towny.utils.CombatUtil;
import com.palmergames.bukkit.util.BukkitTools;

import java.util.Objects;

public class HealthRegenTimerTask extends TownyTimerTask {

private static final Attribute MAX_HEALTH = Objects.requireNonNull(Registry.ATTRIBUTE.get(NamespacedKey.minecraft("max_health")), "max health attribute");

static {
TownySettings.addReloadListener(NamespacedKey.fromString("towny:health-regen-task"), () -> TownyTimerHandler.toggleHealthRegen(TownySettings.hasHealthRegen()));
Expand Down Expand Up @@ -77,7 +82,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(Registry.ATTRIBUTE.getOrThrow(NamespacedKey.minecraft("max_health"))).getValue();
final double maxHP = player.getAttribute(MAX_HEALTH).getValue();

// Shrink gained to fit below the maxHP.
final double gained = futureHP > maxHP ? 1.0 - (futureHP - maxHP) : 1.0;
Expand Down

0 comments on commit 6056735

Please sign in to comment.