PlayerInventory: fix type violation when calling equipItem() for non-Player holder

This commit is contained in:
Dylan K. Taylor 2019-12-12 16:31:22 +00:00
parent 919534d978
commit 9a4b72add5

View File

@ -66,19 +66,23 @@ class PlayerInventory extends BaseInventory{
* @return bool if the equipment change was successful, false if not. * @return bool if the equipment change was successful, false if not.
*/ */
public function equipItem(int $hotbarSlot) : bool{ public function equipItem(int $hotbarSlot) : bool{
$holder = $this->getHolder();
if(!$this->isHotbarSlot($hotbarSlot)){ if(!$this->isHotbarSlot($hotbarSlot)){
$this->sendContents($this->getHolder()); if($holder instanceof Player){
$this->sendContents($holder);
}
return false; return false;
} }
$ev = new PlayerItemHeldEvent($this->getHolder(), $this->getItem($hotbarSlot), $hotbarSlot); if($holder instanceof Player){
$ev = new PlayerItemHeldEvent($holder, $this->getItem($hotbarSlot), $hotbarSlot);
$ev->call(); $ev->call();
if($ev->isCancelled()){ if($ev->isCancelled()){
$this->sendHeldItem($this->getHolder()); $this->sendHeldItem($holder);
return false; return false;
} }
}
$this->setHeldItemIndex($hotbarSlot, false); $this->setHeldItemIndex($hotbarSlot, false);
return true; return true;