Пример #1
0
 /**
  * @param Inventory $inventory
  */
 public function addToInventory(Inventory $inventory)
 {
     foreach ($this->getItems() as $i) {
         $inventory->setItem($inventory->firstEmpty(), clone $i);
     }
     // call_user_func_array($inventory->addItem(), $this->getItems());
 }
Пример #2
0
 public function addInventoryRandomItems($level, Inventory $inv)
 {
     if ($inv != null) {
         $inv->setItem(0, self::randomItems());
         $inv->setItem(1, self::randomItems());
         $inv->setItem(2, self::randomItems());
         $inv->setItem(3, self::randomItems());
     }
 }
Пример #3
0
 /**
  * @param Player $source
  *
  * Sends a slot update to inventory viewers
  * For successful transactions, update non-source viewers (source does not need updating)
  * For failed transactions, update the source (non-source viewers will see nothing anyway)
  */
 public function sendSlotUpdate(Player $source)
 {
     if ($this->getInventory() instanceof TemporaryInventory) {
         return;
     }
     $targets = [];
     if ($this->wasSuccessful) {
         $targets = $this->getInventory()->getViewers();
         unset($targets[spl_object_hash($source)]);
     } else {
         $targets = [$source];
     }
     $this->inventory->sendSlot($this->slot, $targets);
 }
Пример #4
0
 public function loadInventory(Player $player, Inventory $inv)
 {
     $n = trim(strtolower($player->getName()));
     if ($n === "") {
         return false;
     }
     if ($this->isGlobal) {
         $ln = "*";
     } else {
         $ln = trim(strtolower($player->getLevel()->getName()));
     }
     $inv->clearAll();
     $sql = "SELECT slot,id,damage,count FROM NetherChests WHERE player = " . $this->prepare($n) . " AND world = " . $this->prepare($ln);
     $res = $this->database->query($sql);
     if ($res === false) {
         return false;
     }
     while (($row = $res->fetch_assoc()) != null) {
         $inv->setItem($row["slot"], Item::get($row["id"], $row["damage"], $row["count"]));
     }
     $res->free();
     return true;
 }
Пример #5
0
 public function removeWindow(Inventory $inventory)
 {
     $inventory->close($this);
     if ($this->windows->contains($inventory)) {
         $id = $this->windows[$inventory];
         $this->windows->detach($this->windowIndex[$id]);
         unset($this->windowIndex[$id]);
     }
 }
Пример #6
0
 /**
  * @return \pocketmine\entity\Human[]
  */
 public function getViewers()
 {
     return $this->inventory->getViewers();
 }
Пример #7
0
 public function isNeChest(Inventory $inv)
 {
     if ($inv instanceof DoubleChestInventory) {
         return false;
     }
     if (!$inv instanceof ChestInventory) {
         return false;
     }
     $tile = $inv->getHolder();
     if (!$tile instanceof Chest) {
         return false;
     }
     $bl = $tile->getBlock();
     if ($bl->getId() != Block::CHEST) {
         return false;
     }
     if ($bl->getSide(Vector3::SIDE_DOWN)->getId() != $this->base_block) {
         return false;
     }
     return true;
 }
Пример #8
0
 public function deleteChest(Inventory $inv)
 {
     $bl = $inv->getHolder()->getBlock();
     $x = $bl->getFloorX();
     $y = $bl->getFloorY();
     $z = $bl->getFloorZ();
     unset($this->chests[$x . ":" . $y . ":" . $z]);
     //	$this->getLogger()->info('Chest deleted');
 }
Пример #9
-1
 public function loadInventory(Player $player, Inventory $inv)
 {
     $n = trim(strtolower($player->getName()));
     if ($n === "") {
         return false;
     }
     $d = substr($n, 0, 1);
     $path = $this->getDataFolder() . $d . "/" . $n . ".yml";
     if (!is_file($path)) {
         return false;
     }
     $cfg = new Config($path, Config::YAML);
     $yaml = $cfg->getAll();
     if ($this->isGlobal) {
         $ln = "*";
     } else {
         $ln = trim(strtolower($player->getLevel()->getName()));
     }
     if (!isset($yaml[$ln])) {
         return false;
     }
     $inv->clearAll();
     foreach ($yaml[$ln] as $slot => $t) {
         list($id, $dam, $cnt) = explode(":", $t);
         $item = Item::get($id, $dam, $cnt);
         $inv->setItem($slot, $item);
     }
     return true;
 }