PlayerEvents.loggedIn(event => {
    const { player, server } = event

    // Check if the player has the 'sundial_claimed' flag in their persistent data
    if (!player.persistentData.contains('sundial_claimed')) {
        
        // Wait 2 seconds (40 ticks) so they are fully loaded and looking at the screen
        server.scheduleInTicks(40, callback => {
            // Display the message using the standard Title command
            player.tell(Text.gold('Check your quest book to claim your Sundial!')) // Also put it in chat as backup
            
            server.runCommandSilent(`title ${player.username} title {"text":"Claim your sundial","color":"gold"}`)
            server.runCommandSilent(`title ${player.username} subtitle {"text":"in the quest book","color":"yellow"}`)
            
            // Set the flag so this block never runs for this player again
            player.persistentData.putBoolean('sundial_claimed', true)
        })
    }
})