Is there a way to extend a class or do something that I can add variables and methods to players, so I could do for example: PHP: public function onBlockBreak(BlockBreakEvent $event) { $event->getPlayer()->myMethod();}
No. Create your own class that references to the Player, initialize it at login and finalize it at quit. Take a look at the BulkCommands plugin for example. Of course, you can as well do a $player->_______myname_myvar to define a dynamic property and get it later, but it is very bad practice.
Another way to do this is editing PocketMine source but @PEMapModder gave the best solution especially if you want to redistribute this part of code
Yes of course, you can fully edit PocketMine source: don't forget that PocketMine is licensed under GNU GPL. But if you add methods to PocketMine classes and then use those on your plugins, you can't redistribute them unless you redistribute also your modified PocketMine version
And the important thing is, you won't be able to update your PocketMine version fluently. Let me explain my suggestion with some code: PHP: // main class that implements Listenerprivate $sessions = [];public function onJoin(PlayerLoginEvent $event){ $this->sessions[$event->getPlayer()->getId()] = new Session($this, $event->getPlayer()); // from my experience, getting the main class object is almost necessary for every object that interacts with your plugin, so my practice is to make it pass it even if you don't foresee the need to use it yet.}public function onQuit(PlayerQuitEvent $event){ if(isset($this->sessions[$id = $event->getPlayer()->getId()])){ $this->sessions[$id]->finalize(); unset($this->sessions[$id]); }}public function getSession(Player $player){ return isset($this->sessions[$id = $player->getId()]) ? $this->sessions[$id] : null;} P.S. I have written this framework so many times that it gets so boring. PHP: class Session{ public $main; public $player; public $isUsingCommand = false; public function __construct(Main $main, Player $player){ $this->main = $main; $this->player = $player; // tip: if you use PHPStorm, move your pointer to one of the parameters // of the constructor and type Alt+Enter (or whatever your keymap is for auto // intentions), and there would be an "Initialize fields" button. Click it // to automatically add the private fields and the $this->*=$* lines } public function finalize(){ // when player quits }} Then an example command handler inside your main class: PHP: /** @var CommandSender $send */if(!($send instanceof Player)){ $send->sendMessage("please run this command in-game"); return true;}$ses = $this->getSession($send);// we don't need to check whether getSession returns null or a real object, because a player wouldn't issue a command until he has logged in.if(!$ses->isUsingCommand){ $ses->isUsingCommand = true; $send->sendMessage("Are you sure? Run this command again to confirm"); return true;}// execute the command$ses->isUsingCommand = false;