This can go right into the facepalm section but I'm trying to send 2 strings and an array to a async task. The error I'm getting: Code: [10:30:07] [Server thread/CRITICAL]: Could not pass event 'pocketmine\event\player\PlayerJoinEvent' to 'PlayerInfo v1.3.3': Cannot serialize Server instance on Matthww\PlayerInfo\PlayerInfo [10:30:07] [Server thread/CRITICAL]: BadMethodCallException: "Cannot serialize Server instance" (EXCEPTION) in "src/pocketmine/Server" at line 2621 [10:30:07] [Server thread/DEBUG]: #0 plugins/PlayerInfo/src/Matthww/PlayerInfo/Tasks/SaveTask(23): pocketmine\Server->__sleep() [10:30:07] [Server thread/DEBUG]: #1 plugins/PlayerInfo/src/Matthww/PlayerInfo/PlayerInfo(107): Matthww\PlayerInfo\Tasks\SaveTask->__construct(string Matthww, array Array(), string D:\Matthew\Documents\PocketMine-MP\plugins\PlayerInfo//players/matthww.json) [10:30:07] [Server thread/DEBUG]: #2 plugins/PlayerInfo/src/Matthww/PlayerInfo/PlayerInfo(63): Matthww\PlayerInfo\PlayerInfo->Save(pocketmine\Player object, string iOS, string iPhone 8, string Classic UI, string Maximum, string Touch) [10:30:07] [Server thread/DEBUG]: #3 src/pocketmine/plugin/MethodEventExecutor(38): Matthww\PlayerInfo\PlayerInfo->onJoin(pocketmine\event\player\PlayerJoinEvent object) [10:30:07] [Server thread/DEBUG]: #4 src/pocketmine/plugin/RegisteredListener(98): pocketmine\plugin\MethodEventExecutor->execute(Matthww\PlayerInfo\PlayerInfo object, pocketmine\event\player\PlayerJoinEvent object) [10:30:07] [Server thread/DEBUG]: #5 src/pocketmine/plugin/PluginManager(721): pocketmine\plugin\RegisteredListener->callEvent(pocketmine\event\player\PlayerJoinEvent object) [10:30:07] [Server thread/DEBUG]: #6 src/pocketmine/Player(974): pocketmine\plugin\PluginManager->callEvent(pocketmine\event\player\PlayerJoinEvent object) [10:30:07] [Server thread/DEBUG]: #7 src/pocketmine/Player(922): pocketmine\Player->doFirstSpawn() [10:30:07] [Server thread/DEBUG]: #8 src/pocketmine/level/Level(2532): pocketmine\Player->sendChunk(integer 5, integer 11, pocketmine\network\mcpe\protocol\BatchPacket object) [10:30:07] [Server thread/DEBUG]: #9 src/pocketmine/level/Level(2577): pocketmine\level\Level->sendChunkFromCache(integer 5, integer 11) [10:30:07] [Server thread/DEBUG]: #10 src/pocketmine/level/format/io/ChunkRequestTask(88): pocketmine\level\Level->chunkRequestCallback(integer 5, integer 11, pocketmine\network\mcpe\protocol\BatchPacket object) [10:30:07] [Server thread/DEBUG]: #11 src/pocketmine/scheduler/AsyncPool(164): pocketmine\level\format\io\ChunkRequestTask->onCompletion(pocketmine\Server object) [10:30:07] [Server thread/DEBUG]: #12 src/pocketmine/scheduler/ServerScheduler(342): pocketmine\scheduler\AsyncPool->collectTasks() [10:30:07] [Server thread/DEBUG]: #13 src/pocketmine/Server(2536): pocketmine\scheduler\ServerScheduler->mainThreadHeartbeat(integer 285) [10:30:07] [Server thread/DEBUG]: #14 src/pocketmine/Server(2279): pocketmine\Server->tick() [10:30:07] [Server thread/DEBUG]: #15 src/pocketmine/Server(2154): pocketmine\Server->tickProcessor() [10:30:07] [Server thread/DEBUG]: #16 src/pocketmine/Server(1742): pocketmine\Server->start() [10:30:07] [Server thread/DEBUG]: #17 src/pocketmine/PocketMine(553): pocketmine\Server->__construct(BaseClassLoader object, pocketmine\utils\MainLogger object, string D:\Matthew\Documents\PocketMine-MP\, string D:\Matthew\Documents\PocketMine-MP\plugins\) The PlayerJoinEvent function: PHP: public function onJoin(PlayerJoinEvent $joinEvent) { $data = $this->PlayerData[$joinEvent->getPlayer()->getName()]; $this->Save($joinEvent->getPlayer(), $data["DeviceOS"], $data["DeviceModel"], $data["UIProfile"], $data["GuiScale"], $data["CurrentInputMode"]);} My Save function (still needs cleaning): PHP: public function Save($username, string $OS, string $model, string $UI, string $GUI, string $controls) { $DeviceOS = ["Unknown", "Android", "iOS", "macOS", "FireOS", "GearVR", "HoloLens", "Windows 10", "Windows", "Dedicated", "Orbis", "NX"]; $PlayerUI = ["Classic UI", "Pocket UI"]; $PlayerControls = ["Unknown", "Mouse", "Touch", "Controller"]; $PlayerGUI = [-2 => "Minimum", -1 => "Medium", 0 => "Maximum"]; echo "\nrunned save\n"; if($username instanceof Player) { echo "\nrunning async task!\n"; $player = $username->getName(); $ip = $username->getAddress(); $OS = $DeviceOS[$OS]; $model = $this->DeviceModel($model); $UI = $PlayerUI[$UI]; $GUI = $PlayerGUI[$GUI]; $controls = $PlayerControls[$controls]; $data = array( "username" => $username, "IP" => $ip, "OS" => $OS, "DeviceModel" => $model, "UI" => $UI, "GUI" => $GUI, "Controls" => $controls); $path = $this->getDataFolder() . "/players/" . strtolower($player) . ".json"; $this->getServer()->getScheduler()->scheduleAsyncTask(new SaveTask($player, $data, $path)); }}
Totally forgot to paste my Task PHP: public function __construct($username, $data, $path) { $this->savedata = new Config($path, Config::JSON, []); $this->username = $username; $this->data = $data; $this->path = $path; } public function onRun(): void { safe_var_dump($this->username); safe_var_dump($this->data); safe_var_dump($this->path); echo "hello"; if(is_file($this->path)) { $data = json_decode(file_get_contents($this->path), true) ?? []; } else { $data = []; } safe_var_dump($this->data); file_put_contents($this->path, json_encode($data)); } Line 23 is bold: public function __construct($username, $data, $path) { $this->savedata = new Config($path, Config::JSON, []); $this->username = $username; $this->data = $data; $this->path = $path; }
PHP: $player = $username->getName(); gotcha! Your $"username" is actually a player instance, which you are passing in the array.