From ad421015ff36983d12284d62c5dfbc512de2afc2 Mon Sep 17 00:00:00 2001 From: Teriuihi Date: Fri, 7 Feb 2025 23:25:10 +0100 Subject: [PATCH] Reset player health on game end. Ensure players have full health when the game ends by resetting their max health attribute and current health to default values. Logged an error if the max health attribute is unavailable. --- src/main/java/com/alttd/ctf/game/phases/EndedPhase.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/com/alttd/ctf/game/phases/EndedPhase.java b/src/main/java/com/alttd/ctf/game/phases/EndedPhase.java index 6bc0da3..ee74339 100644 --- a/src/main/java/com/alttd/ctf/game/phases/EndedPhase.java +++ b/src/main/java/com/alttd/ctf/game/phases/EndedPhase.java @@ -12,6 +12,8 @@ import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; +import org.bukkit.attribute.Attribute; +import org.bukkit.attribute.AttributeInstance; import java.util.ArrayList; import java.util.HashMap; @@ -39,6 +41,13 @@ public class EndedPhase implements GamePhaseExecutor { player.getInventory().clear(); player.updateInventory(); player.teleportAsync(spawnLocation); + AttributeInstance maxHealthAttribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH); + if (maxHealthAttribute == null) { + log.error("Player does not have max health attribute"); + return; + } + maxHealthAttribute.setBaseValue(20); + player.setHealth(20); }); flag.reset(); }).start();