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

execute if entity @a[team=blue] if score $team_blue pumpkin_count = $core pumpkin_count run scoreboard players add $core pumpkins 1
execute if entity @a[team=red] if score $team_red pumpkin_count = $core pumpkin_count run scoreboard players add $core pumpkins 2
execute if entity @a[team=green] if score $team_green pumpkin_count = $core pumpkin_count run scoreboard players add $core pumpkins 4
execute if entity @a[team=yellow] if score $team_yellow pumpkin_count = $core pumpkin_count run scoreboard players add $core pumpkins 8
execute if score $team_blue pumpkin_count = $core pumpkin_count run tag @a[team=blue] add win
execute if score $team_red pumpkin_count = $core pumpkin_count run tag @a[team=red] add win
execute if score $team_green pumpkin_count = $core pumpkin_count run tag @a[team=green] add win
execute if score $team_yellow pumpkin_count = $core pumpkin_count run tag @a[team=yellow] add win

#Title
execute if score $core pumpkins matches 1 run title @a subtitle ["",{"translate":"game.end.blue","color":"blue","bold":true},{"translate":"game.end.wins","color":"gray"}]
execute if score $core pumpkins matches 2 run title @a subtitle ["",{"translate":"game.end.red","color":"red","bold":true},{"translate":"game.end.wins","color":"gray"}]
execute if score $core pumpkins matches 4 run title @a subtitle ["",{"translate":"game.end.green","color":"green","bold":true},{"translate":"game.end.wins","color":"gray"}]
execute if score $core pumpkins matches 8 run title @a subtitle ["",{"translate":"game.end.yellow","color":"yellow","bold":true},{"translate":"game.end.wins","color":"gray"}]

execute if score $core pumpkins matches 3 run title @a subtitle ["",{"translate":"game.end.draw","color":"gray"},{"translate":"game.end.blue","color":"blue","bold":true},{"translate":"game.end.and","color":"gray"},{"translate":"game.end.red","color":"red","bold":true},{"translate":"game.end.teams.win","color":"gray"}]
execute if score $core pumpkins matches 5 run title @a subtitle ["",{"translate":"game.end.draw","color":"gray"},{"translate":"game.end.blue","color":"blue","bold":true},{"translate":"game.end.and","color":"gray"},{"translate":"game.end.green","color":"green","bold":true},{"translate":"game.end.teams.win","color":"gray"}]
execute if score $core pumpkins matches 9 run title @a subtitle ["",{"translate":"game.end.draw","color":"gray"},{"translate":"game.end.blue","color":"blue","bold":true},{"translate":"game.end.and","color":"gray"},{"translate":"game.end.yellow","color":"yellow","bold":true},{"translate":"game.end.teams.win","color":"gray"}]
execute if score $core pumpkins matches 6 run title @a subtitle ["",{"translate":"game.end.draw","color":"gray"},{"translate":"game.end.red","color":"red","bold":true},{"translate":"game.end.and","color":"gray"},{"translate":"game.end.green","color":"green","bold":true},{"translate":"game.end.teams.win","color":"gray"}]
execute if score $core pumpkins matches 10 run title @a subtitle ["",{"translate":"game.end.draw","color":"gray"},{"translate":"game.end.red","color":"red","bold":true},{"translate":"game.end.and","color":"gray"},{"translate":"game.end.yellow","color":"yellow","bold":true},{"translate":"game.end.teams.win","color":"gray"}]
execute if score $core pumpkins matches 12 run title @a subtitle ["",{"translate":"game.end.draw","color":"gray"},{"translate":"game.end.green","color":"green","bold":true},{"translate":"game.end.and","color":"gray"},{"translate":"game.end.yellow","color":"yellow","bold":true},{"translate":"game.end.teams.win","color":"gray"}]

execute if score $core pumpkins matches 7 run title @a subtitle ["",{"translate":"game.end.draw","color":"gray"},{"translate":"game.end.blue","color":"blue","bold":true},{"text":", ","color":"gray"},{"translate":"game.end.red","color":"red","bold":true},{"translate":"game.end.and","color":"gray"},{"translate":"game.end.green","color":"green","bold":true},{"translate":"game.end.teams.win","color":"gray"}]
execute if score $core pumpkins matches 11 run title @a subtitle ["",{"translate":"game.end.draw","color":"gray"},{"translate":"game.end.blue","color":"blue","bold":true},{"text":", ","color":"gray"},{"translate":"game.end.red","color":"red","bold":true},{"translate":"game.end.and","color":"gray"},{"translate":"game.end.yellow","color":"yellow","bold":true},{"translate":"game.end.teams.win","color":"gray"}]
execute if score $core pumpkins matches 13 run title @a subtitle ["",{"translate":"game.end.draw","color":"gray"},{"translate":"game.end.blue","color":"blue","bold":true},{"text":", ","color":"gray"},{"translate":"game.end.green","color":"green","bold":true},{"translate":"game.end.and","color":"gray"},{"translate":"game.end.yellow","color":"yellow","bold":true},{"translate":"game.end.teams.win","color":"gray"}]
execute if score $core pumpkins matches 14 run title @a subtitle ["",{"translate":"game.end.draw","color":"gray"},{"translate":"game.end.red","color":"red","bold":true},{"text":", ","color":"gray"},{"translate":"game.end.green","color":"green","bold":true},{"translate":"game.end.and","color":"gray"},{"translate":"game.end.yellow","color":"yellow","bold":true},{"translate":"game.end.teams.win","color":"gray"}]

execute if score $core pumpkins matches 15 run title @a subtitle ["",{"translate":"game.end.draw","color":"gray"},{"translate":"game.end.everyone","color":"gray"}]

#Achievement
execute unless score $core pumpkins matches 1 unless score $core pumpkins matches 2 unless score $core pumpkins matches 4 unless score $core pumpkins matches 8 run advancement grant @a[tag=player] only f:close_call
