
# -> If player does not have their own respawn time then set one
execute unless score @s OverlyRealistic.Player.RespawnCountdownTime matches -2147483648..2147483647 run \
    scoreboard players operation @s OverlyRealistic.Player.RespawnCountdownTime = #or.setting.respawn_countdown_time OverlyRealistic.Settings.ArbitrarySetting

# -> Remove second
scoreboard players remove @s OverlyRealistic.Player.RespawnCountdownTime 1

# -> Display time
title @s times 0 40 40
title @s title " "
title @s subtitle [{text:"",extra:[{text:"Respawning in: ",color:"#9e1c1c"},{score:{name:"@s",objective:"OverlyRealistic.Player.RespawnCountdownTime"},color:"#9e1c1c"},{text:"s",color:"#9e1c1c"}]}]

# -> If player's respawn countdown != 0 then return
execute if score @s OverlyRealistic.Player.RespawnCountdownTime matches 1.. run \
    return fail

# -> Reset respawn time
scoreboard players reset @s OverlyRealistic.Player.RespawnCountdownTime

# -> Revive player
function overly_realistic:players/revive/revive_player

# -> If 'Randomized Respawning' is enabled then return and respawn player randomly
execute if score #or.setting.randomized_respawning OverlyRealistic.Settings.ArbitrarySetting matches 1 run \
    return run \
        function overly_realistic:players/revive/randomized_respawning/respawn_player

# -> Get spawn position
data modify storage overly_realistic:general world_spawn_pos_x set from storage overly_realistic:general world_spawn_location[0]
data modify storage overly_realistic:general world_spawn_pos_y set from storage overly_realistic:general world_spawn_location[1]
data modify storage overly_realistic:general world_spawn_pos_z set from storage overly_realistic:general world_spawn_location[2]

# -> Move player to spawn
function overly_realistic:players/ghost/respawn_countdown/respawn_player_move with storage overly_realistic:general
