# Check who has a book
tag @a remove has_book
function book/has_book

# Claim a book
tag @e[type=cubed:book] remove claimed
execute as @a[tag=has_book] at @s anchored eyes positioned ^^^0.5 if entity @e[r=5, c=1, type=cubed:book, tag=!claimed] run function book/claim
execute as @a[tag=has_book] at @s anchored eyes positioned ^^^0.5 unless entity @e[r=5, c=1, type=cubed:book, tag=claimed] run function book/summon

# Delete useless books
event entity @e[type=cubed:book, tag=!claimed] cubed:despawn

# Go next page
title @a[tag=has_book] actionbar Interact: §3Previous§f | Attack: §6Next§f

# Item cooldown
scoreboard objectives add book_cd dummy
scoreboard players add @a book_cd 0
scoreboard players add @a[scores={book_cd=1..}] book_cd -1