tag @s add SpellUpdate

tellraw @s[tag=!HasteUpgrade,tag=!HasteUpgrade2,nbt={SelectedItem:{tag:{kyuhasteupgrade:1b}}}] ["",{"text":"You have unlocked the 'Haste' spell upgrade!","color":"dark_aqua"}]
tellraw @s[tag=HasteUpgrade2,nbt={SelectedItem:{tag:{kyuhasteupgrade:1b}}}] ["",{"text":"You have already unlocked this spell upgrade!","color":"aqua"}]
tag @s[tag=!HasteUpgrade,nbt={SelectedItem:{tag:{kyuhasteupgrade:1b}}}] add HasteUpgrade
clear @s[tag=HasteUpgrade,tag=!HasteUpgrade2,nbt={SelectedItem:{tag:{kyuhasteupgrade:1b}}}] paper{kyuhasteupgrade:1b} 1
tag @s[tag=HasteUpgrade,tag=!HasteUpgrade2] add HasteUpgrade2
#
tellraw @s[tag=!SlowfallUpgrade,tag=!SlowfallUpgrade2,nbt={SelectedItem:{tag:{kyuslowfallupgrade:1b}}}] ["",{"text":"You have unlocked the 'Slowfall' spell upgrade!","color":"dark_aqua"}]
tellraw @s[tag=SlowfallUpgrade2,nbt={SelectedItem:{tag:{kyuslowfallupgrade:1b}}}] ["",{"text":"You have already unlocked this spell upgrade!","color":"aqua"}]
tag @s[tag=!SlowfallUpgrade,nbt={SelectedItem:{tag:{kyuslowfallupgrade:1b}}}] add SlowfallUpgrade
clear @s[tag=SlowfallUpgrade,tag=!SlowfallUpgrade2,nbt={SelectedItem:{tag:{kyuslowfallupgrade:1b}}}] paper{kyuslowfallupgrade:1b} 1
tag @s[tag=SlowfallUpgrade,tag=!SlowfallUpgrade2] add SlowfallUpgrade2
#
tellraw @s[tag=!ResistUpgrade,tag=!ResistUpgrade2,nbt={SelectedItem:{tag:{kyuresistupgrade:1b}}}] ["",{"text":"You have unlocked the 'Resistance' spell upgrade!","color":"dark_aqua"}]
tellraw @s[tag=ResistUpgrade2,nbt={SelectedItem:{tag:{kyuresistupgrade:1b}}}] ["",{"text":"You have already unlocked this spell upgrade!","color":"aqua"}]
tag @s[tag=!ResistUpgrade,nbt={SelectedItem:{tag:{kyuresistupgrade:1b}}}] add ResistUpgrade
clear @s[tag=ResistUpgrade,tag=!ResistUpgrade2,nbt={SelectedItem:{tag:{kyuresistupgrade:1b}}}] paper{kyuresistupgrade:1b} 1
tag @s[tag=ResistUpgrade,tag=!ResistUpgrade2] add ResistUpgrade2
#
tellraw @s[tag=!LadderUpgrade,tag=!LadderUpgrade2,nbt={SelectedItem:{tag:{kyuladderupgrade:1b}}}] ["",{"text":"You have unlocked the 'Escape Ladder' spell upgrade!","color":"dark_aqua"}]
tellraw @s[tag=LadderUpgrade2,nbt={SelectedItem:{tag:{kyuladderupgrade:1b}}}] ["",{"text":"You have already unlocked this spell upgrade!","color":"aqua"}]
tag @s[tag=!LadderUpgrade,nbt={SelectedItem:{tag:{kyuladderupgrade:1b}}}] add LadderUpgrade
clear @s[tag=LadderUpgrade,tag=!LadderUpgrade2,nbt={SelectedItem:{tag:{kyuladderupgrade:1b}}}] paper{kyuladderupgrade:1b} 1
tag @s[tag=LadderUpgrade,tag=!LadderUpgrade2] add LadderUpgrade2
#
tellraw @s[tag=!LocatorUpgrade,tag=!LocatorUpgrade2,nbt={SelectedItem:{tag:{kyulocatorupgrade:1b}}}] ["",{"text":"You have unlocked the 'Enchanted Cavern Locator' spell upgrade!","color":"dark_aqua"}]
tellraw @s[tag=LocatorUpgrade2,nbt={SelectedItem:{tag:{kyulocatorupgrade:1b}}}] ["",{"text":"You have already unlocked this spell upgrade!","color":"aqua"}]
tag @s[tag=!LocatorUpgrade,nbt={SelectedItem:{tag:{kyulocatorupgrade:1b}}}] add LocatorUpgrade
clear @s[tag=LocatorUpgrade,tag=!LocatorUpgrade2,nbt={SelectedItem:{tag:{kyulocatorupgrade:1b}}}] paper{kyulocatorupgrade:1b} 1
tag @s[tag=LocatorUpgrade,tag=!LocatorUpgrade2] add LocatorUpgrade2
#
tellraw @s[tag=!HorseUpgrade,tag=!HorseUpgrade2,nbt={SelectedItem:{tag:{kyuhorseupgrade:1b}}}] ["",{"text":"You have unlocked the 'Summon Horse' spell upgrade!","color":"dark_aqua"}]
tellraw @s[tag=HorseUpgrade2,nbt={SelectedItem:{tag:{kyuhorseupgrade:1b}}}] ["",{"text":"You have already unlocked this spell upgrade!","color":"aqua"}]
tag @s[tag=!HorseUpgrade,nbt={SelectedItem:{tag:{kyuhorseupgrade:1b}}}] add HorseUpgrade
clear @s[tag=HorseUpgrade,tag=!HorseUpgrade2,nbt={SelectedItem:{tag:{kyuhorseupgrade:1b}}}] paper{kyuhorseupgrade:1b} 1
tag @s[tag=HorseUpgrade,tag=!HorseUpgrade2] add HorseUpgrade2
#
tellraw @s[tag=!InvisUpgrade,tag=!InvisUpgrade2,nbt={SelectedItem:{tag:{kyuinvisupgrade:1b}}}] ["",{"text":"You have unlocked the 'Invisibility' spell upgrade!","color":"dark_aqua"}]
tellraw @s[tag=InvisUpgrade2,nbt={SelectedItem:{tag:{kyuinvisupgrade:1b}}}] ["",{"text":"You have already unlocked this spell upgrade!","color":"aqua"}]
tag @s[tag=!InvisUpgrade,nbt={SelectedItem:{tag:{kyuinvisupgrade:1b}}}] add InvisUpgrade
clear @s[tag=InvisUpgrade,tag=!InvisUpgrade2,nbt={SelectedItem:{tag:{kyuinvisupgrade:1b}}}] paper{kyuinvisupgrade:1b} 1
tag @s[tag=InvisUpgrade,tag=!InvisUpgrade2] add InvisUpgrade2
#
tellraw @s[tag=!FarmUpgrade,tag=!FarmUpgrade2,nbt={SelectedItem:{tag:{kyufarmupgrade:1b}}}] ["",{"text":"You have unlocked the 'Farm Animal Capture' spell upgrade!","color":"dark_aqua"}]
tellraw @s[tag=FarmUpgrade2,nbt={SelectedItem:{tag:{kyufarmupgrade:1b}}}] ["",{"text":"You have already unlocked this spell upgrade!","color":"aqua"}]
tag @s[tag=!FarmUpgrade,nbt={SelectedItem:{tag:{kyufarmupgrade:1b}}}] add FarmUpgrade
clear @s[tag=FarmUpgrade,tag=!FarmUpgrade2,nbt={SelectedItem:{tag:{kyufarmupgrade:1b}}}] paper{kyufarmupgrade:1b} 1
tag @s[tag=FarmUpgrade,tag=!FarmUpgrade2] add FarmUpgrade2
#

tag @s[tag=SpellUpdate] add BookUpdate
tag @s[tag=SpellUpdate,nbt=!{SelectedItem:{id:"minecraft:paper",tag:{HideFlags:1,Enchantments:[{}]}}}] remove SpellUpdate