#checking spawns
tellraw @s {"text":"Checking spawn markers...","color":"dark_green"}
$execute unless entity @e[type=marker,tag=blue_spawn,scores={map_id=$(map_id)}] run return run tellraw @s {"text":"Missing blue_spawn for map $(map_id)!","color":"red"}
$execute unless entity @e[type=marker,tag=red_spawn,scores={map_id=$(map_id)}] run return run tellraw @s {"text":"Missing red_spawn for map $(map_id)!","color":"red"}

#checking flags
tellraw @s {"text":"Checking flag markers...","color":"dark_green"}
$execute unless entity @e[type=marker,tag=green_flag_location,scores={map_id=$(map_id)}] run return run tellraw @s {"text":"Missing green_flag_location for map $(map_id)!","color":"red"}
$execute unless entity @e[type=marker,tag=light_purple_flag_location,scores={map_id=$(map_id)}] run return run tellraw @s {"text":"Missing light_purple_flag_location for map $(map_id)!","color":"red"}
$execute unless entity @e[type=marker,tag=aqua_flag_location,scores={map_id=$(map_id)}] run return run tellraw @s {"text":"Missing aqua_flag_location for map $(map_id)!","color":"red"}
$execute unless entity @e[type=marker,tag=yellow_flag_location,scores={map_id=$(map_id)}] run return run tellraw @s {"text":"Missing yellow_flag_location for map $(map_id)!","color":"red"}

#checking flag dropoff
tellraw @s {"text":"Checking flag dropoff markers...","color":"dark_green"}
$execute unless entity @e[type=marker,tag=blue_flag_dropoff,scores={map_id=$(map_id)}] run return run tellraw @s {"text":"Missing blue_flag_dropoff for map $(map_id)!","color":"red"}
$execute unless entity @e[type=marker,tag=red_flag_dropoff,scores={map_id=$(map_id)}] run return run tellraw @s {"text":"Missing red_flag_dropoff for map $(map_id)!","color":"red"}

#checking death plane
tellraw @s {"text":"Checking death plane marker...","color":"dark_green"}
$execute unless entity @e[type=marker,tag=death_plane,scores={map_id=$(map_id)}] run return run tellraw @s {"text":"Missing death_plane for map $(map_id)!","color":"red"}

#checking lobby
tellraw @s {"text":"Checking lobby marker...","color":"dark_green"}
$execute unless entity @e[type=marker,tag=map_lobby,scores={map_id=$(map_id)}] run return run tellraw @s {"text":"Missing map_lobby for map $(map_id)!","color":"red"}
$execute if entity @e[type=marker,tag=map_lobby,scores={map_id=$(map_id)},tag=!not_active] run return run tellraw @s {"bold":true,"click_event":{"action":"suggest_command","command":"/function pctf:create_game_object/map/destroy {map_id: \"$(map_id)\"}"},"color":"dark_red","hoverEvent":{"action":"show_text","value":[{"text":"Click to reset ALL markers for map$(map_id)"}]},"italic":false,"text":"This map is already active! If you wish to reset it, you can click this message!"}

#checking shop
tellraw @s {"text":"Checking for 2 shop markers...","color":"dark_green"}
$execute store result score .num temp if entity @e[type=marker,tag=shop_location,scores={map_id=$(map_id)}]
$execute if score .num temp matches 3.. run return run tellraw @s {"text":"There must be ONLY 2 shop markers for map $(map_id)! You have 3+. Indicated by green sparkly particles","color":"red"}
$execute if score .num temp matches 1 run return run tellraw @s {"text":"There must be 2 shop markers for map $(map_id)! You only have 1. Indicated by green sparkly particles","color":"red"}
$execute if score .num temp matches 0 run return run tellraw @s {"text":"There must be 2 shop markers for map $(map_id)! You have none","color":"red"}

#checking center
tellraw @s {"text":"Checking center marker...","color":"dark_green"}
$execute unless entity @e[type=marker,tag=map_center,scores={map_id=$(map_id)}] run return run tellraw @s {"text":"Missing map_center for map $(map_id)!","color":"red"}

#success
$tellraw @s {"text":"Success! Created game$(map_id) scoreboard and map with name $(map_name)","color":"green"}
playsound minecraft:entity.player.levelup player @s ~ ~ ~ 0.5 0
$scoreboard objectives add game$(map_id) dummy
$scoreboard objectives modify game$(map_id) displayname {"text":"$(map_name)","color":"yellow"}

$data merge entity @n[type=marker,tag=map_lobby,scores={map_id=$(map_id)},tag=not_active] {CustomName:[{"color":"gray","italic":false,"text":"Selected Map: "},{"color":"yellow","italic":false,"text":"$(map_name) "},{"color":"dark_gray","italic":false,"text":"[$(map_id)]"}]}

$tag @n[type=marker,tag=map_lobby,scores={map_id=$(map_id)},tag=not_active] add finished
$tag @n[type=marker,tag=map_lobby,scores={map_id=$(map_id)},tag=not_active] remove not_active

function pctf:mode/z_map_maker/return_tellraw