Sorry if this sounds rude but you aren't suppose to run anything in LoginEvent the Recieve Event runs by itself when the player joins
Without $player it also don't work... Error without $player: Code: Argument 1 passed to Plugin\Main::onDataPacket() must be an instance of pocketmine\event\server\ DataPacketReceiveEvent, none given,
seriously? After you got the name WHAT IN HE*L do you want to do with $this->onDataPacket? You already got your $name now. What do you want to do after all?
Why do you have to get it from the packet? If possible, you should always try to use event listeners instead of handling packets in your plugin. If the username is just an example, what other data aside from the username do you want from the packet?
Which we told you. You're confusing me, do you want to get the player's username, or is that just an example, or what? It's hard for anyone to help you if we don't know.
This was already answered here. You simply used it incorrectly. If you want to echo or use the username you received later, you can save it to an array or variable. Your attempt isn't logical. You don't have a data packet to pass to the onDataPacket() function. You certainly can't pass a Player class to it. If you can't explain EXACTLY what you want to do, you won't get much more help.