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

execute as @a[tag=start_parkour] at @s unless block ~ ~-0.1 ~ #f:parkour run function f:lobby/parkour/reset

#Score
execute at @e[tag=parkour_indicator] if entity @p[distance=..0.8,tag=start_parkour] run tag @s[scores={tick=0}] add next_stage

#Spawn Blocks
execute if entity @s[tag=next_stage] run function f:lobby/parkour/next_stage

scoreboard players add @s[scores={tick=1..}] tick 1
tag @e[tag=pumpkin2] remove parkour
execute if score @s tick matches 7 run tag @e[tag=spin] add spin2
execute as @e[tag=spin2] at @s run tp @s ~ ~ ~ ~10 ~
execute at @e[tag=spin2] run particle minecraft:cloud ~ ~1 ~ 0 0.2 0 0 1

#End
execute if score @s time matches 24 run tag @p[tag=start_parkour] add parkour_winner
execute if score @s time matches 24 as @p[tag=parkour_winner] at @s run playsound minecraft:ui.toast.challenge_complete master @s ~ ~ ~ 100 0.5
execute if score @s time matches 24 run effect give @p[tag=parkour_winner] levitation 10 2 true
execute if score @s time matches 24 as @p[tag=start_parkour] run function f:lobby/parkour/reset

#Place Blocks
execute if score @s tick matches 7 at @e[tag=parkour,tag=hay] run setblock ~ ~ ~ hay_block
execute if score @s tick matches 7 at @e[tag=parkour,tag=pumpkin] run setblock ~ ~ ~ carved_pumpkin
execute if score @s tick matches 7 at @e[tag=parkour,tag=fence] run setblock ~ ~ ~ spruce_fence
execute if score @s tick matches 7 at @e[tag=parkour,tag=pumpkin_lit] run setblock ~ ~ ~ jack_o_lantern
execute if score @s tick matches 7 at @e[tag=pumpkin2] run setblock ~ ~2 ~ creeper_head

execute if score @s tick matches 7 run kill @e[tag=parkour]
execute if score @s tick matches 7 run scoreboard players set @s tick 0