i tried this:
@SubscribeEvent
public static void playerRespawn(PlayerRespawnEvent event) {
Player player = event.getPlayer();
player.getAttribute(Attributes.MAX_HEALTH).setBaseValue(playerhealth - 2);
if (playerhealth == 2) {
((ServerPlayer) player).setGameMode(GameType.SPECTATOR);
Vec3 playerPos = player.position();
teleportPlayer (player, playerPos);
}
}
static void teleportPlayer(Player player, Vec3 position) {
while (playerhealth == 0) {
player.setpos(position);
}
}
but it just crashed me...without crashing me. basically nothing worked anymore from what i know, because i was stuck in spectator and commands didn't work anymore