[16:11:57] [Server thread/CRITICAL]: Could not pass event 'pocketmine\event\player\PlayerJoinEvent' to 'MyriadHC v1': Cannot serialize Server instance on friscowz\hc\listener\CheatListener [16:11:57] [Server thread/CRITICAL]: BadMethodCallException: "Cannot serialize Server instance" (EXCEPTION) in "src/pocketmine/Server" at line 2591 this is what i get everytime i schedule my AsyncTask... debugs : [16:11:57] [Server thread/CRITICAL]: Could not pass event 'pocketmine\event\player\PlayerJoinEvent' to 'MyriadHC v1': Cannot serialize Server instance on friscowz\hc\listener\CheatListener [16:11:57] [Server thread/CRITICAL]: BadMethodCallException: "Cannot serialize Server instance" (EXCEPTION) in "src/pocketmine/Server" at line 2591 [16:11:57] [Server thread/DEBUG]: #0 HardCoreFaction/src/friscowz/hc/task/async/HideBlocksTask(91): pocketmine\Server->__sleep() [16:11:57] [Server thread/DEBUG]: #1 HardCoreFaction/src/friscowz/hc/task/async/HideBlocksTask(27): friscowz\hc\task\async\HideBlocksTask->setPlayer(friscowz\hc\MDPlayer object) [16:11:57] [Server thread/DEBUG]: #2 HardCoreFaction/src/friscowz/hc/MDPlayer(704): friscowz\hc\task\async\HideBlocksTask->__construct(friscowz\hc\MDPlayer object) [16:11:57] [Server thread/DEBUG]: #3 HardCoreFaction/src/friscowz/hc/listener/CheatListener(96): friscowz\hc\MDPlayer->checkBlocks() [16:11:57] [Server thread/DEBUG]: #4 src/pocketmine/plugin/MethodEventExecutor(38): friscowz\hc\listener\CheatListener->onJoin(pocketmine\event\player\PlayerJoinEvent object) [16:11:57] [Server thread/DEBUG]: #5 src/pocketmine/plugin/RegisteredListener(98): pocketmine\plugin\MethodEventExecutor->execute(friscowz\hc\listener\CheatListener object, pocketmine\event\player\PlayerJoinEvent object) [16:11:57] [Server thread/DEBUG]: #6 src/pocketmine/plugin/PluginManager(721): pocketmine\plugin\RegisteredListener->callEvent(pocketmine\event\player\PlayerJoinEvent object) [16:11:57] [Server thread/DEBUG]: #7 src/pocketmine/Player(920): pocketmine\plugin\PluginManager->callEvent(pocketmine\event\player\PlayerJoinEvent object) [16:11:57] [Server thread/DEBUG]: #8 src/pocketmine/Player(868): pocketmine\Player->doFirstSpawn() [16:11:57] [Server thread/DEBUG]: #9 src/pocketmine/level/Level(2393): pocketmine\Player->sendChunk(integer 7, integer 5, pocketmine\network\mcpe\protocol\BatchPacket object) [16:11:57] [Server thread/DEBUG]: #10 src/pocketmine/level/Level(2434): pocketmine\level\Level->sendChunkFromCache(integer 7, integer 5) [16:11:57] [Server thread/DEBUG]: #11 src/pocketmine/level/format/io/ChunkRequestTask(91): pocketmine\level\Level->chunkRequestCallback(integer 7, integer 5, pocketmine\network\mcpe\protocol\BatchPacket object) [16:11:57] [Server thread/DEBUG]: #12 src/pocketmine/scheduler/AsyncPool(164): pocketmine\level\format\io\ChunkRequestTask->onCompletion(pocketmine\Server object) [16:11:57] [Server thread/DEBUG]: #13 src/pocketmine/scheduler/ServerScheduler(342): pocketmine\scheduler\AsyncPool->collectTasks() [16:11:57] [Server thread/DEBUG]: #14 src/pocketmine/Server(2506): pocketmine\scheduler\ServerScheduler->mainThreadHeartbeat(integer 293) [16:11:57] [Server thread/DEBUG]: #15 src/pocketmine/Server(2253): pocketmine\Server->tick() [16:11:57] [Server thread/DEBUG]: #16 src/pocketmine/Server(2132): pocketmine\Server->tickProcessor() [16:11:57] [Server thread/DEBUG]: #17 src/pocketmine/Server(1714): pocketmine\Server->start() [16:11:57] [Server thread/DEBUG]: #18 src/pocketmine/PocketMine(558): pocketmine\Server->__construct(BaseClassLoader object, pocketmine\utils\MainLogger object, string phar:///root/hcf/PocketMine-MP.phar/, string /root/hcf/, string /root/hcf/plugins/) [16:11:57] [Server thread/DEBUG]: #19 /root/hcf/PocketMine-MP.phar(1): require(string phar:///root/hcf/PocketMine-MP.phar/src/pocketmine/PocketMine.php)
you're trying to pass objects into a thread. Bad idea. What are you trying to do? btw please show your code (or parts of it, preferably the relevant parts)
Well, if you’re doing what i think you are doing: FORGET IT That’s not how threads work. What are you planning to do in the AsyncTask?
changed the object (MDPlayer var) to a String: PHP: /*** HideBlocksTask constructor.* @param string $player*/public function __construct(string $player){ $this->setPlayer($player);}/*** @return MDPlayer*/public function getPlayer() : MDPlayer{ return Myriad::getInstance()->getServer()->getPlayer($this->player);}/*** @param string $player*/public function setPlayer(string $player){ $this->player = $player;}
You can never get a Server instnace or a Player instance on another thread. Therefore you can't send packets to players on other threads. That's all.
To be precise, nothing holds a Server instance. Since objects in PHP are passed as reference (not that the variable itself is passed by reference, but the object is passed by reference), a variable or a class property can only hold a reference to an object's memory address, but it can never hold the object instance itself. The object instance is held by PHP itself.
Note that "on another thread" doesn't mean whether the code is in your HideBlocksTask.php. Any code that is called from onRun() of the AsyncTask is executed on another thread, wherever the code is written.
If you want to know the cause, it's because Server is a heavy object. Serializing it means you are serializing everything. That includes all the plugins, levels, players...
Serializing it has no problem (if it can really be serialized). The problem is that it is useless even if you send it to another thread, because all passed objects are cloned (i.e. the changes won't reflect on the main thread), and all resources are dead (i.e. PHP can't send packets from another thread under any circumstances).