How to detect player joining a Minecraft world? [duplicate]

Self solved , experiment under discussion with chyx

The world loads before player join even if it's single player, so freely assume at the beginning there's no player:

give @a[score_onLine=0] iron_shovel
scoreboard players set * onLine 0
scoreboard players set @a onLine 1