The title says it all Or a wrapper class would be better? EDIT: Just found that I can modify player class in PlayerCreationEvent. It seems certainly possible!
It is a possible, and "safe". However, it is bad practice. If you are running your own SourceInterface, it makes sense, but for other problems, there should be a better solution.
Add custom methods / fields to the class? I am trying to write a minigame plugin, and of course the code will involve things like reading and writing player data, getting information from database, etc. Originally wanted to implement features using a wrapper class, like: PHP: class PlayerInfo { private static $playerInfos; public static function getPlayerInfo(Player $player) { $info = $this->playerInfos[$player->getName()]; if ($info === null) { $info = new PlayerInfo($player); $this->playerInfos[$player->getName()] = $info; } return $info; } private $player; public function __construct(Player $player) {...} // Custom fields and methods here} Something like that. But it is a pain in the ass to call PlayerInfo::getPlayerInfo(Player) everytime when I need access to certain data. Therefore I posted the question. And yes, it is possible, and PocketMine even has a built-in support for replacing the Player class, through PlayerCreationEvent.
The PocketMine extension, pthreads, breaks something when you use static object properties. Avoid using static properties containing objects or arrays of objects.
I would just like to add a note on this half a year old threads (bumping!), that unless you are coding a private plugin, or unless it is impossible to otherwise do so, never use PlayerCreationEvent. Two plugins doing so will clash and only one can survive.