PHP: <?php namespace YourName\YourPlugin; use pocketmine\plugin\PluginBase; use pocketmine\Player; use pocketmine\event\Listener; use pocketmine\event\server\DataPacketReceiveEvent; use pocketmine\event\player\PlayerJoinEvent; use pocketmine\event\player\PlayerQuitEvent; use pocketmine\network\protocol\LoginPacket; class Main extends PluginBase implements Listener { private $username[]; public function onDataPacket(DataPacketReceiveEvent $event) { if($event->getPacket() instanceof LoginPacket) { /* Using IP as the key. Probably a bad idea, but not moreso than this entire example. */ $this->username[$event->getPlayer()->getAddress()] = $event->getPacket()->username; } } public function onJoin(PlayerJoinEvent $event) { if(isset($this->username[$event->getPlayer()->getAddress()])) { echo $this->username[$event->getPlayer()->getAddress()]; } } public function onQuit(PlayerQuitEvent $event) { if(isset($this->username[$event->getPlayer()->getAddress()])) { unset($this->username[$event->getPlayer()->getAddress()]); } } } I regret writing this, because it is absolutely pointless and, honestly, stupid. I only hope that whatever you plan to do is more logical than this.
sorry to bump this thread but it was related to my issue and thought you guys could chime in. also still not sure if I should use public or private for my purpose, because I need to generate username to input through the console. Link; How To Get Player Username PocketMine
Spoiler: Large Quote looking back at this code, and trying to implement parts of it for my own purpose is rather confusing. what is >getAddess doing? I simply just need to be able to output the plain text username "user_123" I also dont need it to run at login, since it activates by a "tap" ( left click ) and will be issueing commands through the console, it would have to be each unique event, cant really set variables. My Issue is; I seem to be looking for the username wrong Code: $block = $tap->getPlayer()->getLevel()->getTile($tap->getBlock()); $PlayerName = $tap->getPlayer(); When I try to output $PlayerName I get "player(1)" "player(2)" "player(3)" instead of the desired username if I could get their username instead of player number or convert the number to a username somehow I think I can get it going.
You need to use $tap->getPlayer()->getName(); to get the username. Whenever you use $anyEvent->getPlayer(), it will return a Player Object. You can then get data(or run functions like $playerObject->teleport()) with the Object.
oh wow that was really simple. is there any documentation to where those functions are? getplayer, getname etc.