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

playsound minecraft:item.chorus_fruit.teleport master @s[scores={kill-timer=50}] ~ ~ ~ 300 2
gamemode adventure @s[scores={kill-timer=50..}]
clear @s
effect clear @s minecraft:speed
effect clear @s minecraft:slowness
effect clear @s minecraft:jump_boost
effect clear @s minecraft:night_vision
effect give @s invisibility 1 0 true
effect give @s minecraft:weakness 1 250 true

#score
scoreboard players remove @s[scores={respawn_cooldown=1..}] respawn_cooldown 1

execute if entity @s[x=24.19,y=247,z=84.5,distance=..0.3,scores={respawn_cooldown=0}] run scoreboard players add @s y_respawn 1
execute if entity @s[x=24.5,y=247,z=84.81,distance=..0.3,scores={respawn_cooldown=0}] run scoreboard players remove @s x_respawn 1
execute if entity @s[x=24.81,y=247,z=84.5,distance=..0.3,scores={respawn_cooldown=0}] run scoreboard players remove @s y_respawn 1
execute if entity @s[x=24.5,y=247,z=84.19,distance=..0.3,scores={respawn_cooldown=0}] run scoreboard players add @s x_respawn 1
tag @s[x=24.5,y=247.51,z=84.5,distance=..0.5] add jump

execute unless entity @s[x=24.5,y=247,z=84.5,distance=..0.01] run playsound minecraft:ui.button.click master @s[scores={respawn_cooldown=0}] ~ ~ ~ 0.5
execute unless entity @s[x=24.5,y=247,z=84.5,distance=..0.01] run scoreboard players set @s respawn_cooldown 5
execute unless entity @s[x=24.5,y=247,z=84.5,distance=..0.01] run tp @s 24 247 84 90 90
execute unless entity @s[x_rotation=90,y_rotation=90] run tp @s ~ ~ ~ 90 90
tp @s[scores={respawn_cooldown=1..}] 24.5 247.0 84.5 90 90

#align
scoreboard players add @a x_respawn 0
scoreboard players add @a y_respawn 0
execute if score @s x_respawn matches -2 if score @s y_respawn matches 1 run scoreboard players set @s align 1
execute if score @s x_respawn matches -2 if score @s y_respawn matches -1 run scoreboard players set @s align 1
scoreboard players set @s[scores={align=1}] x_respawn -1
scoreboard players set @s[scores={align=1}] y_respawn 0

execute if score @s x_respawn matches -1 if score @s y_respawn matches 2 run scoreboard players set @s align 2
execute if score @s x_respawn matches 1 if score @s y_respawn matches 2 run scoreboard players set @s align 2
scoreboard players set @s[scores={align=2}] x_respawn 0
scoreboard players set @s[scores={align=2}] y_respawn 1

execute if score @s x_respawn matches 2 if score @s y_respawn matches 1 run scoreboard players set @s align 3
execute if score @s x_respawn matches 2 if score @s y_respawn matches -1 run scoreboard players set @s align 3
scoreboard players set @s[scores={align=3}] x_respawn 1
scoreboard players set @s[scores={align=3}] y_respawn 0

execute if score @s x_respawn matches 1 if score @s y_respawn matches -2 run scoreboard players set @s align 4
scoreboard players set @s[scores={align=4}] x_respawn 0
scoreboard players set @s[scores={align=4}] y_respawn -1
scoreboard players set @s align 0

#limitation
execute if score @s x_respawn matches ..-2 run scoreboard players set @s x_respawn -1
execute if score @s x_respawn matches 2.. run scoreboard players set @s x_respawn 1
execute if score @s y_respawn matches ..-2 run scoreboard players set @s y_respawn -1
execute if score @s y_respawn matches 2.. run scoreboard players set @s y_respawn 1

#select spawnpoint
execute if score $game_type main matches 2 run tag @e[tag=spawnpoint,limit=1,sort=random] add selected_spawnpoin
execute if score @s x_respawn matches -1 if score @s y_respawn matches 1 run tag @e[tag=spawnpoint1] add selected_spawnpoin
execute if score @s x_respawn matches 0 if score @s y_respawn matches 1 run tag @e[tag=spawnpoint2] add selected_spawnpoin
execute if score @s x_respawn matches 1 if score @s y_respawn matches 1 run tag @e[tag=spawnpoint3] add selected_spawnpoin
execute if score @s x_respawn matches -1 if score @s y_respawn matches 0 run tag @e[tag=spawnpoint4] add selected_spawnpoin
execute if score @s x_respawn matches 0 if score @s y_respawn matches 0 run tag @e[tag=spawnpoint5] add selected_spawnpoin
execute if score @s x_respawn matches 1 if score @s y_respawn matches 0 run tag @e[tag=spawnpoint6] add selected_spawnpoin
execute if score @s x_respawn matches -1 if score @s y_respawn matches -1 run tag @e[tag=spawnpoint7] add selected_spawnpoin
execute if score @s x_respawn matches 0 if score @s y_respawn matches -1 run tag @e[tag=spawnpoint8] add selected_spawnpoin
execute if score @s x_respawn matches 1 if score @s y_respawn matches -1 run tag @e[tag=spawnpoint9] add selected_spawnpoin
execute at @e[tag=selected_spawnpoin] run particle minecraft:dust 0 1 0 1 ~ ~1.5 ~ 0 0 0 0 1 normal @s

#skip
execute if score $game_type main matches 2..3 run tag @e[tag=selected_spawnpoin] remove selected_spawnpoin
execute if score $game_type main matches 2 run tag @e[tag=spawnpoint,limit=1,sort=random] add selected_spawnpoin
execute if score $game_type main matches 2..3 run tag @s add jump

#hide and seek
execute if score $game_type main matches 3 if score timer click matches 1 run tag @s remove player
execute if score $game_type main matches 3 if score timer click matches 1 run tp @s 21.5 145.0 -35.0 -90 0
execute if score $game_type main matches 3 unless score timer click matches 1 run tp @s 29 141 81 0 0

execute if score $game_type main matches 3 if score timer time matches 1.. run title @s title {"translate":"game.found.you","color":"red"}
execute if score $game_type main matches 3 if score timer time matches 1.. run title @s subtitle ["",{"translate":"game.you.are","color":"gray"},{"translate":"score.seeker","color":"dark_purple","bold":true}]
execute if score $game_type main matches 3 if score timer time matches 1.. run tellraw @s ["",{"text":"\n > ","color":"gold","bold":true},{"translate":"game.remember","color":"red","bold":true},{"translate":"game.remember.seeker","color":"gray"},{"text":"\n"}]

#tp player
execute if entity @s[tag=jump] run function f:game/kill/spawn

#end
tag @e[tag=selected_spawnpoin] remove selected_spawnpoin
