hi im making inventory-backup plugin. Code: <?php namespace NoLostItem; use pocketmine\Server; use pocketmine\plugin\PluginBase; use pocketmine\event\Listener; use pocketmine\Player; use pocketmine\event\player\PlayerJoinEvent; use pocketmine\permission\Permission; use pocketmine\command\Command; use pocketmine\command\CommandExecutor; use pocketmine\command\CommandSender; use pocketmine\event\player\PlayerQuitEvent; use pocketmine\item\Item; use pocketmine\utils\TextFormat; use pocketmine\scheduler\CallbackTask; use pocketmine\scheduler\ServerScheduler; use pocketmine\utils\Config; class NoLostItem extends PluginBase implements Listener{ public function onEnable(){ $this->getServer()->getPluginManager()->registerEvents($this, $this); $task = new CallbackTask(array($this, "schedule")); $time = 40; $this->getServer()->getScheduler()->scheduleRepeatingTask($task, $time); $dbf = $this->getDataFolder()."item.sqlite3.db"; if(!file_exists($this->getDataFolder())){ @mkdir($this->getDataFolder(), 0744, true); } if(!file_exists($dbf)){ $this->db = new \SQLite3($dbf, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE); }else{ $this->db = new \SQLite3($dbf, SQLITE3_OPEN_READWRITE); } $this->db->query("CREATE TABLE IF NOT EXISTS itemp (name TEXT PRIMARY KEY, id TEXT, armor TEXT)"); $this->getLogger()->info(TextFormat::GREEN."sqlite3 was loaded!"); } public function onDisable(){ $this->schedule(); $this->db->close(); $this->getLogger()->info(TextFormat::GREEN."sqlite3 was unloaded!"); } public function joinplayer(PlayerJoinEvent $event){ $player = $event->getPlayer(); $name = $player->getName(); $player->getInventory()->clearall(); $result = $this->db->query("SELECT name,id, armor FROM itemp WHERE name = \"$name\""); $rows = $result->fetchArray(SQLITE3_ASSOC); if($result){ if($rows['name'] != null and $rows['id'] != null and $rows['armor'] != null){ $player->getInventory()->setContents(unserialize(base64_decode($rows['id']))); $player->getInventory()->setArmorContents(unserialize(base64_decode($rows['armor']))); }} } public function quitgo (PlayerquitEvent $event){ $this->dare($event->getPlayer()); $event->getPlayer()->getInventory()->clearall(); } public function schedule (){ foreach($this->getServer()->getOnlinePlayers() as $player){ #$this->dare($player); } } public function dare ($player){ $name = $player->getName(); $this->db->query("DELETE FROM itemp WHERE name = \"$name\""); $id = base64_encode(serialize($player->getInventory()->getContents())); $armor = base64_encode(serialize($player->getInventory()->getArmorContents())); $this->db->query("INSERT OR REPLACE INTO itemp VALUES(\"$name\", \"$id\", \"$armor\")"); } } http://haniokasai.com/file/NoLostItemsql.zip when i use a item and left the server,this error happened. Code: [14:39:38] [CRITICAL]: "Could not pass event 'pocketmine\event\player\PlayerQuitEvent' to 'NoLostItem v1.0.0': Serialization of 'Closure' is not allowed on NoLostItem\NoLostItem [14:39:38] [CRITICAL]: Exception: "Serialization of 'Closure' is not allowed" (EXCEPTION) in "/NoLostItemsql/src/NoLostItem/NoLostItem" at line 82 [14:39:38] [INFO]: haniokasai_dev left the game [14:39:38] [INFO]: haniokasai_dev[/192.168.1.3:19132] logged out due to client disconnect Please tell how to fix it.
Format the item array yourself. Serializing the items may not work in new versions of PocketMine where items contain more data (and appears to contain reference to the server instance? Not sure but a wild guess)
Maybe as @PEMapModder said, make an array your self like this: Code: array( array( id, meta, count ) array( id, meta, count ) )
@PEMapModder and @Legoboy0215 ,thank for reply! i must use array... oh ,i get it. i'll try fix my plugin.
@PEMapModder and @Legoboy0215 ,thanks<3 my plugin is neary finished! Code: <?php namespace NoLostItem; use pocketmine\Server; use pocketmine\plugin\PluginBase; use pocketmine\event\Listener; use pocketmine\Player; use pocketmine\event\player\PlayerJoinEvent; use pocketmine\permission\Permission; use pocketmine\command\Command; use pocketmine\command\CommandExecutor; use pocketmine\command\CommandSender; use pocketmine\event\player\PlayerQuitEvent; use pocketmine\item\Item; use pocketmine\utils\TextFormat; use pocketmine\scheduler\CallbackTask; use pocketmine\scheduler\ServerScheduler; use pocketmine\utils\Config; class NoLostItem extends PluginBase implements Listener{ public function onEnable(){ $this->getServer()->getPluginManager()->registerEvents($this, $this); $task = new CallbackTask(array($this, "schedule")); $time = 400; $this->getServer()->getScheduler()->scheduleRepeatingTask($task, $time); $dbf = $this->getDataFolder()."item.sqlite3.db"; if(!file_exists($this->getDataFolder())){ @mkdir($this->getDataFolder(), 0744, true); } if(!file_exists($dbf)){ $this->db = new \SQLite3($dbf, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE); }else{ $this->db = new \SQLite3($dbf, SQLITE3_OPEN_READWRITE); } $this->db->query("CREATE TABLE IF NOT EXISTS itemp (name TEXT PRIMARY KEY, id TEXT, armor TEXT)"); $this->getLogger()->info(TextFormat::GREEN."sqlite3 was loaded!"); } public function onDisable(){ $this->schedule(); $this->db->close(); $this->getLogger()->info(TextFormat::GREEN."sqlite3 was unloaded!"); } public function joinplayer(PlayerJoinEvent $event){ $player = $event->getPlayer(); $name = $player->getName(); $player->getInventory()->clearall(); $result = $this->db->query("SELECT name,id, armor FROM itemp WHERE name = \"$name\""); $rows = $result->fetchArray(SQLITE3_ASSOC); if($result){ if($rows['name'] != null and $rows['id'] != null and $rows['armor'] != null){ $stack =unserialize(base64_decode($rows['id'])); $i =1;$ok =1; var_dump($stack); while($i <=36 and $ok == 1){ if(@$player->getInventory()->addItem(Item::get($stack[$i]["id"],$stack[$i]["da"],$stack[$i]["co"]))){ $i++; }else{ $ok =0; } } $player->getInventory()->setArmorContents(unserialize(base64_decode($rows['armor']))); }} } public function quitgo (PlayerquitEvent $event){ $this->dare($event->getPlayer()); $event->getPlayer()->getInventory()->clearall(); } public function schedule (){ foreach($this->getServer()->getOnlinePlayers() as $player){ #$this->dare($player); } } public function dare ($player){ $name = $player->getName(); $this->db->query("DELETE FROM itemp WHERE name = \"$name\""); $stack =array(); $i = 1; foreach($player->getInventory()->getContents() as $items){ $stack[$i]["id"] = $items->getId();$stack[$i]["da"] = $items->getDamage();$stack[$i]["co"] = $items->getCount(); $i++; } var_dump($stack); $id = base64_encode(serialize($stack)); $armor = base64_encode(serialize($player->getInventory()->getArmorContents())); $this->db->query("INSERT OR REPLACE INTO itemp VALUES(\"$name\", \"$id\", \"$armor\")"); } }
im haniokasai. https://forums.pocketmine.net/plugins/timecapsule.252/ https://forums.pocketmine.net/plugins/authors/falk.1229/