#unfreeze
tag @e[tag=dummy] remove error_playercount
execute @e[tag=dummy,scores={playercount=2}] ~ ~ ~ execute @a[scores={player_id=1}] ~ ~ ~ execute @a[scores={player_id=2}] ~ ~ ~ tag @e[tag=dummy] add error_playercount
execute @e[tag=dummy,scores={playercount=3}] ~ ~ ~ execute @a[scores={player_id=1}] ~ ~ ~ execute @a[scores={player_id=2}] ~ ~ ~ execute @a[scores={player_id=3}] ~ ~ ~ tag @e[tag=dummy] add error_playercount
execute @e[tag=dummy,scores={playercount=4}] ~ ~ ~ execute @a[scores={player_id=1}] ~ ~ ~ execute @a[scores={player_id=2}] ~ ~ ~ execute @a[scores={player_id=3}] ~ ~ ~ execute @a[scores={player_id=4}] ~ ~ ~ tag @e[tag=dummy] add error_playercount
execute @e[tag=dummy,tag=error_playercount,scores={ingame=2}] ~ ~ ~ function error_unpause





#tick
scoreboard players remove @e[tag=dummy] stoperror_tick 1
scoreboard players remove @e[tag=dummy,scores={stoperror_tick=0}] stoperror_sec 1
scoreboard players set @e[tag=dummy,scores={stoperror_tick=0}] stoperror_tick 20


#seconds
scoreboard players remove @e[tag=dummy,scores={stoperror_sec=-1}] stoperror_min 1
scoreboard players set @e[tag=dummy,scores={stoperror_sec=-1}] stoperror_sec 59


#extrazero
scoreboard players reset * stoperror_extra
scoreboard players set @e[tag=dummy,scores={stoperror_sec=0..9}] stoperror_extra 0


execute @e[tag=dummy,scores={stoperror_tick=20}] ~ ~ ~ title @a times 0 20 10
execute @e[tag=dummy,scores={stoperror_tick=20}] ~ ~ ~ title @a title §4
execute @e[tag=dummy,scores={stoperror_tick=20}] ~ ~ ~ titleraw @a subtitle {"rawtext": [{"text": "§cGame will automatically stop in "},{"score":{"name":"@e[tag=dummy]","objective":"stoperror_min"}},{"text": ":"},{"score":{"name":"@e[tag=dummy]","objective":"stoperror_extra"}},{"score":{"name":"@e[tag=dummy]","objective":"stoperror_sec"}}]}




execute @e[tag=dummy,scores={stoperror_tick=20,stoperror_sec=50}] ~ ~ ~ tellraw @a {"rawtext": [{"text": "§cMissing players! Game will continue when all players reconnect! You can also manually stop the game by pressing the button on the right."}]}
execute @e[tag=dummy,scores={stoperror_tick=20,stoperror_sec=40}] ~ ~ ~ tellraw @a {"rawtext": [{"text": "§cMissing players! Game will continue when all players reconnect! You can also manually stop the game by pressing the button on the right."}]}
execute @e[tag=dummy,scores={stoperror_tick=20,stoperror_sec=30}] ~ ~ ~ tellraw @a {"rawtext": [{"text": "§cMissing players! Game will continue when all players reconnect! You can also manually stop the game by pressing the button on the right."}]}
execute @e[tag=dummy,scores={stoperror_tick=20,stoperror_sec=20}] ~ ~ ~ tellraw @a {"rawtext": [{"text": "§cMissing players! Game will continue when all players reconnect! You can also manually stop the game by pressing the button on the right."}]}
execute @e[tag=dummy,scores={stoperror_tick=20,stoperror_sec=10}] ~ ~ ~ tellraw @a {"rawtext": [{"text": "§cMissing players! Game will continue when all players reconnect! You can also manually stop the game by pressing the button on the right."}]}
execute @e[tag=dummy,scores={stoperror_tick=20,stoperror_sec=0,stoperror_min=1..}] ~ ~ ~ tellraw @a {"rawtext": [{"text": "§cMissing players! Game will continue when all players reconnect! You can also manually stop the game by pressing the button on the right."}]}
execute @e[tag=dummy,scores={stoperror_tick=20,stoperror_sec=0,stoperror_min=0}] ~ ~ ~ tellraw @a {"rawtext": [{"text": "§cGame stopped!"}]}
execute @e[tag=dummy,scores={stoperror_tick=20,stoperror_sec=0,stoperror_min=0}] ~ ~ ~ function stop




#stop buttons
scoreboard players add @a stopbutton 0
scoreboard players remove @a[scores={stopbutton=1..}] stopbutton 1

execute @a[scores={stopbutton=1..,player_id=1}] ~ ~ ~ detect 33 28 -45 minecraft:mangrove_button 10 function stop_button_confirm
execute @a[scores={stopbutton=1..,player_id=2}] ~ ~ ~ detect 43 28 -33 minecraft:mangrove_button 11 function stop_button_confirm
execute @a[scores={stopbutton=1..,player_id=3}] ~ ~ ~ detect 44 28 -44 minecraft:mangrove_button 13 function stop_button_confirm
execute @a[scores={stopbutton=1..,player_id=4}] ~ ~ ~ detect 32 28 -34 minecraft:mangrove_button 12 function stop_button_confirm

execute @a[scores={stopbutton=0,player_id=1}] ~ ~ ~ detect 33 28 -45 minecraft:mangrove_button 10 function stop_button_request
execute @a[scores={stopbutton=0,player_id=2}] ~ ~ ~ detect 43 28 -33 minecraft:mangrove_button 11 function stop_button_request
execute @a[scores={stopbutton=0,player_id=3}] ~ ~ ~ detect 44 28 -44 minecraft:mangrove_button 13 function stop_button_request
execute @a[scores={stopbutton=0,player_id=4}] ~ ~ ~ detect 32 28 -34 minecraft:mangrove_button 12 function stop_button_request

setblock 33 28 -45 minecraft:mangrove_button 2
setblock 43 28 -33 minecraft:mangrove_button 3
setblock 44 28 -44 minecraft:mangrove_button 5
setblock 32 28 -34 minecraft:mangrove_button 4





#fix draw button
setblock 43 28 -45 minecraft:mangrove_button 2
setblock 33 28 -33 minecraft:mangrove_button 3
setblock 44 28 -34 minecraft:mangrove_button 5
setblock 32 28 -44 minecraft:mangrove_button 4
