# Runs the function again in 1 second
schedule function ss:timed/1sec 1s replace

# Runs lobby slow
function ss:lobby/slow

# Detects if a player has joined and their time is not set.
# (Players joining singleplayer for the first time will get this set, but not any other time)
# (Will always reset rejoining player on a multiplayer server.)
execute as @a unless score @s time = #world time run function ss:player/join
# Adds 1 to the time and applies to all players
scoreboard players add #world time 1
scoreboard players operation @a time = #world time

# Runs game if game is running
execute if score run ssData matches 1 run function ss:main/slow
execute if score run zombData matches 1 run function ss:zomb/slow

# Kills all arrows in ground
execute as @e[type=arrow,nbt={inGround:1b}] run function ss:main/kill_arrow

# Player respawning
scoreboard players remove @a[scores={deathTimer=1..}] deathTimer 1
execute as @a[scores={deathTimer=1..}] run title @s subtitle [{"text":"respawning in ","color":"gray"},{"score":{"name":"@s","objective":"deathTimer"},"color":"#f0f01c"},{"text":" seconds..."}]
execute as @a[scores={deathTimer=0}] run function ss:player/timed/respawn

# Removes balloons after a while
execute as @e[tag=present_stand,tag=!popped] at @s run function ss:main/balloon/time

# Gives players black hole advancement
execute positioned 0.89 33.96 -67.00 as @a[distance=..10,tag=!h9] run advancement grant @s only ss:secret/black_hole

# Removes music score from all players
scoreboard players remove @a musicTime 1
execute as @a[scores={musicTime=..0,location=0}] at @s run function ss:music/lobby_music
execute as @a[scores={musicTime=..0,location=1..2}] at @s run function ss:music/game_music
execute as @a[scores={musicTime=..0,location=3..4}] at @s run function ss:music/zomb_music

execute as @a unless score @s location matches 1..2 run xp set @s 0 levels 