###Check if already collected nearby###
execute if entity @s[advancements={nitref:dragonology/collect_dragon_head=true}] unless entity @e[tag=nitHeadCollected,distance=..50] run tag @s add nitSuccess
execute if entity @s[advancements={nitref:dragonology/kill_enderdragon=true}] run tag @s add nitSuccess
execute if entity @s[advancements={nitref:dragonology/destroy_dragon_crystal=true}] run tag @s add nitSuccess
execute if entity @s[advancements={nitref:dragonology/find_dragon_egg=true}] unless entity @e[tag=nitEggFound,distance=..32] run tag @s add nitSuccess

###Grant Dragon Scales###
execute if entity @s[tag=nitSuccess] run playsound ui.toast.challenge_complete player @a ~ ~ ~ 1 1.6
execute if entity @s[tag=nitSuccess] run loot give @s loot nitref:command/dragon_scales
execute if entity @s[tag=nitSuccess,advancements={nitref:dragonology/kill_enderdragon=true}] run loot give @s loot nitref:command/dragon_scales

###Mark area as collected###
execute if entity @s[advancements={nitref:dragonology/collect_dragon_head=true},tag=nitSuccess] run summon marker ~ ~ ~ {Tags:[nitEntity,smithed.entity,smithed.strict,nitHeadCollected]}
execute if entity @s[advancements={nitref:dragonology/find_dragon_egg=true},tag=nitSuccess] run summon marker ~ ~ ~ {Tags:[nitEntity,smithed.entity,smithed.strict,nitEggFound]}
tellraw @s[advancements={nitref:dragonology/collect_dragon_head=true},tag=nitSuccess] [{"text":"[۩]","color":"green","bold":true},{"text":": ","color":"white","bold":false},{"text":"Dragon Head collected from this location! Turn in your Dragon Scales for Dragonology Research!","color":"white","bold":false}]
tellraw @s[advancements={nitref:dragonology/kill_enderdragon=true},tag=nitSuccess] [{"text":"[۩]","color":"green","bold":true},{"text":": ","color":"white","bold":false},{"text":"You've slain an Enderdragon! Turn in its Dragon Scales for Dragonology Research.","color":"white","bold":false}]
tellraw @s[advancements={nitref:dragonology/destroy_dragon_crystal=true},tag=nitSuccess] [{"text":"[۩]","color":"green","bold":true},{"text":": ","color":"white","bold":false},{"text":"You destroyed an ancient End Crystal! Turn in your Dragon Scales for Dragonology Research.","color":"white","bold":false}]
tellraw @s[advancements={nitref:dragonology/find_dragon_egg=true},tag=nitSuccess] [{"text":"[۩]","color":"green","bold":true},{"text":": ","color":"white","bold":false},{"text":"You found a giant ancient Dragon Egg! Turn in your Dragon Scales for Dragonology Research!","color":"white","bold":false}]

###Revoke Advancements###
tag @s remove nitSuccess
advancement revoke @s only nitref:dragonology/collect_dragon_head
advancement revoke @s only nitref:dragonology/kill_enderdragon
advancement revoke @s only nitref:dragonology/destroy_dragon_crystal
advancement revoke @s only nitref:dragonology/find_dragon_egg