public function setHeldItemSlot($slot)
 {
     if ($slot >= -1 and $slot < $this->getSize()) {
         $item = $this->getItem($slot);
         if ($this->getHolder() instanceof Player) {
             Server::getInstance()->getPluginManager()->callEvent($ev = new PlayerItemHeldEvent($this->getHolder(), $item, $slot, $this->itemInHandIndex));
             if ($ev->isCancelled()) {
                 $this->sendHeldItem($this->getHolder());
                 return;
             }
         }
         $this->setHotbarSlotIndex($this->itemInHandIndex, $slot);
         $this->sendHeldItem($this->getHolder()->getViewers());
     }
 }
Example #2
0
 /**
  * @priority MONITOR
  */
 public function onItemHeld(PlayerItemHeldEvent $event)
 {
     $player = $event->getPlayer();
     $item = $event->getItem();
     if ($player->isCreative()) {
         return;
     }
     if (!$this->isAllowedWorld($player->getLevel())) {
         return;
     }
     if ($event->isCancelled() || $this->auth !== null && !$this->auth->isPlayerAuthenticated($player)) {
         return;
     }
     foreach ($this->getConfig()->get("data") as $slot => $g) {
         if ($item->getId() === $g["id"] && $item->getDamage() === $g["damage"]) {
             foreach ($g["command"] as $cmd) {
                 $popup = $g["popup"];
                 $player->sendPopup($popup);
                 if (!empty($cmd)) {
                     $this->getServer()->dispatchCommand(new ConsoleCommandSender(), str_replace("{player}", $player->getName(), str_replace("/", "", $cmd)));
                 }
             }
         }
     }
 }
Example #3
0
 /**
  * @param int  $hotbarSlotIndex
  * @param bool $sendToHolder
  * @param int  $slotMapping
  *
  * Sets which hotbar slot the player is currently holding.
  * Allows slot remapping as specified by a MobEquipmentPacket. DO NOT CHANGE SLOT MAPPING IN PLUGINS!
  * This new implementation is fully compatible with older APIs.
  * NOTE: Slot mapping is the raw slot index sent by MCPE, which will be between 9 and 44.
  */
 public function setHeldItemIndex($hotbarSlotIndex, $sendToHolder = true, $slotMapping = null)
 {
     if ($slotMapping !== null) {
         //Get the index of the slot in the actual inventory
         $slotMapping -= $this->getHotbarSize();
     }
     if (0 <= $hotbarSlotIndex and $hotbarSlotIndex < $this->getHotbarSize()) {
         $this->itemInHandIndex = $hotbarSlotIndex;
         if ($slotMapping !== null) {
             /* Handle a hotbar slot mapping change. This allows PE to select different inventory slots.
              * This is the only time slot mapping should ever be changed. */
             if ($slotMapping < 0 or $slotMapping >= $this->getSize()) {
                 //Mapping was not in range of the inventory, set it to -1
                 //This happens if the client selected a blank slot (sends 255)
                 $slotMapping = -1;
             }
             $item = $this->getItem($slotMapping);
             if ($this->getHolder() instanceof Player) {
                 Server::getInstance()->getPluginManager()->callEvent($ev = new PlayerItemHeldEvent($this->getHolder(), $item, $slotMapping, $hotbarSlotIndex));
                 if ($ev->isCancelled()) {
                     $this->sendHeldItem($this->getHolder());
                     $this->sendContents($this->getHolder());
                     return;
                 }
             }
             if (($key = array_search($slotMapping, $this->hotbar)) !== false and $slotMapping !== -1) {
                 /* Do not do slot swaps if the slot was null
                  * Chosen slot is already linked to a hotbar slot, swap the two slots around.
                  * This will already have been done on the client-side so no changes need to be sent. */
                 $this->hotbar[$key] = $this->hotbar[$this->itemInHandIndex];
             }
             $this->hotbar[$this->itemInHandIndex] = $slotMapping;
         }
         $this->sendHeldItem($this->getHolder()->getViewers());
         if ($sendToHolder) {
             $this->sendHeldItem($this->getHolder());
         }
     }
 }
 public function setHeldItemSlot($slot)
 {
     if ($slot >= -1 and $slot < $this->getSize()) {
         $item = $this->getItem($slot);
         $itemIndex = $this->getHeldItemIndex();
         if ($this->getHolder() instanceof Player) {
             Server::getInstance()->getPluginManager()->callEvent($ev = new PlayerItemHeldEvent($this->getHolder(), $item, $slot, $itemIndex));
             if ($ev->isCancelled()) {
                 $this->sendContents($this->getHolder());
                 return;
             }
             if ($this->getHolder()->fishingHook instanceof FishingHook) {
                 $this->getHolder()->fishingHook->close();
             }
         }
         $this->setHotbarSlotIndex($itemIndex, $slot);
     }
 }
Example #5
-1
 public function onItemHeld(PlayerItemHeldEvent $e)
 {
     if ($e->isCancelled()) {
         return;
     }
     $p = $e->getPlayer();
     $n = $p->getName();
     //echo __METHOD__.",".__LINE__."\n";//##DEBUG
     if ($e->getItem()->getID() == Item::BOW) {
         return;
     }
     //echo __METHOD__.",".__LINE__."\n";//##DEBUG
     if (isset($this->shooters[$n])) {
         unset($this->shooters[$n]);
         $p->sendMessage("Disarming RPG");
     }
     if (isset($this->dumdums[$n])) {
         unset($this->dumdums[$n]);
         $p->sendMessage("Unloading dumdums");
     }
 }
Example #6
-1
 public function setHeldItemSlot($slot)
 {
     if ($slot >= -1 and $slot < $this->getSize()) {
         $item = $this->getItem($slot);
         $itemIndex = $this->getHeldItemIndex();
         for ($i = 0; $i < $this->getHotbarSize(); ++$i) {
             if ($this->getHotbarSlotIndex($i) === $slot) {
                 $itemIndex = $i;
                 break;
             }
         }
         if ($this->getHolder() instanceof Player) {
             Server::getInstance()->getPluginManager()->callEvent($ev = new PlayerItemHeldEvent($this->getHolder(), $item, $slot, $itemIndex));
             if ($ev->isCancelled()) {
                 $this->sendHeldItem($this->getHolder());
                 return;
             }
         }
         $this->setHotbarSlotIndex($itemIndex, $slot);
         $this->setHeldItemIndex($itemIndex);
     }
 }