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


#####Database is required for statistics to function properly because it is necessary to track offline players#####

execute as @a store result score @s UUID run data get entity @s UUID[0]
execute as @a store result score @s UUID2 run data get entity @s UUID[1]
execute as @a store result score @s UUID3 run data get entity @s UUID[2]
execute as @a store result score @s UUID4 run data get entity @s UUID[3]
#scoreboard players operation @a UUID += test UUID
execute as @a[tag=!registered] run function f:data/register

#Save scores
execute as @a run function f:data/save

#Display Stats
execute as @e[tag=stats_player] run data merge entity @s {CustomName:'{"text":"N/A","italic":true,"color":"gray"}'}

function f:data/position
execute as @e[tag=database] run scoreboard players operation @s pos_y += @s wins
function f:data/leaderboard
data modify entity @e[tag=1spot,tag=stats_wins,limit=1] CustomName set from entity @e[tag=database,limit=1,scores={main=5}] data.Wins
data modify entity @e[tag=2spot,tag=stats_wins,limit=1] CustomName set from entity @e[tag=database,limit=1,scores={main=4}] data.Wins
data modify entity @e[tag=3spot,tag=stats_wins,limit=1] CustomName set from entity @e[tag=database,limit=1,scores={main=3}] data.Wins
data modify entity @e[tag=4spot,tag=stats_wins,limit=1] CustomName set from entity @e[tag=database,limit=1,scores={main=2}] data.Wins
data modify entity @e[tag=5spot,tag=stats_wins,limit=1] CustomName set from entity @e[tag=database,limit=1,scores={main=1}] data.Wins

function f:data/position
execute as @e[tag=database] run scoreboard players operation @s pos_y += @s kills
function f:data/leaderboard
data modify entity @e[tag=1spot,tag=stats_kills,limit=1] CustomName set from entity @e[tag=database,limit=1,scores={main=5}] data.Kills
data modify entity @e[tag=2spot,tag=stats_kills,limit=1] CustomName set from entity @e[tag=database,limit=1,scores={main=4}] data.Kills
data modify entity @e[tag=3spot,tag=stats_kills,limit=1] CustomName set from entity @e[tag=database,limit=1,scores={main=3}] data.Kills
data modify entity @e[tag=4spot,tag=stats_kills,limit=1] CustomName set from entity @e[tag=database,limit=1,scores={main=2}] data.Kills
data modify entity @e[tag=5spot,tag=stats_kills,limit=1] CustomName set from entity @e[tag=database,limit=1,scores={main=1}] data.Kills

function f:data/position
execute as @e[tag=database] run scoreboard players operation @s pos_y += @s pumpkins
function f:data/leaderboard
data modify entity @e[tag=1spot,tag=stats_pumpkins,limit=1] CustomName set from entity @e[tag=database,limit=1,scores={main=5}] data.Pumpkins
data modify entity @e[tag=2spot,tag=stats_pumpkins,limit=1] CustomName set from entity @e[tag=database,limit=1,scores={main=4}] data.Pumpkins
data modify entity @e[tag=3spot,tag=stats_pumpkins,limit=1] CustomName set from entity @e[tag=database,limit=1,scores={main=3}] data.Pumpkins
data modify entity @e[tag=4spot,tag=stats_pumpkins,limit=1] CustomName set from entity @e[tag=database,limit=1,scores={main=2}] data.Pumpkins
data modify entity @e[tag=5spot,tag=stats_pumpkins,limit=1] CustomName set from entity @e[tag=database,limit=1,scores={main=1}] data.Pumpkins
function f:data/position