execute if score countdown Stats matches 0.. run function mctsts:lobby/countdown


execute positioned 4 26 34 as @a[distance=..4] at @s if block ~ ~ ~ end_gateway run setblock 13 32 33 air
execute positioned 4 26 34 as @a[distance=..4] at @s if block ~ ~ ~ end_gateway run setblock 13 32 35 air
execute positioned 4 26 34 as @a[distance=..4] at @s if block ~ ~ ~ end_gateway if block 4 39 34 air run clone 9 20 39 -1 18 29 -1 39 29
execute positioned 4 26 34 as @a[distance=..4] at @s if block ~ ~ ~ end_gateway unless score countdown Stats matches 0.. run scoreboard players set countdown Stats 250
execute positioned 4 26 34 as @a[distance=..4] at @s if block ~ ~ ~ end_gateway run playsound minecraft:entity.shulker.shoot master @s ~ ~7 ~ 1 0.75
execute positioned 4 26 34 as @a[distance=..4] at @s if block ~ ~ ~ end_gateway run tp @s 4 41 34 ~ 0

execute if score countdown Stats matches -1.. positioned 4 39 34 unless block ~ ~ ~ air positioned ~ ~2 ~ unless entity @a[distance=..3.5] unless entity @a[distance=..4.5,nbt={OnGround:1b}] run scoreboard players set countdown Stats -1
execute if score countdown Stats matches -1.. positioned 4 39 34 unless block ~ ~ ~ air positioned ~ ~2 ~ unless entity @a[distance=..3.5] unless entity @a[distance=..4.5,nbt={OnGround:1b}] run title @a times 0 15 20
execute if score countdown Stats matches -1.. positioned 4 39 34 unless block ~ ~ ~ air positioned ~ ~2 ~ unless entity @a[distance=..3.5] unless entity @a[distance=..4.5,nbt={OnGround:1b}] run title @a title [""]
execute if score countdown Stats matches -1.. positioned 4 39 34 unless block ~ ~ ~ air positioned ~ ~2 ~ unless entity @a[distance=..3.5] unless entity @a[distance=..4.5,nbt={OnGround:1b}] run title @a subtitle [{"translate":"lobby.game_cancelled","color":"red","bold":true}]
execute if score countdown Stats matches -1.. positioned 4 39 34 unless block ~ ~ ~ air positioned ~ ~2 ~ unless entity @a[distance=..3.5] unless entity @a[distance=..4.5,nbt={OnGround:1b}] run function mctsts:lobby/countdown_remove

scoreboard players set lobbyPlayers Stats 0
execute positioned 4 39 34 as @a[distance=..3.5,nbt={OnGround:0b}] run scoreboard players add lobbyPlayers Stats 1
execute positioned 4 39 34 as @a[distance=..4.5,nbt={OnGround:1b}] run scoreboard players add lobbyPlayers Stats 1


execute positioned 4 39 34 run team join ready @a[distance=..5,team=!ready] 
execute positioned 4 39 34 run team join lobby @a[distance=5..,team=!lobby] 

clear @a[gamemode=adventure]

# tutorial translations
execute as @a at @s anchored eyes facing entity @e[type=armor_stand,tag=tut1,distance=..7,limit=1] feet anchored feet positioned ^ ^ ^1 rotated as @s positioned ^ ^ ^-1 if entity @s[distance=..0.5] run title @s actionbar [{"translate":"lobby.tutorial.1","color":"black"}]
execute as @a at @s anchored eyes facing entity @e[type=armor_stand,tag=tut2,distance=..7,limit=1] feet anchored feet positioned ^ ^ ^1 rotated as @s positioned ^ ^ ^-1 if entity @s[distance=..0.5] run title @s actionbar [{"translate":"lobby.tutorial.2","color":"black"}]