clear @s minecraft:book[custom_data={backroomloot:tag}] 1
loot give @s loot survivalplus:backroomloot
advancement revoke @s only survivalplus:finale/backrooms/loot
execute if data entity @s {Inventory:[{id:"minecraft:book",components:{"minecraft:custom_data":{backroomloot:"tag"}}}]} run advancement grant @s only survivalplus:finale/backrooms/loot