getPlayer() публичный Метод

public getPlayer ( ) : Player
Результат pocketmine\Player
Пример #1
1
 /**
  * Close inventory event
  *
  * @param InventoryCloseEvent $ev
  */
 public function onClose(InventoryCloseEvent $ev)
 {
     $pl = $ev->getPlayer();
     $xx = $this->getState(self::tag, $pl, null);
     if ($xx == null) {
         return;
     }
     // Compute shopping basket
     $basket = [];
     $total = 0;
     foreach ($pl->getInventory()->getContents() as $slot => $item) {
         if ($item->getId() == Item::AIR) {
             continue;
         }
         $idmeta = implode(":", [$item->getId(), $item->getDamage()]);
         if (!isset($xx["shop"][$idmeta])) {
             continue;
         }
         list($i, $price) = $xx["shop"][$idmeta];
         $total += round($item->getCount() / $i->getCount()) * $price;
         $basket[] = [$item->getId(), $item->getDamage(), $item->getCount()];
     }
     // Restore original inventory...
     $this->restoreInv($pl);
     // Check-out
     if (count($basket) == 0) {
         $pl->sendMessage(mc::_("No items purchased"));
         return;
     }
     if ($total < $this->owner->getMoney($pl)) {
         $this->owner->grantMoney($pl, -$total);
         $pl->sendMessage(mc::n(mc::_("Bought one item for %1%G", $total), mc::_("Bought %1% items for %2%G", count($basket), $total), count($basket)));
         foreach ($basket as $ck) {
             list($id, $meta, $cnt) = $ck;
             $pl->getInventory()->addItem(Item::get($id, $meta, $cnt));
         }
     } else {
         $pl->sendMessage(mc::_("Not enough money."));
         $pl->sendMessage(mc::_("You need %1%G", $total));
     }
 }
Пример #2
0
 public function onClose(InventoryCloseEvent $ev)
 {
     echo __METHOD__ . "," . __LINE__ . "\n";
     $pl = $ev->getPlayer();
     $xx = $this->getState("trade-inv", $pl, null);
     if ($xx == null) {
         return;
     }
     // Compute shopping basket
     $basket = [];
     $total = 0;
     foreach ($pl->getInventory()->getContents() as $slot => $item) {
         if ($item->getId() == Item::AIR) {
             continue;
         }
         $idmeta = implode(":", [$item->getId(), $item->getDamage()]);
         if (!isset($this->keepers[$xx["shop"]]["items"][$idmeta])) {
             continue;
         }
         list($i, $price) = $this->keepers[$xx["shop"]]["items"][$idmeta];
         $total += round($item->getCount() / $i->getCount()) * $price;
         $basket[] = [$item->getId(), $item->getDamage(), $item->getCount()];
     }
     // Restore original inventory...
     $this->restoreInv($pl);
     // Check-out
     if (count($basket) == 0) {
         $this->shopMsg($pl, $xx["shop"], "next-time");
         return;
     }
     if ($total < $this->owner->getMoney($pl)) {
         $this->owner->grantMoney($pl, -$total);
         if (count($basket) == 1) {
             $this->shopMsg($pl, $xx["shop"], "bought-items1", $total, count($basket));
         } else {
             $this->shopMsg($pl, $xx["shop"], "bought-itemsX", $total, count($basket));
         }
         foreach ($basket as $ck) {
             list($id, $meta, $cnt) = $ck;
             $pl->getInventory()->addItem(Item::get($id, $meta, $cnt));
         }
         $this->shopMsg($pl, $xx["shop"], "thank-you", $total, count($basket));
     } else {
         $this->shopMsg($pl, $xx["shop"], "no-money", $total, count($basket));
     }
 }
Пример #3
0
 public function onInventoryCloseEvent(InventoryCloseEvent $ev)
 {
     $player = $ev->getPlayer();
     $inv = $ev->getInventory();
     if (!$this->isNeChest($inv)) {
         return;
     }
     if ($this->unlockChest($player, $inv)) {
         $player->sendMessage(mc::_("Closing NetherChest!"));
         $this->saveInventory($player, $inv);
     }
 }
Пример #4
0
 public function onClose(InventoryCloseEvent $event)
 {
     $Player = $event->getPlayer();
     $this->plugin->unsetState("buying_chest", $Player);
 }
Пример #5
0
 public function onInvClose(InventoryCloseEvent $event)
 {
     $inventory = $event->getInventory();
     if ($inventory instanceof ChestInventory) {
         $config = new Config($this->getDataFolder() . "shop.yml", Config::YAML);
         $all = $config->get("Shop");
         $realChest = $inventory->getHolder();
         $first = $all[0];
         $second = $all[2];
         if ($inventory->getItem(0)->getId() == $first && $inventory->getItem(1)->getId() == $second || $inventory->getItem(1)->getId() == 384) {
             $event->getPlayer()->getLevel()->setBlock(new Vector3($realChest->getX(), $realChest->getY(), $realChest->getZ()), Block::get(Block::AIR));
             $this->isShopping[$event->getPlayer()->getName()] = "nein";
         }
     }
 }