function tick{
    #game type#
    execute if score $players PlayerCount matches ..1 run scoreboard players set $map mapselect 1

    execute if score $map mapselect matches 3.. run scoreboard players set $map mapselect 1
    execute if score $map mapselect matches ..0 run scoreboard players set $map mapselect 2

    execute if score $map mapselect matches 1 run data merge block -6 34 0 {front_text:{messages:['{"text":""}','{"text":"Mirror","color":"yellow"}','{"text":"[One by One]","color":"white"}','{"text":""}']}}
    execute if score $map mapselect matches 2 run data merge block -6 34 0 {front_text:{messages:['{"text":""}','{"text":"Versus","color":"yellow"}','{"text":"[One vs One]","color":"white"}','{"text":""}']}}

    #testfor build#
    execute if blocks 3 5 17 13 11 11 3 17 5 all run function main:complete

    execute if blocks -5 5 17 5 11 11 3 17 5 all as @a[tag=sep,scores={id=2}] run function main:leftcomplete
    execute if blocks 11 5 17 21 11 11 3 17 5 all as @a[tag=sep,scores={id=3}] run function main:rightcomplete

        
    #effects#
    effect give @a saturation 100000 255 true
    effect give @a regeneration 100000 255 true
    effect give @a night_vision 100000 255 true
    effect give @a haste 100000 120 true

    #bossbar view#
    bossbar set minecraft:time players @a[team=!lobby]

    #revoke#
    advancement revoke @a everything
    gamerule doLimitedCrafting true
    recipe take @a *

    #flag items#
    execute as @e[type=item] at @s run function loot:__generated__/execute/1
    execute as @e[type=item] at @s run data modify entity @s Item.tag.HideFlags set value 127

    #playercounter#
    execute store result score $players PlayerCount if entity @a

    execute if score $players PlayerCount matches 1.. if score $progress ip matches 0 if score $confirm ip matches 0 run team join lobby @a

    #loop to builds#
    execute if score $map mapselect matches 1 if score $round round matches 150 run scoreboard players set $round round 1

    gamemode adventure @a[tag=!aandeel]


    #win#
    execute as @a[team=ingame] if score @s wins = $max points at @s run function main:temp/sub/text/_hidden_/win

    data merge block -4 34 -8 {front_text:{messages:['{"text":""}','{"text":"Points To Win","color":"#FEFFB6","bold":true}','{"score":{"name":"$max","objective":"points"},"color":"#ACF8F5","bold":true}','{"text":""}']}}
    
    execute if score $max points matches 31.. run scoreboard players set $max points 30
    execute if score $max points matches ..1 run scoreboard players set $max points 1

    #doublejump#
    scoreboard players add @a[tag=DoubleJump] jump_timer 1
    tag @a[tag=DoubleJumper,nbt={FallFlying:1b,}] add DoubleJump
    clear @a[tag=DoubleJump] minecraft:elytra
    tag @a[scores={jump_timer=4}] remove DoubleJump
    effect give @a[scores={jump_timer=1}] minecraft:levitation 1 30 true
    effect clear @a[scores={jump_timer=4}] minecraft:levitation
    scoreboard players set @a[scores={jump_timer=4}] jump_timer 0
    #Double Jump Mechanics
    execute as @a[tag=DoubleJumper,nbt={OnGround:1b}] run item replace entity @a[tag=DoubleJumper,nbt={OnGround:1b}] armor.chest with minecraft:elytra{Enchantments:[{id:"minecraft:binding_curse",lvl:1s}],Unbreakable:1b}
    #Reset Double Jump
    execute at @a[tag=DoubleJumper,nbt={FallFlying:1b}] anchored feet run particle minecraft:poof ~ ~ ~ 0.4 0.4 0.4 0 30
    execute at @a[tag=DoubleJumper,nbt={FallFlying:1b}] run playsound minecraft:block.slime_block.fall ambient @a ~ ~ ~
    #Double Jump Special Effects

    #UpdateReadySign#
    execute if score $progress ip matches 0 run title @a[team=lobby] actionbar ["",{"score":{"name":"$people","objective":"ready"},"bold":true,"color":"gold"},{"text":"/","bold":true,"color":"red"},{"score":{"name":"$players","objective":"PlayerCount"},"bold":true,"color":"gold"},{"text":" Players are Ready to Play","bold":true,"color":"red"}]

    #ReadyUp#
    kill @e[type=item,nbt={Item:{id:"minecraft:carrot_on_a_stick"}}]

    execute store result score $people ready if entity @a[team=lobby,tag=ready]

    execute as @a if score @s[team=lobby,tag=!ready] readyup matches 1 run{
        tag @s add ready
        tellraw @s {"text":"You are now ready to play!","color":"aqua","bold":true,"underlined":false}
        playsound minecraft:block.note_block.bell master @s ^ ^ ^ 2 1 1
        scoreboard players set @s readyup 0
    }

    execute as @a if score @s[team=lobby,tag=ready] readyup matches 1 run{
        tag @s remove ready
        tellraw @s {"text":"You have withdrawn from the game!","color":"red","bold":true,"underlined":false}
        playsound minecraft:block.note_block.bass master @s ~ ~ ~ 2 1 1
        scoreboard players set @s readyup 0
    }
    
    execute if entity @a[team=lobby,tag=!ready,tag=!admin] run{
        item replace entity @a[tag=!ready] hotbar.4 with carrot_on_a_stick{display:{Name:'[{"text":"Ready Up","color":"red","bold":true,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false},{"text":" (Right Click)","color":"white","bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false}]'},CustomModelData:1111,Enchantments:[{}]} 1
        LOOP(9,i){
            !IF(i!==4){
                item replace entity @a[team=lobby,tag=!ready,tag=!admin] hotbar.<%i%> with air 1
            }
        }
        LOOP(27,i){
            item replace entity @a[team=lobby,tag=!ready,tag=!admin] inventory.<%i%> with air 1
        }
    }

    execute if entity @a[team=lobby,tag=ready,tag=!admin] run{
        item replace entity @a[team=lobby,tag=ready] hotbar.4 with carrot_on_a_stick{display:{Name:'[{"text":"Stay Behind","color":"red","bold":true,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false},{"text":" (Right Click)","color":"white","bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false}]'},CustomModelData:1112} 1
        LOOP(9,i){
            !IF(i!==4){
                item replace entity @a[team=lobby,tag=ready,tag=!admin] hotbar.<%i%> with air 1
            }
        }
        LOOP(27,i){
            item replace entity @a[team=lobby,tag=ready,tag=!admin] inventory.<%i%> with air 1
        }
    }


    #Difficulty#
    execute if score $difficulty ip matches 1 run data merge block 4 34 -8 {front_text:{messages:['{"text":""}','{"text":"Difficulty","color":"#FEFFB6","bold":true}','{"text":"Professional","color":"white","bold":true}','{"text":"(15s)","color":"white"}']}}
    execute if score $difficulty ip matches 2 run data merge block 4 34 -8 {front_text:{messages:['{"text":"[Recommended]","color":"yellow"}','{"text":"Difficulty","color":"#FEFFB6","bold":true}','{"text":"Intermediate","color":"white","bold":true}','{"text":"(20s)","color":"white"}']}}
    execute if score $difficulty ip matches 3 run data merge block 4 34 -8 {front_text:{messages:['{"text":""}','{"text":"Difficulty","color":"#FEFFB6","bold":true}','{"text":"Amateur","color":"white","bold":true}','{"text":"(30s)","color":"white"}']}}
    execute if score $difficulty ip matches 4.. run scoreboard players set $difficulty ip 1
    execute if score $difficulty ip matches ..0 run scoreboard players set $difficulty ip 3

}

function load{
    say Map Reloaded
    scoreboard players set $max points 5
    scoreboard players set $difficulty ip 2
}

function reset{
    function main:setarena
    function main:clearschedule
    kill @e[type=minecraft:armor_stand,tag=holo]
    tag @a remove processed
    scoreboard objectives remove queue
    scoreboard objectives add queue
    scoreboard players set $order queue 0
    scoreboard players set $constant queue 0
    scoreboard players set $constant PlayerCount 0
    scoreboard objectives remove points
    scoreboard players set $round round 0
    scoreboard players set @a played 0
    scoreboard objectives add points dummy
    scoreboard players set $difficulty ip 2
    execute store result score max id if entity @a[tag=ready]
    execute if score order id = max id run scoreboard players set order id 0
    setblock 8 4 2 minecraft:structure_block
    data modify block 8 4 2 mode set value "LOAD"
    data modify block 8 4 2 name set value "minecraft:clear"
    data modify block 8 4 2 posX set value -5
    data modify block 8 4 2 posY set value 2
    data modify block 8 4 2 posZ set value -3
    fill 3 6 17 13 11 11 air
    setblock 8 3 2 minecraft:redstone_block 
    setblock 8 16 14 minecraft:structure_block
    data modify block 8 16 14 mode set value "LOAD"
    data modify block 8 16 14 name set value "minecraft:build1"
    data modify block 8 16 14 posX set value -5
    data modify block 8 16 14 posY set value 2
    data modify block 8 16 14 posZ set value -3
    data modify block 8 16 14 mirror set value "LEFT_RIGHT"
    setblock 8 17 14 minecraft:redstone_block 
    schedule function main:redstone 1s
    clear @a
    tag @a remove DoubleJumper
    tag @a remove DoubleJump
    scoreboard players reset @a wins
    scoreboard objectives remove wins
    scoreboard objectives add wins dummy {"text":"Points!","color":"gold"}
    scoreboard objectives setdisplay sidebar
    scoreboard players set $round round 0
    scoreboard objectives add jump_timer dummy
    scoreboard players set @a jump_timer 0
    bossbar set minecraft:time value 10
    tag @a remove ingame
    tag @a remove inround
    tag @a remove win
    tag @a remove sep
    scoreboard objectives remove jtimer
    scoreboard objectives remove jump
    scoreboard objectives remove sneak
    scoreboard objectives remove id
    scoreboard objectives add jump minecraft.custom:minecraft.jump
    scoreboard objectives add sneak minecraft.custom:minecraft.sneak_time
    scoreboard objectives add jtimer dummy
    scoreboard objectives add id dummy
    scoreboard players set $difficulty ip 2
    scoreboard players set $progress ip 0
    scoreboard players set $confirm ip 0
    scoreboard players set random build 0
    schedule function main:reset2 2s
    scoreboard players set $max points 5
    scoreboard objectives remove id
    scoreboard objectives add id dummy
    scoreboard players set #ready ready 0
    tag @a remove ready
    bossbar set minecraft:time style progress
    bossbar set minecraft:time max 20
    bossbar set minecraft:time value 20
    bossbar set time name [{"text":" "}]
    data merge block -4 34 -8 {front_text:{messages:['{"text":""}','{"text":"Points To Win","color":"#FEFFB6","bold":true}','{"score":{"name":"$max","objective":"points"},"color":"#ACF8F5","bold":true}','{"text":""}']}}
}

function reset2{
    function main:clearschedule
    summon armor_stand 4 35 -8 {CustomNameVisible:1b,NoGravity:1b,Silent:1b,Invulnerable:1b,Marker:1b,Invisible:1b,CustomName:'{"text":"Set Difficulty","color":"black","bold":true,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false}',Tags:["holo"]}
    summon armor_stand -4 35 -8 {CustomNameVisible:1b,NoGravity:1b,Silent:1b,Invulnerable:1b,Marker:1b,Invisible:1b,CustomName:'{"text":"Set Points","color":"black","bold":true,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false}',Tags:["holo"]}
    tag @a remove processed
    scoreboard objectives remove queue
    scoreboard objectives add queue
    scoreboard players set $order queue 0
    scoreboard players set $constant queue 0
    scoreboard players set $constant PlayerCount 0
    scoreboard objectives remove points
    scoreboard players set $round round 0
    scoreboard players set @a played 0

    scoreboard objectives add points dummy
    
    setblock 8 0 8 minecraft:structure_block
    data modify block 8 0 8 mode set value "LOAD"
    data modify block 8 0 8 name set value "minecraft:empty2"
    data modify block 8 0 8 posX set value -14
    data modify block 8 0 8 posY set value 3
    data modify block 8 0 8 posZ set value -10
    setblock 9 0 8 minecraft:redstone_block
    setblock 9 0 8 minecraft:stone

    setblock 8 4 2 minecraft:structure_block
    data modify block 8 4 2 mode set value "LOAD"
    data modify block 8 4 2 name set value "minecraft:clear"
    data modify block 8 4 2 posX set value -5
    data modify block 8 4 2 posY set value 2
    data modify block 8 4 2 posZ set value -3
    fill 3 6 17 13 11 11 air
    setblock 8 3 2 minecraft:redstone_block 
    setblock 8 16 14 minecraft:structure_block
    data modify block 8 16 14 mode set value "LOAD"
    data modify block 8 16 14 name set value "minecraft:build1"
    data modify block 8 16 14 posX set value -5
    data modify block 8 16 14 posY set value 2
    data modify block 8 16 14 posZ set value -3
    data modify block 8 16 14 mirror set value "LEFT_RIGHT"

    setblock 8 17 14 minecraft:redstone_block 

    schedule function main:redstone 1s

    clear @a

    scoreboard players reset @a wins
    scoreboard objectives remove wins
    scoreboard objectives add wins dummy {"text":"Points!","color":"gold"}
    scoreboard objectives setdisplay sidebar
    scoreboard players set $round round 0

    bossbar set minecraft:time value 10

    tag @a remove ingame
    tag @a remove inround
    tag @a remove win
    tag @a remove sep

    scoreboard players set $max points 5

    scoreboard objectives remove jtimer
    scoreboard objectives remove jump
    scoreboard objectives remove sneak

    scoreboard objectives add jump minecraft.custom:minecraft.jump
    scoreboard objectives add sneak minecraft.custom:minecraft.sneak_time
    scoreboard objectives add jtimer dummy

    scoreboard players set $difficulty ip 2
    scoreboard players set $progress ip 0
    scoreboard players set $confirm ip 0

    scoreboard players set random build 0

    scoreboard objectives remove id
    scoreboard objectives add id dummy
    scoreboard players set #ready ready 0
    tag @a remove ready
    data merge block -4 34 -8 {Text1:'{"text":""}',Text2:'{"text":"Points To Win","bold":true,"color":"#FEFFB6"}',Text3:'{"score":{"name":"$max","objective":"points"},"bold":true,"color":"#ACF8F5"}'}
}


function restart{
    function main:reset
    say Restarted
    tp @a 0 33 7 180 2
    tag @a remove DoubleJumper
    scoreboard players set $max points 5
}

function redstone{
    setblock 8 3 2 minecraft:air
    setblock 8 17 14 minecraft:air
}

function portalstart{
    kill @e[type=item]
    scoreboard players add $round round 1
    fill 13 14 -1 3 6 9 air
    function main:random
    tag @s add inround
    schedule function main:nextround 6s
}

function duoportalstart{
    kill @e[type=item]
    tag @a remove DoubleJumper
    scoreboard players add $round round 1
    function main:random
    execute as @r[team=ingame,limit=1] run{
	        tag @s add sep
            scoreboard players set @s id 2
        }
    execute as @r[team=ingame,tag=!sep,limit=1] run{
	        tag @s add sep
            scoreboard players set @s id 3
        }
    schedule function main:duonextround 6s
}

function nextround{ 
    tag @a[tag=inround] add DoubleJumper
    bossbar set minecraft:time style progress
    bossbar set minecraft:time max 20
    bossbar set minecraft:time value 20
    bossbar set time name [{"text":" "}]
    kill @e[type=item]
    tp @a[tag=inround] 8.5 6.0 15.5 -180 2
    team join build @a[tag=inround]
    LOOP(150,i){
       execute if score random build matches <%i+1%> run function main:rounds/<%i+1%>/view
    }
}

function duonextround{ 
    setblock 8 0 8 minecraft:structure_block
    data modify block 8 0 8 mode set value "LOAD"
    data modify block 8 0 8 name set value "minecraft:empty2"
    data modify block 8 0 8 posX set value -14
    data modify block 8 0 8 posY set value 3
    data modify block 8 0 8 posZ set value -10
    setblock 9 0 8 minecraft:redstone_block
    setblock 9 0 8 minecraft:stone
    setblock 8 0 8 minecraft:structure_block
    data modify block 8 0 8 mode set value "LOAD"
    data modify block 8 0 8 name set value "minecraft:duo"
    data modify block 8 0 8 posX set value -14
    data modify block 8 0 8 posY set value 3
    data modify block 8 0 8 posZ set value -10
    setblock 9 0 8 minecraft:redstone_block
    setblock 9 0 8 minecraft:stone
    bossbar set minecraft:time style progress
    bossbar set minecraft:time max 20
    bossbar set minecraft:time value 20
    bossbar set time name [{"text":" "}]
    kill @e[type=item]
    tag @a[tag=sep] add DoubleJumper
    tag @a[tag=sep] add inround
    team join build @a[tag=sep]
    tp @a[tag=sep,scores={id=2}] 0.5 6.0 14.5 -180 2
    tp @a[tag=sep,scores={id=3}] 16.5 6.0 14.5 -180 2
    LOOP(150,i){
    execute if score random build matches <%i+1%> run function main:duorounds/<%i+1%>/view
    }
}

function forcequit{
    execute as @a if score @s wins = $max points at @s if score @s wins matches 1.. run function main:temp/sub/text/_hidden_/win

    tag @a remove processed
    function main:restart
    tag @a remove ingame
    tag @a remove inround
    scoreboard objectives remove wins
    clear @a
    tp @a 0 33 7 180 2
    title @a actionbar {"text":"GAME ENDED","bold":true,"color":"red"}
}

dir fail{
    function outoftime{
        execute if entity @a[tag=inround] run clear @a[tag=inround]

        execute if entity @a[tag=inround] run title @a[tag=inround] times 0 80 5
        execute if entity @a[tag=inround] run title @a[tag=inround] title {"text":"You Failed!","color":"red"}

        execute if entity @a[tag=inround] run playsound minecraft:entity.generic.explode master @a 11 6 14 10 1
        execute if entity @a[tag=inround] run playsound minecraft:entity.generic.explode master @a 8 6 14 10 1
        execute if entity @a[tag=inround] run playsound minecraft:entity.generic.explode master @a 4 6 14 10 1
        execute if entity @a[tag=inround] run particle minecraft:explosion 8 6 14 10 6 7 0.01 750 normal
        execute if entity @a[tag=inround] if score $map mapselect matches 1 run fill 3 6 17 13 11 11 air
        execute if score $map mapselect matches 2 run setblock 8 0 8 minecraft:structure_block
        execute if score $map mapselect matches 2 run data modify block 8 0 8 mode set value "LOAD"
        execute if score $map mapselect matches 2 run data modify block 8 0 8 name set value "minecraft:duo"
        execute if score $map mapselect matches 2 run data modify block 8 0 8 posX set value -14
        execute if score $map mapselect matches 2 run data modify block 8 0 8 posY set value 3
        execute if score $map mapselect matches 2 run data modify block 8 0 8 posZ set value -10
        setblock 9 0 8 minecraft:redstone_block
        setblock 9 0 8 minecraft:stone
        execute if entity @a[tag=inround] run team join ingame @a[tag=inround]
        tag @a[tag=inround] remove DoubleJumper
        execute if entity @a[tag=inround] run tp @a[tag=inround] -15.5 6.00 8.5 270 2

        execute if score $map mapselect matches 2 run scoreboard players set @a[scores={id=1}] id 0
        execute if score $map mapselect matches 2 run scoreboard players set @a[scores={id=2}] id 0
        execute if score $map mapselect matches 2 run scoreboard players set @a[scores={id=3}] id 0
        execute if entity @a[tag=inround] run tag @a[tag=inround] remove sep
        execute if entity @a[tag=inround] run tag @a[tag=inround] remove inround

        bossbar set minecraft:time visible false
        bossbar set time name [{"text":" "}]

        execute store result score max id if entity @a[tag=ready]
        execute if score order id = max id run scoreboard players set order id 0
        scoreboard players add order id 1
        execute(if score $map mapselect matches 1 as @a[team=ingame] if score @s id = order id){
              function main:portalstart
          }else{
            scoreboard players add order id 1
            execute store result score max id if entity @a[tag=ready]
            execute if score order id = max id run scoreboard players set order id 0
            execute as @a[team=ingame] if score @s id = order id run function main:check
          }
        execute if score $map mapselect matches 2 run{
              function main:duoportalstart
          }
    }
}

dir lobby{
    function htp{
        tellraw @s ["",{"text":"How To Play ","bold":true,"color":"white"},{"text":"Mirror Me","bold":true,"color":"yellow"},{"text":"\n"},{"text":"- You are chosen at random to be teleported onto the platform.","color":"gold"},{"text":"\n"},{"text":"- You will be shown a build and will have 20 seconds to view it.","color":"aqua"},{"text":"\n"},{"text":"- Once the viewing time is over, You'll have 20 seconds to rebuild it... but ","color":"gold"},{"text":"Mirrored","bold":true,"color":"gold"},{"text":".","color":"gold"},{"text":"\n"},{"text":"- If you FAIL to build in the time you have, you will be returned to the viewing area and will wait for your next turn.","color":"aqua"},{"text":"\n"},{"text":"- If you COMPLETE a build in time, you will gain a point, players with the most points at the end wins.","color":"gold"}]
    }

    function htp2{
        tellraw @s ["",{"text":"Tool Tips for ","bold":true,"color":"white"},{"text":"Mirror Me","bold":true,"color":"yellow"},{"text":"\n"},{"text":"- You can double jump by jumping and then sneaking whilst in the air! ","color":"gold"},{"text":"\n"},{"text":"- You will be given all the blocks you need!","color":"aqua"},{"text":"\n"},{"text":"- You will also be given tools to break misplaced blocks!","color":"gold"},{"text":"\n"},{"text":"- If you fail a round, don't worry, you'll be chosen again soon!","color":"aqua"}]
    }
}

dir start{
    function confirm1{
        tellraw @s ["",{"text":"Do you confirm the start of this ","italic":true,"color":"yellow"},{"text":"SINGLEPLAYER","bold":true,"italic":true,"color":"yellow"},{"text":" Match of Mirror Me?","italic":true,"color":"yellow"},{"text":"\n"},{"text":"Click here to confirm","bold":true,"underlined":true,"color":"aqua","clickEvent":{"action":"run_command","value":"/function main:start/confirmed"}},{"text":", then right-click the sign again to start the game!","italic":true,"color":"yellow"}]
    }

    function confirm2{
        tellraw @s ["",{"text":"Do you confirm the start of this ","italic":true,"color":"yellow"},{"text":"MULTIPLAYER","bold":true,"italic":true,"color":"yellow"},{"text":" Match of Mirror Me?","italic":true,"color":"yellow"},{"text":"\n"},{"text":"Click here to confirm","bold":true,"underlined":true,"color":"aqua","clickEvent":{"action":"run_command","value":"/function main:start/confirmed"}},{"text":", then right-click the sign again to start the game!","italic":true,"color":"yellow"}]
    }

    function confirmed{
        scoreboard players set $confirm ip 1
        playsound block.note_block.chime master @s ~ ~ ~ 10 1 1
        tellraw @a ["",{"text":"Game Start Confirmed by ","bold":true,"color":"dark_gray"},{"selector":"@s","bold":true,"color":"gray"}]
        tellraw @s ["",{"text":"Click the sign again to start!","bold":false,"italic":true,"color":"#94FFF8"}]
    }

    function nostart{
        tellraw @s ["",{"text":">> Game failed to start. ","color":"red"},{"text":"Game already in progress!","color":"green"}]
    }

    function nostart2{
        tellraw @s ["",{"text":">> Game failed to start. ","color":"red"},{"text":"No Player's Ready!","color":"green"}]
    }

    function start1{
        function main:setarena
        tag @a[tag=ready] add ingame
        team join ingame @a[tag=ready]
        effect give @a[tag=ready] nausea 5 255 true
        playsound minecraft:block.ender_chest.open master @a[tag=ready] ~ ~ ~ 10 1 1
        tp @a[tag=ready] -15.5 6.00 8.5 270 2

        scoreboard players set $progress ip 1

        clear @a[tag=ready]
        gamemode adventure @a[tag=ready]
        scoreboard players reset @a wins
        scoreboard objectives remove wins
        scoreboard objectives add wins dummy {"text":"Points!","color":"gold"}
        scoreboard objectives setdisplay sidebar wins
        scoreboard players set @a[team=ingame] wins 0
        scoreboard players set $round round 1
        bossbar set minecraft:time value 10

        kill @e[type=minecraft:armor_stand,tag=holo]

        schedule function main:start/start2 1s
    }

    function start2{
        title @a[tag=ready] times 20 80 10
        title @a[tag=ready] title [{"text":"Mirror Me!","bold":true}]
        execute if score $map mapselect matches 1 run tellraw @a[tag=ready] ["",{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"---<","color":"yellow"},{"text":" Mirror Me","bold":false},{"text":" >---","color":"yellow"},{"text":"\n"},{"text":"\u25b6","color":"gray"},{"text":" You have a set amount of time to view the mirrored build.\n"},{"text":"\u25b6 ","color":"gray"},{"text":"Memorise it.\n"},{"text":"\u25b6 ","color":"gray"},{"text":"After the time is up, the mirrored build will disappear.\n"},{"text":"\u25b6","color":"gray"},{"text":" Build what you saw. but Mirrored.\n"},{"text":"(Warning. YOU WILL ONLY SEE THE BUILD ONCE!)","color":"red"}]
        execute if score $map mapselect matches 2 run tellraw @a[tag=ready] ["",{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"\n"},{"text":"---<","color":"yellow"},{"text":" Mirror Me","bold":false},{"text":" >---","color":"yellow"},{"text":"\n"},{"text":"\u25b6","color":"gray"},{"text":" You have a set amount of time to view the mirrored build.\n"},{"text":"\u25b6 ","color":"gray"},{"text":"Memorise it.\n"},{"text":"\u25b6 ","color":"gray"},{"text":"After the time is up, the mirrored build will disappear.\n"},{"text":"\u25b6","color":"gray"},{"text":" Build what you saw. but Mirrored... First to complete the build wins the point!\n"},{"text":"(Warning. YOU WILL ONLY SEE THE BUILD ONCE!)","color":"red"}]

        tag @a[tag=ready] add ingame
        scoreboard players set $round round 0
        scoreboard players set random build 0

        scoreboard players set temp id 0


        scoreboard players add order id 1
        
        execute if score $map mapselect matches 1 run{
        execute as @a[team=ingame] run function main:give_id
        execute(as @a[team=ingame] if score @s id = order id){
              function main:portalstart
          }else{
            scoreboard players add order id 1
            execute as @a[team=ingame] if score @s id = order id run function main:check
          }
        }

        execute if score $map mapselect matches 2 run{
            function main:duoportalstart
          }
        }
    

    
    function startsign{
        execute if score $progress ip matches 1 run tellraw @s {"text":"Action Denied, Game In Progress!","color":"red"}

        execute if score $people ready matches 0 if score $progress ip matches 0 run function main:start/nostart2

        execute if score $people ready matches 1.. if score $players PlayerCount matches ..1 if score $progress ip matches 0 if score $confirm ip matches 0 run function main:start/confirm1

        execute if score $people ready matches 1.. if score $players PlayerCount matches 2.. if score $progress ip matches 0 if score $confirm ip matches 0 run function main:start/confirm2

        execute if score $people ready matches 1.. if score $players PlayerCount matches 2.. if score $progress ip matches 0 if score $confirm ip matches 1 run function main:start/start1

        execute if score $people ready matches 1.. if score $players PlayerCount matches ..1 if score $progress ip matches 0 if score $confirm ip matches 1 run function main:start/start1
    }
}

dir temp{
    dir sub{
        dir text{
            dir _hidden_{
                function win{
                    team leave @a
                    scoreboard objectives remove wins
                    tp @a 0 33 7 180 2
                    clear @a
                    tp @a 0 33 7 180 2
                    title @a times 10 120 50
                    title @a title ["",{"selector":"@s","bold":true,"color":"yellow"},{"text":" WON!","bold":true,"color":"yellow"}]
                    title @a subtitle {"text":"Congratulations!","bold":true,"italic":true,"color":"aqua"}

                    function main:reset
                    scoreboard objectives remove wins
                    tag @a remove ingame
                    tag @a remove inround
                    clear @a
                    tp @a 0 33 7 180 2
                    function main:reset
                    scoreboard objectives remove wins

                    summon firework_rocket -2.41 34.00 0.47 {LifeTime:8,FireworksItem:{id:firework_rocket,Count:1,tag:{Fireworks:{Explosions:[{Type:2,Flicker:1,Colors:[I;16775936,14602026,16775936,15790320],FadeColors:[I;15790320,14602026,16775936,15790320]}],Flight:1}}}}
                    summon firework_rocket 0.55 34.00 0.40 {LifeTime:8,FireworksItem:{id:firework_rocket,Count:1,tag:{Fireworks:{Explosions:[{Type:4,Flicker:1,Colors:[I;16775936,14602026,16775936,15790320],FadeColors:[I;15790320,14602026,16775936,15790320]}],Flight:1}}}}
                    summon firework_rocket 3.48 34.00 0.57 {LifeTime:8,FireworksItem:{id:firework_rocket,Count:1,tag:{Fireworks:{Explosions:[{Type:2,Flicker:1,Colors:[I;16775936,14602026,16775936,15790320],FadeColors:[I;15790320,14602026,16775936,15790320]}],Flight:1}}}}
                    summon firework_rocket -1 34.00 0.47 {LifeTime:8,FireworksItem:{id:firework_rocket,Count:1,tag:{Fireworks:{Explosions:[{Type:1,Flicker:1,Colors:[I;16775936,14602026,16775936,15790320],FadeColors:[I;15790320,14602026,16775936,15790320]}],Flight:1}}}}
                    summon firework_rocket -1 34.00 0.40 {LifeTime:8,FireworksItem:{id:firework_rocket,Count:1,tag:{Fireworks:{Explosions:[{Type:2,Flicker:1,Colors:[I;16775936,14602026,16775936,15790320],FadeColors:[I;15790320,14602026,16775936,15790320]}],Flight:1}}}}
                    summon firework_rocket 2.48 34.00 0.57 {LifeTime:8,FireworksItem:{id:firework_rocket,Count:1,tag:{Fireworks:{Explosions:[{Type:3,Flicker:1,Colors:[I;16775936,14602026,16775936,15790320],FadeColors:[I;15790320,14602026,16775936,15790320]}],Flight:1}}}}
                }
            }
        }
    }
}

dir timerhard{
    function timerstart{
        bossbar set minecraft:time style progress
        bossbar set minecraft:time max 15
        bossbar set minecraft:time value 15
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"15 seconds","color":"red"}]
        schedule function main:timerhard/14 2s
    }

    function 14{
        bossbar set minecraft:time value 14
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"14 seconds","color":"red"}]
        schedule function main:timerhard/13 1s
    }
    
    function 13{
        bossbar set minecraft:time value 13
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"13 seconds","color":"red"}]
        schedule function main:timerhard/12 1s
    }

    function 12{
        bossbar set minecraft:time value 12
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"12 seconds","color":"red"}]
        schedule function main:timerhard/11 1s
    }

    function 11{
        bossbar set minecraft:time value 11
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"11 seconds","color":"red"}]
        schedule function main:timerhard/10 1s
    }

    function 10{
        bossbar set minecraft:time value 10
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"10 seconds","color":"red"}]
        schedule function main:timerhard/9 1s
    }

    function 9{
        bossbar set minecraft:time value 9
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"9 seconds","color":"red"}]
        schedule function main:timerhard/8 1s
    }

    function 8{
        bossbar set minecraft:time value 8
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"8 seconds","color":"red"}]
        schedule function main:timerhard/7 1s        
    }

    function 7{
        bossbar set minecraft:time value 7
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"7 seconds","color":"red"}]
        schedule function main:timerhard/6 1s       
    }

    function 6{
        bossbar set minecraft:time value 6
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"6 seconds","color":"red"}]
        schedule function main:timerhard/5 1s        
    }

    function 5{
        bossbar set minecraft:time value 5
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"5 seconds","color":"red"}]
        schedule function main:timerhard/4 1s        
    }

    function 4{
        bossbar set minecraft:time value 4
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"4 seconds","color":"red"}]
        schedule function main:timerhard/3 1s       
    }

    function 3{
        bossbar set minecraft:time value 3
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"3 seconds","color":"red"}]
        playsound minecraft:block.note_block.bass master @a ~ ~ ~ 10 1 1
        execute if entity @a[tag=inround] run schedule function main:timerhard/2 1s        
    }

    function 2{
        bossbar set minecraft:time value 2
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"2 seconds","color":"red"}]
        playsound minecraft:block.note_block.bass master @a ~ ~ ~ 10 1 1
        execute if entity @a[tag=inround] run schedule function main:timerhard/1 1s        
    }

    function 1{
        bossbar set minecraft:time value 1
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"1 seconds","color":"red"}]
        playsound minecraft:block.note_block.bass master @a ~ ~ ~ 10 1 1
        execute if entity @a[tag=inround] run schedule function main:timerhard/timerfinish 1s        
    }

    function timerfinish{
        bossbar set minecraft:time value 0
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"0 seconds","color":"red"}]
        playsound minecraft:block.note_block.pling master @a[tag=inround] ~ ~ ~ 10 1 1
        setblock 8 3 2 minecraft:air
        fill 13 14 -1 3 6 9 air
        
        LOOP(150,i){
       execute if score $map mapselect matches 1 if score random build matches <%i+1%> run function main:rounds/<%i+1%>/clear
        }

        LOOP(150,i){
       execute if score $map mapselect matches 2 if score random build matches <%i+1%> run function main:duorounds/<%i+1%>/clear
        }
    }
}

dir timermed{
    function timerstart{
        bossbar set minecraft:time style progress
        bossbar set minecraft:time max 20
        bossbar set minecraft:time value 20
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"20 seconds","color":"red"}]
        schedule function main:timermed/19 2s
    }

    function 19{
        bossbar set minecraft:time value 19
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"19 seconds","color":"red"}]
        schedule function main:timermed/18 1s
    }

    function 18{
        bossbar set minecraft:time value 18
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"18 seconds","color":"red"}]
        schedule function main:timermed/17 1s
    }

    function 17{
        bossbar set minecraft:time value 17
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"17 seconds","color":"red"}]
        schedule function main:timermed/16 1s
    }

    function 16{
        bossbar set minecraft:time value 16
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"16 seconds","color":"red"}]
        schedule function main:timermed/15 1s
    }

    function 15{
        bossbar set minecraft:time value 15
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"15 seconds","color":"red"}]
        schedule function main:timermed/14 1s
    }

    function 14{
        bossbar set minecraft:time value 14
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"14 seconds","color":"red"}]
        schedule function main:timermed/13 1s
    }
    
    function 13{
        bossbar set minecraft:time value 13
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"13 seconds","color":"red"}]
        schedule function main:timermed/12 1s
    }

    function 12{
        bossbar set minecraft:time value 12
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"12 seconds","color":"red"}]
        schedule function main:timermed/11 1s
    }

    function 11{
        bossbar set minecraft:time value 11
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"11 seconds","color":"red"}]
        schedule function main:timermed/10 1s
    }

    function 10{
        bossbar set minecraft:time value 10
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"10 seconds","color":"red"}]
        schedule function main:timermed/9 1s
    }

    function 9{
        bossbar set minecraft:time value 9
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"9 seconds","color":"red"}]
        schedule function main:timermed/8 1s
    }

    function 8{
        bossbar set minecraft:time value 8
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"8 seconds","color":"red"}]
        schedule function main:timermed/7 1s        
    }

    function 7{
        bossbar set minecraft:time value 7
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"7 seconds","color":"red"}]
        schedule function main:timermed/6 1s       
    }

    function 6{
        bossbar set minecraft:time value 6
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"6 seconds","color":"red"}]
        schedule function main:timermed/5 1s        
    }

    function 5{
        bossbar set minecraft:time value 5
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"5 seconds","color":"red"}]
        schedule function main:timermed/4 1s        
    }

    function 4{
        bossbar set minecraft:time value 4
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"4 seconds","color":"red"}]
        schedule function main:timermed/3 1s       
    }

    function 3{
        bossbar set minecraft:time value 3
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"3 seconds","color":"red"}]
        playsound minecraft:block.note_block.bass master @a ~ ~ ~ 10 1 1
        execute if entity @a[tag=inround] run schedule function main:timermed/2 1s        
    }

    function 2{
        bossbar set minecraft:time value 2
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"2 seconds","color":"red"}]
        playsound minecraft:block.note_block.bass master @a ~ ~ ~ 10 1 1
        execute if entity @a[tag=inround] run schedule function main:timermed/1 1s        
    }

    function 1{
        bossbar set minecraft:time value 1
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"1 seconds","color":"red"}]
        playsound minecraft:block.note_block.bass master @a ~ ~ ~ 10 1 1
        execute if entity @a[tag=inround] run schedule function main:timermed/timerfinish 1s        
    }

    function timerfinish{
        bossbar set minecraft:time value 0
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"0 seconds","color":"red"}]
        playsound minecraft:block.note_block.pling master @a[tag=inround] ~ ~ ~ 10 1 1
        setblock 8 3 2 minecraft:air
        fill 13 14 -1 3 6 9 air
        
        LOOP(150,i){
       execute if score $map mapselect matches 1 if score random build matches <%i+1%> run function main:rounds/<%i+1%>/clear
        }

        LOOP(150,i){
       execute if score $map mapselect matches 2 if score random build matches <%i+1%> run function main:duorounds/<%i+1%>/clear
        }
    }
}

dir timereasy{
    function timerstart{
        bossbar set minecraft:time style progress
        bossbar set minecraft:time max 30
        bossbar set minecraft:time value 30
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"30 seconds","color":"red"}]
        schedule function main:timereasy/29 2s
    }
    
    function 29{
        bossbar set minecraft:time value 29
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"29 seconds","color":"yellow"}]
        schedule function main:timereasy/28 1s
    }

    function 28{
        bossbar set minecraft:time value 28
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"28 seconds","color":"yellow"}]
        schedule function main:timereasy/27 1s
    }

    function 27{
        bossbar set minecraft:time value 27
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"27 seconds","color":"yellow"}]
        schedule function main:timereasy/26 1s
    }

    function 26{
        bossbar set minecraft:time value 26
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"26 seconds","color":"yellow"}]
        schedule function main:timereasy/25 1s
    }

    function 25{
        bossbar set minecraft:time value 25
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"25 seconds","color":"yellow"}]
        schedule function main:timereasy/24 1s
    }

    function 24{
        bossbar set minecraft:time value 24
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"24 seconds","color":"yellow"}]
        schedule function main:timereasy/23 1s
    }

    function 23{
        bossbar set minecraft:time value 23
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"23 seconds","color":"yellow"}]
        schedule function main:timereasy/22 1s
    }

    function 22{
        bossbar set minecraft:time value 22
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"22 seconds","color":"yellow"}]
        schedule function main:timereasy/21 1s
    }

    function 21{
        bossbar set minecraft:time value 21
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"21 seconds","color":"yellow"}]
        schedule function main:timereasy/20 1s
    }


    function 20{
        bossbar set minecraft:time value 20
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"20 seconds","color":"red"}]
        schedule function main:timereasy/19 1s
    }

    function 19{
        bossbar set minecraft:time value 19
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"19 seconds","color":"red"}]
        schedule function main:timereasy/18 1s
    }

    function 18{
        bossbar set minecraft:time value 18
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"18 seconds","color":"red"}]
        schedule function main:timereasy/17 1s
    }

    function 17{
        bossbar set minecraft:time value 17
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"17 seconds","color":"red"}]
        schedule function main:timereasy/16 1s
    }

    function 16{
        bossbar set minecraft:time value 16
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"16 seconds","color":"red"}]
        schedule function main:timereasy/15 1s
    }

    function 15{
        bossbar set minecraft:time value 15
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"15 seconds","color":"red"}]
        schedule function main:timereasy/14 1s
    }

    function 14{
        bossbar set minecraft:time value 14
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"14 seconds","color":"red"}]
        schedule function main:timereasy/13 1s
    }
    
    function 13{
        bossbar set minecraft:time value 13
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"13 seconds","color":"red"}]
        schedule function main:timereasy/12 1s
    }

    function 12{
        bossbar set minecraft:time value 12
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"12 seconds","color":"red"}]
        schedule function main:timereasy/11 1s
    }

    function 11{
        bossbar set minecraft:time value 11
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"11 seconds","color":"red"}]
        schedule function main:timereasy/10 1s
    }

    function 10{
        bossbar set minecraft:time value 10
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"10 seconds","color":"red"}]
        schedule function main:timereasy/9 1s
    }

    function 9{
        bossbar set minecraft:time value 9
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"9 seconds","color":"red"}]
        schedule function main:timereasy/8 1s
    }

    function 8{
        bossbar set minecraft:time value 8
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"8 seconds","color":"red"}]
        schedule function main:timereasy/7 1s        
    }

    function 7{
        bossbar set minecraft:time value 7
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"7 seconds","color":"red"}]
        schedule function main:timereasy/6 1s       
    }

    function 6{
        bossbar set minecraft:time value 6
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"6 seconds","color":"red"}]
        schedule function main:timereasy/5 1s        
    }

    function 5{
        bossbar set minecraft:time value 5
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"5 seconds","color":"red"}]
        schedule function main:timereasy/4 1s        
    }

    function 4{
        bossbar set minecraft:time value 4
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"4 seconds","color":"red"}]
        schedule function main:timereasy/3 1s       
    }

    function 3{
        bossbar set minecraft:time value 3
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"3 seconds","color":"red"}]
        playsound minecraft:block.note_block.bass master @a ~ ~ ~ 10 1 1
        execute if entity @a[tag=inround] run schedule function main:timereasy/2 1s        
    }

    function 2{
        bossbar set minecraft:time value 2
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"2 seconds","color":"red"}]
        playsound minecraft:block.note_block.bass master @a ~ ~ ~ 10 1 1
        execute if entity @a[tag=inround] run schedule function main:timereasy/1 1s        
    }

    function 1{
        bossbar set minecraft:time value 1
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"1 seconds","color":"red"}]
        playsound minecraft:block.note_block.bass master @a ~ ~ ~ 10 1 1
        execute if entity @a[tag=inround] run schedule function main:timereasy/timerfinish 1s        
    }

    function timerfinish{
        bossbar set minecraft:time value 0
        bossbar set time name [{"text":"View Time Remaining: "},{"text":"0 seconds","color":"red"}]
        playsound minecraft:block.note_block.pling master @a[tag=inround] ~ ~ ~ 10 1 1
        setblock 8 3 2 minecraft:air
        fill 13 14 -1 3 6 9 air
        
        LOOP(150,i){
       execute if score $map mapselect matches 1 if score random build matches <%i+1%> run function main:rounds/<%i+1%>/clear
        }

        LOOP(150,i){
       execute if score $map mapselect matches 2 if score random build matches <%i+1%> run function main:duorounds/<%i+1%>/clear
        }
    }
}

dir timerbuildhard{
    function timerstart{
        bossbar set minecraft:time style progress
        bossbar set minecraft:time max 15
        bossbar set minecraft:time value 15
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"15 seconds","color":"yellow"}]
        schedule function main:timerbuildhard/14 2s
    }

    function 14{
        bossbar set minecraft:time value 14
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"14 seconds","color":"yellow"}]
        schedule function main:timerbuildhard/13 1s
    }

    function 13{
        bossbar set minecraft:time value 13
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"13 seconds","color":"yellow"}]
        schedule function main:timerbuildhard/12 1s
    }

    function 12{
        bossbar set minecraft:time value 12
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"12 seconds","color":"yellow"}]
        schedule function main:timerbuildhard/11 1s
    }

    function 11{
        bossbar set minecraft:time value 11
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"11 seconds","color":"yellow"}]
        schedule function main:timerbuildhard/10 1s
    }

    function 10{
        bossbar set minecraft:time value 10
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"10 seconds","color":"yellow"}]
        schedule function main:timerbuildhard/9 1s
    }

    function 9{
        bossbar set minecraft:time value 9
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"9 seconds","color":"yellow"}]
        schedule function main:timerbuildhard/8 1s
    }
    
    function 8{
        bossbar set minecraft:time value 8
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"8 seconds","color":"yellow"}]
        schedule function main:timerbuildhard/7 1s
    }

    function 7{
        bossbar set minecraft:time value 7
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"7 seconds","color":"yellow"}]
        schedule function main:timerbuildhard/6 1s
    }

    function 6{
        bossbar set minecraft:time value 6
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"6 seconds","color":"yellow"}]
        schedule function main:timerbuildhard/5 1s
    }

    function 5{
        bossbar set minecraft:time value 5
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"5 seconds","color":"yellow"}]
        playsound minecraft:block.note_block.bass master @a ~ ~ ~ 10 1 1
        schedule function main:timerbuildhard/4 1s
    }

    function 4{
        bossbar set minecraft:time value 4
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"4 seconds","color":"yellow"}]
        playsound minecraft:block.note_block.bass master @a ~ ~ ~ 10 1 1
        execute if entity @a[tag=inround] run schedule function main:timerbuildhard/3 1s
    }

    function 3{
        bossbar set minecraft:time value 3
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"3 seconds","color":"yellow"}]
        playsound minecraft:block.note_block.bass master @a ~ ~ ~ 10 1 1
        execute if entity @a[tag=inround] run schedule function main:timerbuildhard/2 1s
    }

    function 2{
        bossbar set minecraft:time value 2
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"2 seconds","color":"yellow"}]
        playsound minecraft:block.note_block.bass master @a ~ ~ ~ 10 1 1
        execute if entity @a[tag=inround] run schedule function main:timerbuildhard/1 1s
    }

    function 1{
        bossbar set minecraft:time value 1
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"1 second","color":"yellow"}]
        playsound minecraft:block.note_block.bass master @a ~ ~ ~ 10 1 1
        execute if entity @a[tag=inround] run schedule function main:timerbuildhard/timerfinish 1s
    }

    function timerfinish{
        bossbar set minecraft:time value 0
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"0 seconds","color":"yellow"}]
        playsound minecraft:block.note_block.pling master @a[tag=inround] ~ ~ ~ 10 1 1

        setblock 8 3 2 minecraft:air
        fill 13 14 -1 3 6 9 air

        execute if entity @a[team=build] run function main:fail/outoftime
    }
}

dir timerbuildmed{
    function timerstart{
        bossbar set minecraft:time style progress
        bossbar set minecraft:time max 20
        bossbar set minecraft:time value 20
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"20 seconds","color":"yellow"}]
        schedule function main:timerbuildmed/19 2s
    }

    function 19{
        bossbar set minecraft:time value 19
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"19 seconds","color":"yellow"}]
        schedule function main:timerbuildmed/18 1s
    }

    function 18{
        bossbar set minecraft:time value 18
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"18 seconds","color":"yellow"}]
        schedule function main:timerbuildmed/17 1s
    }

    function 17{
        bossbar set minecraft:time value 17
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"17 seconds","color":"yellow"}]
        schedule function main:timerbuildmed/16 1s
    }

    function 16{
        bossbar set minecraft:time value 16
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"16 seconds","color":"yellow"}]
        schedule function main:timerbuildmed/15 1s
    }

    function 15{
        bossbar set minecraft:time value 15
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"15 seconds","color":"yellow"}]
        schedule function main:timerbuildmed/14 1s
    }

    function 14{
        bossbar set minecraft:time value 14
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"14 seconds","color":"yellow"}]
        schedule function main:timerbuildmed/13 1s
    }

    function 13{
        bossbar set minecraft:time value 13
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"13 seconds","color":"yellow"}]
        schedule function main:timerbuildmed/12 1s
    }

    function 12{
        bossbar set minecraft:time value 12
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"12 seconds","color":"yellow"}]
        schedule function main:timerbuildmed/11 1s
    }

    function 11{
        bossbar set minecraft:time value 11
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"11 seconds","color":"yellow"}]
        schedule function main:timerbuildmed/10 1s
    }

    function 10{
        bossbar set minecraft:time value 10
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"10 seconds","color":"yellow"}]
        schedule function main:timerbuildmed/9 1s
    }

    function 9{
        bossbar set minecraft:time value 9
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"9 seconds","color":"yellow"}]
        schedule function main:timerbuildmed/8 1s
    }
    
    function 8{
        bossbar set minecraft:time value 8
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"8 seconds","color":"yellow"}]
        schedule function main:timerbuildmed/7 1s
    }

    function 7{
        bossbar set minecraft:time value 7
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"7 seconds","color":"yellow"}]
        schedule function main:timerbuildmed/6 1s
    }

    function 6{
        bossbar set minecraft:time value 6
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"6 seconds","color":"yellow"}]
        schedule function main:timerbuildmed/5 1s
    }

    function 5{
        bossbar set minecraft:time value 5
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"5 seconds","color":"yellow"}]
        playsound minecraft:block.note_block.bass master @a ~ ~ ~ 10 1 1
        schedule function main:timerbuildmed/4 1s
    }

    function 4{
        bossbar set minecraft:time value 4
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"4 seconds","color":"yellow"}]
        playsound minecraft:block.note_block.bass master @a ~ ~ ~ 10 1 1
        execute if entity @a[tag=inround] run schedule function main:timerbuildmed/3 1s
    }

    function 3{
        bossbar set minecraft:time value 3
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"3 seconds","color":"yellow"}]
        playsound minecraft:block.note_block.bass master @a ~ ~ ~ 10 1 1
        execute if entity @a[tag=inround] run schedule function main:timerbuildmed/2 1s
    }

    function 2{
        bossbar set minecraft:time value 2
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"2 seconds","color":"yellow"}]
        playsound minecraft:block.note_block.bass master @a ~ ~ ~ 10 1 1
        execute if entity @a[tag=inround] run schedule function main:timerbuildmed/1 1s
    }

    function 1{
        bossbar set minecraft:time value 1
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"1 second","color":"yellow"}]
        playsound minecraft:block.note_block.bass master @a ~ ~ ~ 10 1 1
        execute if entity @a[tag=inround] run schedule function main:timerbuildmed/timerfinish 1s
    }

    function timerfinish{
        bossbar set minecraft:time value 0
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"0 seconds","color":"yellow"}]
        playsound minecraft:block.note_block.pling master @a[tag=inround] ~ ~ ~ 10 1 1

        setblock 8 3 2 minecraft:air
        fill 13 14 -1 3 6 9 air

        execute if entity @a[team=build] run function main:fail/outoftime
    }
}

dir timerbuildeasy{
    function timerstart{
        bossbar set minecraft:time style progress
        bossbar set minecraft:time max 30
        bossbar set minecraft:time value 30
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"30 seconds","color":"yellow"}]
        schedule function main:timerbuildeasy/29 1s
    }
    
    function 29{
        bossbar set minecraft:time value 29
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"29 seconds","color":"yellow"}]
        schedule function main:timerbuildeasy/28 1s
    }

    function 28{
        bossbar set minecraft:time value 28
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"28 seconds","color":"yellow"}]
        schedule function main:timerbuildeasy/27 1s
    }

    function 27{
        bossbar set minecraft:time value 27
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"27 seconds","color":"yellow"}]
        schedule function main:timerbuildeasy/26 1s
    }

    function 26{
        bossbar set minecraft:time value 26
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"26 seconds","color":"yellow"}]
        schedule function main:timerbuildeasy/25 1s
    }

    function 25{
        bossbar set minecraft:time value 25
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"25 seconds","color":"yellow"}]
        schedule function main:timerbuildeasy/24 1s
    }

    function 24{
        bossbar set minecraft:time value 24
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"24 seconds","color":"yellow"}]
        schedule function main:timerbuildeasy/23 1s
    }

    function 23{
        bossbar set minecraft:time value 23
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"23 seconds","color":"yellow"}]
        schedule function main:timerbuildeasy/22 1s
    }

    function 22{
        bossbar set minecraft:time value 22
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"22 seconds","color":"yellow"}]
        schedule function main:timerbuildeasy/21 1s
    }

    function 21{
        bossbar set minecraft:time value 21
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"21 seconds","color":"yellow"}]
        schedule function main:timerbuildeasy/20 1s
    }

    function 20{
        bossbar set minecraft:time value 20
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"20 seconds","color":"yellow"}]
        schedule function main:timerbuildeasy/19 1s
    }

    function 19{
        bossbar set minecraft:time value 19
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"19 seconds","color":"yellow"}]
        schedule function main:timerbuildeasy/18 1s
    }

    function 18{
        bossbar set minecraft:time value 18
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"18 seconds","color":"yellow"}]
        schedule function main:timerbuildeasy/17 1s
    }

    function 17{
        bossbar set minecraft:time value 17
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"17 seconds","color":"yellow"}]
        schedule function main:timerbuildeasy/16 1s
    }

    function 16{
        bossbar set minecraft:time value 16
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"16 seconds","color":"yellow"}]
        schedule function main:timerbuildeasy/15 1s
    }

    function 15{
        bossbar set minecraft:time value 15
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"15 seconds","color":"yellow"}]
        schedule function main:timerbuildeasy/14 1s
    }

    function 14{
        bossbar set minecraft:time value 14
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"14 seconds","color":"yellow"}]
        schedule function main:timerbuildeasy/13 1s
    }

    function 13{
        bossbar set minecraft:time value 13
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"13 seconds","color":"yellow"}]
        schedule function main:timerbuildeasy/12 1s
    }

    function 12{
        bossbar set minecraft:time value 12
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"12 seconds","color":"yellow"}]
        schedule function main:timerbuildeasy/11 1s
    }

    function 11{
        bossbar set minecraft:time value 11
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"11 seconds","color":"yellow"}]
        schedule function main:timerbuildeasy/10 1s
    }

    function 10{
        bossbar set minecraft:time value 10
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"10 seconds","color":"yellow"}]
        schedule function main:timerbuildeasy/9 1s
    }

    function 9{
        bossbar set minecraft:time value 9
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"9 seconds","color":"yellow"}]
        schedule function main:timerbuildeasy/8 1s
    }
    
    function 8{
        bossbar set minecraft:time value 8
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"8 seconds","color":"yellow"}]
        schedule function main:timerbuildeasy/7 1s
    }

    function 7{
        bossbar set minecraft:time value 7
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"7 seconds","color":"yellow"}]
        schedule function main:timerbuildeasy/6 1s
    }

    function 6{
        bossbar set minecraft:time value 6
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"6 seconds","color":"yellow"}]
        schedule function main:timerbuildeasy/5 1s
    }

    function 5{
        bossbar set minecraft:time value 5
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"5 seconds","color":"yellow"}]
        playsound minecraft:block.note_block.bass master @a ~ ~ ~ 10 1 1
        schedule function main:timerbuildeasy/4 1s
    }

    function 4{
        bossbar set minecraft:time value 4
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"4 seconds","color":"yellow"}]
        playsound minecraft:block.note_block.bass master @a ~ ~ ~ 10 1 1
        execute if entity @a[tag=inround] run schedule function main:timerbuildeasy/3 1s
    }

    function 3{
        bossbar set minecraft:time value 3
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"3 seconds","color":"yellow"}]
        playsound minecraft:block.note_block.bass master @a ~ ~ ~ 10 1 1
        execute if entity @a[tag=inround] run schedule function main:timerbuildeasy/2 1s
    }

    function 2{
        bossbar set minecraft:time value 2
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"2 seconds","color":"yellow"}]
        playsound minecraft:block.note_block.bass master @a ~ ~ ~ 10 1 1
        execute if entity @a[tag=inround] run schedule function main:timerbuildeasy/1 1s
    }

    function 1{
        bossbar set minecraft:time value 1
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"1 second","color":"yellow"}]
        playsound minecraft:block.note_block.bass master @a ~ ~ ~ 10 1 1
        execute if entity @a[tag=inround] run schedule function main:timerbuildeasy/timerfinish 1s
    }

    function timerfinish{
        bossbar set minecraft:time value 0
        bossbar set time name [{"text":"Build Time Remaining: "},{"text":"0 seconds","color":"yellow"}]
        playsound minecraft:block.note_block.pling master @a[tag=inround] ~ ~ ~ 10 1 1

        setblock 8 3 2 minecraft:air
        fill 13 14 -1 3 6 9 air

        execute if entity @a[team=build] run function main:fail/outoftime
    }
}

dir rounds{
    LOOP(150,i){
        dir <%i+1%>{
        function clear{
            #clear#
            setblock 8 4 2 minecraft:structure_block
            data modify block 8 4 2 mode set value "LOAD"
            data modify block 8 4 2 name set value "minecraft:clear"
            data modify block 8 4 2 posX set value -5
            data modify block 8 4 2 posY set value 2
            data modify block 8 4 2 posZ set value -3
            kill @e[type=item]

            setblock 8 3 2 minecraft:redstone_block 

            schedule function main:redstone 1s

            kill @e[type=item]

            #load#
            setblock 8 16 14 minecraft:structure_block
            data modify block 8 16 14 mode set value "LOAD"
            data modify block 8 16 14 name set value "minecraft:build<%i+1%>"
            data modify block 8 16 14 posX set value -5
            data modify block 8 16 14 posY set value 2
            data modify block 8 16 14 posZ set value -3
            data modify block 8 16 14 mirror set value "LEFT_RIGHT"

            setblock 8 17 14 minecraft:redstone_block 

            schedule function main:redstone 1s

            #give#
            execute as @a[team=build] at @s run summon item ~ ~ ~ {PickupDelay:1,Tags:["tool"],Item:{id:"minecraft:diamond_pickaxe",Count:1b,tag:{Enchantments:[{id:"minecraft:efficiency",lvl:6s},{id:"minecraft:unbreaking",lvl:100s},{id:"minecraft:silk_touch",lvl:100s}]}}}
            execute as @a[team=build] at @s run function loot:get_items

            #timerstart#
            execute if score $difficulty ip matches 1 run function main:timerbuildhard/timerstart
            execute if score $difficulty ip matches 2 run function main:timerbuildmed/timerstart
            execute if score $difficulty ip matches 3 run function main:timerbuildeasy/timerstart
        }

        function complete{
            execute if entity @a[tag=inround] run particle minecraft:happy_villager 8 6 14 6 6 6 0.01 650 normal
            fill 3 6 17 13 11 11 air
            execute at @a run playsound minecraft:block.note_block.bell master @a[tag=inround] ~ ~ ~ 10 1 1
            team join ingame @a[tag=inround]
            clear @a[tag=inround]
            tp @a[tag=inround] -15.5 6.00 8.5 270 2
            scoreboard players add @a[tag=inround] score 1
            bossbar set minecraft:time visible false

            title @a[tag=inround] times 0 30 10
            title @a[tag=inround] subtitle {"text":"You Mirrored The Build!"}
            title @a[tag=inround] title {"text":"Congratulations!","color":"green"}

            scoreboard players add @a[tag=inround] wins 1


            tag @a[tag=inround] remove DoubleJumper
            tag @a[tag=inround] remove inround

            bossbar set minecraft:time style progress
            bossbar set minecraft:time max 10
            bossbar set minecraft:time value 10
            bossbar set time name [{"text":"View Time Remaining: "},{"text":"10 seconds","color":"red"}]

            function main:clearschedule
            execute store result score max id if entity @a[tag=ready]
            execute if score order id = max id run scoreboard players set order id 0
            scoreboard players add order id 1
            execute(if score $map mapselect matches 1 as @a[team=ingame] if score @s id = order id){
              function main:portalstart
              }else{
            scoreboard players add order id 1
            execute store result score max id if entity @a[tag=ready]
            execute if score order id = max id run scoreboard players set order id 0
            execute as @a[team=ingame] if score @s id = order id run function main:check
            }

            execute if score $map mapselect matches 2
        }

        function view{
            #load#
            setblock 8 4 2 minecraft:structure_block
            data modify block 8 4 2 mode set value "LOAD"
            data modify block 8 4 2 name set value "minecraft:build<%i+1%>"
            data modify block 8 4 2 posX set value -5
            data modify block 8 4 2 posY set value 2
            data modify block 8 4 2 posZ set value -3

            setblock 8 3 2 minecraft:redstone_block 

            execute at @a[tag=inround,distance=..20] run kill @e[type=item]

            #timer#
            bossbar set minecraft:time visible true
            execute if score $difficulty ip matches 1 run function main:timerhard/timerstart
            execute if score $difficulty ip matches 2 run function main:timermed/timerstart
            execute if score $difficulty ip matches 3 run function main:timereasy/timerstart
        }
    }
    }
}

function random{
    execute store result score random build run loot spawn ~ ~-60 ~ loot main:randomiser
    #tellraw @a {"score":{"objective":"build","name":"random"}}
}

function clearschedule{
    schedule clear main:portalstart
    schedule clear main:nextround
    schedule clear main:timermed/timerstart
    schedule clear main:timermed/20
    schedule clear main:timermed/19
    schedule clear main:timermed/18
    schedule clear main:timermed/17
    schedule clear main:timermed/16
    schedule clear main:timermed/15
    schedule clear main:timermed/14
    schedule clear main:timermed/13
    schedule clear main:timermed/12
    schedule clear main:timermed/11
    schedule clear main:timermed/10
    schedule clear main:timermed/9
    schedule clear main:timermed/8
    schedule clear main:timermed/7
    schedule clear main:timermed/6
    schedule clear main:timermed/5
    schedule clear main:timermed/4
    schedule clear main:timermed/3
    schedule clear main:timermed/2
    schedule clear main:timermed/1
    schedule clear main:timermed/timerfinish
    schedule clear main:timereasy/timerstart
    schedule clear main:timereasy/29
    schedule clear main:timereasy/28
    schedule clear main:timereasy/27
    schedule clear main:timereasy/26
    schedule clear main:timereasy/25
    schedule clear main:timereasy/24
    schedule clear main:timereasy/23
    schedule clear main:timereasy/22
    schedule clear main:timereasy/21
    schedule clear main:timereasy/20
    schedule clear main:timereasy/19
    schedule clear main:timereasy/18
    schedule clear main:timereasy/17
    schedule clear main:timereasy/16
    schedule clear main:timereasy/15
    schedule clear main:timereasy/14
    schedule clear main:timereasy/13
    schedule clear main:timereasy/12
    schedule clear main:timereasy/11
    schedule clear main:timereasy/10
    schedule clear main:timereasy/9
    schedule clear main:timereasy/8
    schedule clear main:timereasy/7
    schedule clear main:timereasy/6
    schedule clear main:timereasy/5
    schedule clear main:timereasy/4
    schedule clear main:timereasy/3
    schedule clear main:timereasy/2
    schedule clear main:timereasy/1
    schedule clear main:timereasy/timerfinish
    schedule clear main:timerhard/timerstart
    schedule clear main:timerhard/14
    schedule clear main:timerhard/13
    schedule clear main:timerhard/12
    schedule clear main:timerhard/11
    schedule clear main:timerhard/10
    schedule clear main:timerhard/9
    schedule clear main:timerhard/8
    schedule clear main:timerhard/7
    schedule clear main:timerhard/6
    schedule clear main:timerhard/5
    schedule clear main:timerhard/4
    schedule clear main:timerhard/3
    schedule clear main:timerhard/2
    schedule clear main:timerhard/1
    schedule clear main:timerhard/timerfinish
    schedule clear main:timerbuildmed/timerstart
    schedule clear main:timerbuildmed/20
    schedule clear main:timerbuildmed/19
    schedule clear main:timerbuildmed/18
    schedule clear main:timerbuildmed/17
    schedule clear main:timerbuildmed/16
    schedule clear main:timerbuildmed/15
    schedule clear main:timerbuildmed/14
    schedule clear main:timerbuildmed/13
    schedule clear main:timerbuildmed/12
    schedule clear main:timerbuildmed/11
    schedule clear main:timerbuildmed/10
    schedule clear main:timerbuildmed/9
    schedule clear main:timerbuildmed/8
    schedule clear main:timerbuildmed/7
    schedule clear main:timerbuildmed/6
    schedule clear main:timerbuildmed/5
    schedule clear main:timerbuildmed/4
    schedule clear main:timerbuildmed/3
    schedule clear main:timerbuildmed/2
    schedule clear main:timerbuildmed/1
    schedule clear main:timerbuildmed/timerfinish
    schedule clear main:timerbuildhard/timerstart
    schedule clear main:timerbuildhard/14
    schedule clear main:timerbuildhard/13
    schedule clear main:timerbuildhard/12
    schedule clear main:timerbuildhard/11
    schedule clear main:timerbuildhard/10
    schedule clear main:timerbuildhard/9
    schedule clear main:timerbuildhard/8
    schedule clear main:timerbuildhard/7
    schedule clear main:timerbuildhard/6
    schedule clear main:timerbuildhard/5
    schedule clear main:timerbuildhard/4
    schedule clear main:timerbuildhard/3
    schedule clear main:timerbuildhard/2
    schedule clear main:timerbuildhard/1
    schedule clear main:timerbuildhard/timerfinish
    schedule clear main:timerbuildeasy/timerstart
    schedule clear main:timerbuildeasy/29
    schedule clear main:timerbuildeasy/28
    schedule clear main:timerbuildeasy/27
    schedule clear main:timerbuildeasy/26
    schedule clear main:timerbuildeasy/25
    schedule clear main:timerbuildeasy/24
    schedule clear main:timerbuildeasy/23
    schedule clear main:timerbuildeasy/22
    schedule clear main:timerbuildeasy/21
    schedule clear main:timerbuildeasy/20
    schedule clear main:timerbuildeasy/19
    schedule clear main:timerbuildeasy/18
    schedule clear main:timerbuildeasy/17
    schedule clear main:timerbuildeasy/16
    schedule clear main:timerbuildeasy/15
    schedule clear main:timerbuildeasy/14
    schedule clear main:timerbuildeasy/13
    schedule clear main:timerbuildeasy/12
    schedule clear main:timerbuildeasy/11
    schedule clear main:timerbuildeasy/10
    schedule clear main:timerbuildeasy/9
    schedule clear main:timerbuildeasy/8
    schedule clear main:timerbuildeasy/7
    schedule clear main:timerbuildeasy/6
    schedule clear main:timerbuildeasy/5
    schedule clear main:timerbuildeasy/4
    schedule clear main:timerbuildeasy/3
    schedule clear main:timerbuildeasy/2
    schedule clear main:timerbuildeasy/1
    schedule clear main:timerbuildeasy/timerfinish
    schedule clear main:fail/outoftime
}

function give_id{
    scoreboard players add temp id 1
    scoreboard players operation @s id = temp id

}

function check{
            execute(as @a[team=ingame] if score @s id = order id){
              function main:portalstart
              }else{
            scoreboard players add order id 1
            execute store result score max id if entity @a[tag=ready]
            execute if score order id = max id run scoreboard players set order id 0
            execute as @a[team=ingame] if score @s id = order id run function main:check
          }
}

function addpoint{
    execute if score $progress ip matches 0 run{
        scoreboard players add $max points 1
        playsound minecraft:block.note_block.bell master @a[team=lobby] ~ ~ ~ 2 1 1
        }
    execute if score $progress ip matches 1 run tellraw @s {"text":"Action Denied, Game In Progress!","color":"red"}
} 

function subpoint{
        execute if score $progress ip matches 0 run{
        scoreboard players remove $max points 1
        playsound minecraft:block.note_block.bass master @a[team=lobby] ~ ~ ~ 2 1 1
        }
    execute if score $progress ip matches 1 run tellraw @s {"text":"Action Denied, Game In Progress!","color":"red"}
} 

function complete{
            execute if entity @a[tag=inround] run particle minecraft:happy_villager 8 6 14 6 6 6 0.01 650 normal
            fill 3 6 17 13 11 11 air
            execute at @a run playsound minecraft:block.note_block.bell master @a[tag=inround] ~ ~ ~ 10 1 1
            team join ingame @a[tag=inround]
            clear @a[tag=inround]
            tp @a[tag=inround] -15.5 6.00 8.5 270 2
            scoreboard players add @a[tag=inround] score 1
            bossbar set minecraft:time visible false

            title @a[tag=inround] times 0 30 10
            title @a[tag=inround] subtitle {"text":"You Mirrored The Build!"}
            title @a[tag=inround] title {"text":"Congratulations!","color":"green"}

            scoreboard players add @a[tag=inround] wins 1




            tag @a[tag=inround] remove inround
            bossbar set minecraft:time style progress
            bossbar set minecraft:time max 20
            bossbar set minecraft:time value 20

            function main:clearschedule
            execute store result score max id if entity @a[tag=ready]
            execute if score order id = max id run scoreboard players set order id 0
            scoreboard players add order id 1
            execute(as @a[team=ingame] if score @s id = order id){
              function main:portalstart
              }else{
            scoreboard players add order id 1
            execute store result score max id if entity @a[tag=ready]
            execute if score order id = max id run scoreboard players set order id 0
            execute as @a[team=ingame] if score @s id = order id run function main:check
          }

        }

function adddiff{
    execute if score $progress ip matches 0 run{
        scoreboard players add $difficulty ip 1
        playsound minecraft:block.note_block.bit master @a[team=lobby] ~ ~ ~ 2 1 1
        }
    execute if score $progress ip matches 1 run tellraw @s {"text":"Action Denied, Game In Progress!","color":"red"}
} 

function subdiff{
        execute if score $progress ip matches 0 run{
        scoreboard players remove $difficulty ip 1
        playsound minecraft:block.note_block.bit master @a[team=lobby] ~ ~ ~ 2 1 1
        }
    execute if score $progress ip matches 1 run tellraw @s {"text":"Action Denied, Game In Progress!","color":"red"}
} 

function model{
    execute if score $progress ip matches 0 if score $players PlayerCount matches 1.. run{
        scoreboard players remove $map mapselect 1
        playsound minecraft:block.note_block.bit master @a[team=lobby] ~ ~ ~ 2 1 1
        }
    execute if score $progress ip matches 1 run tellraw @s {"text":"Action Denied, Game In Progress!","color":"red"}
    execute if score $players PlayerCount matches ..1 run tellraw @s {"text":"Action Denied, Gamemode locked due to playing solo.","color":"red"}
} 

function moder{
        execute if score $progress ip matches 0 if score $players PlayerCount matches 1.. run{
        scoreboard players add $map mapselect 1
        playsound minecraft:block.note_block.bit master @a[team=lobby] ~ ~ ~ 2 1 1
        }
    execute if score $progress ip matches 1 run tellraw @s {"text":"Action Denied, Game In Progress!","color":"red"}
    execute if score $players PlayerCount matches ..1 run tellraw @s {"text":"Action Denied, Gamemode locked due to playing solo.","color":"red"}
} 

function setarena{
    execute if score $map mapselect matches 1 run{
            setblock 8 0 8 minecraft:structure_block
            data modify block 8 0 8 mode set value "LOAD"
            data modify block 8 0 8 name set value "minecraft:empty2"
            data modify block 8 0 8 posX set value -14
            data modify block 8 0 8 posY set value 3
            data modify block 8 0 8 posZ set value -10
            setblock 9 0 8 minecraft:redstone_block
            setblock 9 0 8 minecraft:stone

            setblock 8 0 8 minecraft:structure_block
            data modify block 8 0 8 mode set value "LOAD"
            data modify block 8 0 8 name set value "minecraft:empty"
            data modify block 8 0 8 posX set value -7
            data modify block 8 0 8 posY set value 3
            data modify block 8 0 8 posZ set value -11
            setblock 9 0 8 minecraft:redstone_block
            setblock 9 0 8 minecraft:stone

            setblock 8 0 8 minecraft:structure_block
            data modify block 8 0 8 mode set value "LOAD"
            data modify block 8 0 8 name set value "minecraft:solo"
            data modify block 8 0 8 posX set value -7
            data modify block 8 0 8 posY set value 3
            data modify block 8 0 8 posZ set value -11
            setblock 9 0 8 minecraft:redstone_block
            setblock 9 0 8 minecraft:stone
            
    }
    execute if score $map mapselect matches 2 run{
            setblock 8 0 8 minecraft:structure_block
            data modify block 8 0 8 mode set value "LOAD"
            data modify block 8 0 8 name set value "minecraft:empty"
            data modify block 8 0 8 posX set value -7
            data modify block 8 0 8 posY set value 3
            data modify block 8 0 8 posZ set value -11
            setblock 9 0 8 minecraft:redstone_block
            setblock 9 0 8 minecraft:stone

            setblock 8 0 8 minecraft:structure_block
            data modify block 8 0 8 mode set value "LOAD"
            data modify block 8 0 8 name set value "minecraft:empty2"
            data modify block 8 0 8 posX set value -14
            data modify block 8 0 8 posY set value 3
            data modify block 8 0 8 posZ set value -10
            setblock 9 0 8 minecraft:redstone_block
            setblock 9 0 8 minecraft:stone

            setblock 8 0 8 minecraft:structure_block
            data modify block 8 0 8 mode set value "LOAD"
            data modify block 8 0 8 name set value "minecraft:duo"
            data modify block 8 0 8 posX set value -14
            data modify block 8 0 8 posY set value 3
            data modify block 8 0 8 posZ set value -10
            setblock 9 0 8 minecraft:redstone_block
            setblock 9 0 8 minecraft:stone
            
    }
}

dir duorounds{
    LOOP(150,i){
        dir <%i+1%>{
            function clear{
                #clear#
                setblock 0 4 2 minecraft:structure_block
                data modify block 0 4 2 mode set value "LOAD"
                data modify block 0 4 2 name set value "minecraft:clear"
                data modify block 0 4 2 posX set value -5
                data modify block 0 4 2 posY set value 2
                data modify block 0 4 2 posZ set value -3
                setblock 0 3 2 minecraft:redstone_block 
                setblock 0 3 2 minecraft:stone

                setblock 16 4 2 minecraft:structure_block
                data modify block 16 4 2 mode set value "LOAD"
                data modify block 16 4 2 name set value "minecraft:clear"
                data modify block 16 4 2 posX set value -5
                data modify block 16 4 2 posY set value 2
                data modify block 16 4 2 posZ set value -3
                setblock 16 3 2 minecraft:redstone_block 
                setblock 16 3 2 minecraft:stone
                kill @e[type=item]

                #load#
                setblock 8 16 14 minecraft:structure_block
                data modify block 8 16 14 mode set value "LOAD"
                data modify block 8 16 14 name set value "minecraft:build<%i+1%>"
                data modify block 8 16 14 posX set value -5
                data modify block 8 16 14 posY set value 2
                data modify block 8 16 14 posZ set value -3
                data modify block 8 16 14 mirror set value "LEFT_RIGHT"
                setblock 8 17 14 minecraft:redstone_block 
                setblock 8 17 14 minecraft:stone


                #give#
                execute as @a[team=build] at @s run summon item ~ ~ ~ {PickupDelay:1,Tags:["tool"],Item:{id:"minecraft:diamond_pickaxe",Count:1b,tag:{Enchantments:[{id:"minecraft:efficiency",lvl:6s},{id:"minecraft:unbreaking",lvl:100s},{id:"minecraft:silk_touch",lvl:100s}]}}}
                execute as @a[team=build] at @s run function loot:get_items

                #timerstart#
                execute if score $difficulty ip matches 1 run function main:timerbuildhard/timerstart
                execute if score $difficulty ip matches 2 run function main:timerbuildmed/timerstart
                execute if score $difficulty ip matches 3 run function main:timerbuildeasy/timerstart
            }
        

            function view{
                #load#
                setblock 0 4 2 minecraft:structure_block
                data modify block 0 4 2 mode set value "LOAD"
                data modify block 0 4 2 name set value "minecraft:build<%i+1%>"
                data modify block 0 4 2 posX set value -5
                data modify block 0 4 2 posY set value 2
                data modify block 0 4 2 posZ set value -3
                setblock 0 3 2 minecraft:redstone_block 
                setblock 0 3 2 minecraft:stone



                setblock 16 4 2 minecraft:structure_block
                data modify block 16 4 2 mode set value "LOAD"
                data modify block 16 4 2 name set value "minecraft:build<%i+1%>"
                data modify block 16 4 2 posX set value -5
                data modify block 16 4 2 posY set value 2
                data modify block 16 4 2 posZ set value -3
                setblock 16 3 2 minecraft:redstone_block 
                setblock 16 3 2 minecraft:stone
                
                execute at @a[tag=inround,distance=..20] run kill @e[type=item]

                #timer#
                bossbar set minecraft:time visible true
                execute if score $difficulty ip matches 1 run function main:timerhard/timerstart
                execute if score $difficulty ip matches 2 run function main:timermed/timerstart
                execute if score $difficulty ip matches 3 run function main:timereasy/timerstart
            }
        }
    }
}

function stone{
    setblock 9 0 8 minecraft:stone
}

function leftcomplete{
                execute if entity @a[tag=inround] run particle minecraft:happy_villager 8 6 14 6 6 6 0.01 650 normal
                setblock 8 0 8 minecraft:structure_block
                data modify block 8 0 8 mode set value "LOAD"
                data modify block 8 0 8 name set value "minecraft:duo"
                data modify block 8 0 8 posX set value -14
                data modify block 8 0 8 posY set value 3
                data modify block 8 0 8 posZ set value -10
                setblock 9 0 8 minecraft:redstone_block
                setblock 9 0 8 minecraft:stone
                execute at @a run playsound minecraft:block.note_block.bell master @a[tag=ingame] ~ ~ ~ 10 1 1
                team join ingame @a[tag=inround]
                clear @a[tag=inround]
                tp @a[tag=inround] -15.5 6.00 8.5 270 2
                scoreboard players add @a[tag=inround] score 1
                bossbar set minecraft:time visible false

                title @a[tag=ingame] times 0 30 10
                title @a[tag=ingame] subtitle [{"selector":"@s","color":"yellow"},{"text":" Mirrored The Build!"}]
                title @a[tag=ingame] title {"text":"Congratulations!","color":"green"}

                scoreboard players add @a[tag=sep,scores={id=2}] wins 1
                scoreboard players set @a id 0


                tag @a[tag=inround] remove sep
                tag @a[tag=inround] remove inround

                bossbar set minecraft:time style progress
                bossbar set minecraft:time max 10
                bossbar set minecraft:time value 10
                bossbar set time name [{"text":"View Time Remaining: "},{"text":"10 seconds","color":"red"}]

                function main:clearschedule
                function main:duoportalstart
            }
function rightcomplete{
                execute if entity @a[tag=inround] run particle minecraft:happy_villager 8 6 14 6 6 6 0.01 650 normal
                setblock 8 0 8 minecraft:structure_block
                data modify block 8 0 8 mode set value "LOAD"
                data modify block 8 0 8 name set value "minecraft:duo"
                data modify block 8 0 8 posX set value -14
                data modify block 8 0 8 posY set value 3
                data modify block 8 0 8 posZ set value -10
                setblock 9 0 8 minecraft:redstone_block
                setblock 9 0 8 minecraft:stone
                execute at @a run playsound minecraft:block.note_block.bell master @a[tag=inround] ~ ~ ~ 10 1 1
                team join ingame @a[tag=inround]
                clear @a[tag=inround]
                tp @a[tag=inround] -15.5 6.00 8.5 270 2
                scoreboard players add @a[tag=inround] score 1
                bossbar set minecraft:time visible false

                title @a[tag=ingame] times 0 30 10
                title @a[tag=ingame] subtitle [{"selector":"@s","color":"yellow"},{"text":" Mirrored The Build!"}]
                title @a[tag=ingame] title {"text":"Congratulations!","color":"green"}

                scoreboard players add @a[tag=sep,scores={id=3}] wins 1
                scoreboard players set @a id 0


                tag @a[tag=inround] remove sep
                tag @a[tag=inround] remove inround

                bossbar set minecraft:time style progress
                bossbar set minecraft:time max 10
                bossbar set minecraft:time value 10
                bossbar set time name [{"text":"View Time Remaining: "},{"text":"10 seconds","color":"red"}]

                function main:clearschedule
                function main:duoportalstart
            }