getContents() public method

public getContents ( ) : Item[]
return pocketmine\item\Item[]
Beispiel #1
0
 public function saveInventory(Player $player, Inventory $inv)
 {
     $n = trim(strtolower($player->getName()));
     if ($n === "") {
         return false;
     }
     $d = substr($n, 0, 1);
     if (!is_dir($this->getDataFolder() . $d)) {
         mkdir($this->getDataFolder() . $d);
     }
     $path = $this->getDataFolder() . $d . "/" . $n . ".yml";
     $cfg = new Config($path, Config::YAML);
     $yaml = $cfg->getAll();
     if ($this->isGlobal) {
         $ln = "*";
     } else {
         $ln = trim(strtolower($player->getLevel()->getName()));
     }
     $yaml[$ln] = [];
     foreach ($inv->getContents() as $slot => &$item) {
         $yaml[$ln][$slot] = implode(":", [$item->getId(), $item->getDamage(), $item->getCount()]);
     }
     $inv->clearAll();
     $cfg->setAll($yaml);
     $cfg->save();
     return true;
 }
Beispiel #2
0
 public function saveInventory(Player $player, Inventory $inv)
 {
     $n = trim(strtolower($player->getName()));
     if ($n === "") {
         return false;
     }
     if ($this->isGlobal) {
         $ln = "*";
     } else {
         $ln = trim(strtolower($player->getLevel()->getName()));
     }
     // Save inventory...
     $sql = "DELETE FROM NetherChests WHERE player=" . $this->prepare($n) . " AND world=" . $this->prepare($ln);
     $this->database->query($sql);
     foreach ($inv->getContents() as $slot => &$item) {
         $sql = "INSERT INTO NetherChests (player,world,slot,id,damage,count) VALUES (" . $this->prepare($n) . ", " . $this->prepare($ln) . ", " . $slot . ", " . $item->getId() . ", " . $item->getDamage() . ", " . $item->getCount() . ")";
         $this->database->query($sql);
     }
     $inv->clearAll();
     return true;
 }