#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
#
#    This function has been created by Skilendarz Group.
#             https://skilendarz.com
#
#      GIVE MAP MAKERS THE CREDIT THEY DESERVE!
#             COPYING IS PROHIBITED!
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#

#Game/lobby
scoreboard players add @a logout 0
execute as @a[scores={logout=0..}] run function f:lobby/join
execute if entity @p[x=317,y=105,z=-320,distance=..140] run function f:lobby/main
execute if score $core main matches 1 run function f:game/main

#Missile
execute if block 213 141 -410 minecraft:lever[powered=true] run function f:lobby/tnt
tp @a[x=193,y=138,z=-399,distance=..2] 318 117 -352 0 -90
execute if entity @p[distance=..60,x=202,y=146,z=-406] run function f:lobby/missile
execute if score missile time matches 0 run time set 17000

#Effects
effect give @a minecraft:saturation 1000000 250 true
effect give @a minecraft:resistance 1000000 250 true
effect give @a[team=lobby] minecraft:weakness 2 250 true
effect give @a[team=lobby] speed 1 1 true
effect give @a[x=269,y=106,z=-319,distance=..20] minecraft:weakness 2 250 true
effect give @a[x=269,y=106,z=-319,distance=..20] speed 1 1 true

#Clear Items
execute as @a store result score @s clear_item run clear @s minecraft:iron_pickaxe 0
clear @a[scores={clear_item=2..}] minecraft:iron_pickaxe 64

execute as @a store result score @s clear_item run clear @s minecraft:carrot_on_a_stick{Limit:1} 0
clear @a[scores={clear_item=2..}] minecraft:carrot_on_a_stick{Limit:1} 64

execute as @a store result score @s clear_item run clear @s minecraft:compass 0
clear @a[scores={clear_item=2..}] minecraft:compass 64

execute as @a store result score @s clear_item run clear @s minecraft:feather 0
clear @a[scores={clear_item=2..}] minecraft:feather 64

execute as @a store result score @s clear_item run clear @s minecraft:snowball 0
clear @a[scores={clear_item=2..}] minecraft:snowball 64

#Other
team join lobby @a[x=317,y=105,z=-320,distance=..20,team=!lobby]
execute as @e[type=item,tag=!itemwin] run data merge entity @s {PickupDelay:0}
execute as @e[type=minecraft:chicken] run data merge entity @s {Age:-1000000}

execute as @a[team=lobby,x=205,y=143,z=-409,distance=25..] at @s positioned ~ 145 ~ as @s[distance=..5] run effect give @s jump_boost 1 253 true

execute as @a[scores={sleep=1..}] at @s run tp @s ~ ~0.5 ~
scoreboard players set @a[scores={sleep=1..}] sleep 0

gamemode adventure @a[gamemode=survival]
spawnpoint @a 365 129 -450
scoreboard players set @a[x=361,y=129,z=-454,dx=8,dy=100,dz=8] logout 0

#Spectator
gamemode spectator @a[team=spec,gamemode=!spectator]
execute as @a[team=spec] at @s unless block ~ 90 ~ emerald_ore run function f:spec-tp
execute as @a[team=spec] at @s positioned ~ 110 ~ as @s[distance=..10] run function f:spec-tp
execute as @a[team=spec] at @s positioned ~ 185 ~ as @s[distance=..10] run function f:spec-tp
effect give @a[team=spec] minecraft:glowing 1 1 true
effect give @a[team=spec] minecraft:night_vision 11 1 true
