Why isnt the player fully unregistered when PlayerQuitEvent was triggered, as example when I do count($level->getPlayers()) on the level of the player who left, then the left player gets also counted, is it a bug? And is there any way to bypass it?
It is not a bug. When PlayerQuitEvent is triggered, the player actually hasn't left the game yet. How to fix it: remember this fact, every time player quits, minus one from player count.