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.
This commit is contained in:
Teriuihi 2025-02-07 23:25:10 +01:00
parent 73c11ab1ca
commit ad421015ff

View File

@ -12,6 +12,8 @@ import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -39,6 +41,13 @@ public class EndedPhase implements GamePhaseExecutor {
player.getInventory().clear(); player.getInventory().clear();
player.updateInventory(); player.updateInventory();
player.teleportAsync(spawnLocation); 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(); flag.reset();
}).start(); }).start();