Unwrap more code from packet handlers

This commit is contained in:
Dylan K. Taylor
2018-07-20 18:48:46 +01:00
parent 015ee90571
commit 30c044f028
3 changed files with 24 additions and 55 deletions

View File

@@ -24,7 +24,6 @@ declare(strict_types=1);
namespace pocketmine\inventory;
use pocketmine\entity\Human;
use pocketmine\event\player\PlayerItemHeldEvent;
use pocketmine\item\Item;
use pocketmine\network\mcpe\protocol\InventoryContentPacket;
use pocketmine\network\mcpe\protocol\MobEquipmentPacket;
@@ -55,33 +54,7 @@ class PlayerInventory extends BaseInventory{
return 36;
}
/**
* Called when a client equips a hotbar slot. This method should not be used by plugins.
* This method will call PlayerItemHeldEvent.
*
* @param int $hotbarSlot Number of the hotbar slot to equip.
*
* @return bool if the equipment change was successful, false if not.
*/
public function equipItem(int $hotbarSlot) : bool{
if(!$this->isHotbarSlot($hotbarSlot)){
$this->sendContents($this->getHolder());
return false;
}
$this->getHolder()->getLevel()->getServer()->getPluginManager()->callEvent($ev = new PlayerItemHeldEvent($this->getHolder(), $this->getItem($hotbarSlot), $hotbarSlot));
if($ev->isCancelled()){
$this->sendHeldItem($this->getHolder());
return false;
}
$this->setHeldItemIndex($hotbarSlot, false);
return true;
}
private function isHotbarSlot(int $slot) : bool{
public function isHotbarSlot(int $slot) : bool{
return $slot >= 0 and $slot <= $this->getHotbarSize();
}