From d6ce3f82b1a7d75ceccc811e80d3dd76df58a345 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 20 May 2019 16:30:00 +0100 Subject: [PATCH] Inventory: remove redundant return values --- src/pocketmine/inventory/ArmorInventory.php | 16 ++++++++-------- src/pocketmine/inventory/BaseInventory.php | 12 ++++-------- src/pocketmine/inventory/CraftingGrid.php | 11 +++-------- .../inventory/DoubleChestInventory.php | 9 +++------ src/pocketmine/inventory/FurnaceInventory.php | 18 ++++++------------ src/pocketmine/inventory/Inventory.php | 9 ++------- src/pocketmine/inventory/PlayerInventory.php | 12 +++--------- 7 files changed, 29 insertions(+), 58 deletions(-) diff --git a/src/pocketmine/inventory/ArmorInventory.php b/src/pocketmine/inventory/ArmorInventory.php index 3643f1d64..82d8c2e14 100644 --- a/src/pocketmine/inventory/ArmorInventory.php +++ b/src/pocketmine/inventory/ArmorInventory.php @@ -60,19 +60,19 @@ class ArmorInventory extends BaseInventory{ return $this->getItem(self::SLOT_FEET); } - public function setHelmet(Item $helmet) : bool{ - return $this->setItem(self::SLOT_HEAD, $helmet); + public function setHelmet(Item $helmet) : void{ + $this->setItem(self::SLOT_HEAD, $helmet); } - public function setChestplate(Item $chestplate) : bool{ - return $this->setItem(self::SLOT_CHEST, $chestplate); + public function setChestplate(Item $chestplate) : void{ + $this->setItem(self::SLOT_CHEST, $chestplate); } - public function setLeggings(Item $leggings) : bool{ - return $this->setItem(self::SLOT_LEGS, $leggings); + public function setLeggings(Item $leggings) : void{ + $this->setItem(self::SLOT_LEGS, $leggings); } - public function setBoots(Item $boots) : bool{ - return $this->setItem(self::SLOT_FEET, $boots); + public function setBoots(Item $boots) : void{ + $this->setItem(self::SLOT_FEET, $boots); } } diff --git a/src/pocketmine/inventory/BaseInventory.php b/src/pocketmine/inventory/BaseInventory.php index a58001cb1..9f46d8a05 100644 --- a/src/pocketmine/inventory/BaseInventory.php +++ b/src/pocketmine/inventory/BaseInventory.php @@ -117,9 +117,7 @@ abstract class BaseInventory implements Inventory{ $this->clear($i, false); } }else{ - if(!$this->setItem($i, $items[$i], false)){ - $this->clear($i, false); - } + $this->setItem($i, $items[$i], false); } } @@ -134,7 +132,7 @@ abstract class BaseInventory implements Inventory{ } } - public function setItem(int $index, Item $item, bool $send = true) : bool{ + public function setItem(int $index, Item $item, bool $send = true) : void{ if($item->isNull()){ $item = ItemFactory::air(); }else{ @@ -145,8 +143,6 @@ abstract class BaseInventory implements Inventory{ $this->slots[$index] = $item->isNull() ? null : $item; $this->onSlotChange($index, $oldItem, $send); - - return true; } public function contains(Item $item) : bool{ @@ -330,8 +326,8 @@ abstract class BaseInventory implements Inventory{ return $itemSlots; } - public function clear(int $index, bool $send = true) : bool{ - return $this->setItem($index, ItemFactory::air(), $send); + public function clear(int $index, bool $send = true) : void{ + $this->setItem($index, ItemFactory::air(), $send); } public function clearAll(bool $send = true) : void{ diff --git a/src/pocketmine/inventory/CraftingGrid.php b/src/pocketmine/inventory/CraftingGrid.php index 8aa45a65d..2cdabff19 100644 --- a/src/pocketmine/inventory/CraftingGrid.php +++ b/src/pocketmine/inventory/CraftingGrid.php @@ -61,14 +61,9 @@ class CraftingGrid extends BaseInventory{ throw new \BadMethodCallException("Cannot change the size of a crafting grid"); } - public function setItem(int $index, Item $item, bool $send = true) : bool{ - if(parent::setItem($index, $item, $send)){ - $this->seekRecipeBounds(); - - return true; - } - - return false; + public function setItem(int $index, Item $item, bool $send = true) : void{ + parent::setItem($index, $item, $send); + $this->seekRecipeBounds(); } /** diff --git a/src/pocketmine/inventory/DoubleChestInventory.php b/src/pocketmine/inventory/DoubleChestInventory.php index 51a46e8c4..2eb0a9f6f 100644 --- a/src/pocketmine/inventory/DoubleChestInventory.php +++ b/src/pocketmine/inventory/DoubleChestInventory.php @@ -58,13 +58,10 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{ return $index < $this->left->getSize() ? $this->left->getItem($index) : $this->right->getItem($index - $this->left->getSize()); } - public function setItem(int $index, Item $item, bool $send = true) : bool{ + public function setItem(int $index, Item $item, bool $send = true) : void{ $old = $this->getItem($index); - if($index < $this->left->getSize() ? $this->left->setItem($index, $item, $send) : $this->right->setItem($index - $this->left->getSize(), $item, $send)){ - $this->onSlotChange($index, $old, $send); - return true; - } - return false; + $index < $this->left->getSize() ? $this->left->setItem($index, $item, $send) : $this->right->setItem($index - $this->left->getSize(), $item, $send); + $this->onSlotChange($index, $old, $send); } public function getContents(bool $includeEmpty = false) : array{ diff --git a/src/pocketmine/inventory/FurnaceInventory.php b/src/pocketmine/inventory/FurnaceInventory.php index 79a400c06..24699a7f0 100644 --- a/src/pocketmine/inventory/FurnaceInventory.php +++ b/src/pocketmine/inventory/FurnaceInventory.php @@ -70,28 +70,22 @@ class FurnaceInventory extends ContainerInventory{ /** * @param Item $item - * - * @return bool */ - public function setResult(Item $item) : bool{ - return $this->setItem(2, $item); + public function setResult(Item $item) : void{ + $this->setItem(2, $item); } /** * @param Item $item - * - * @return bool */ - public function setFuel(Item $item) : bool{ - return $this->setItem(1, $item); + public function setFuel(Item $item) : void{ + $this->setItem(1, $item); } /** * @param Item $item - * - * @return bool */ - public function setSmelting(Item $item) : bool{ - return $this->setItem(0, $item); + public function setSmelting(Item $item) : void{ + $this->setItem(0, $item); } } diff --git a/src/pocketmine/inventory/Inventory.php b/src/pocketmine/inventory/Inventory.php index a27a8525c..8260b5943 100644 --- a/src/pocketmine/inventory/Inventory.php +++ b/src/pocketmine/inventory/Inventory.php @@ -56,15 +56,12 @@ interface Inventory{ /** * Puts an Item in a slot. - * If a plugin refuses the update or $index is invalid, it'll return false * * @param int $index * @param Item $item * @param bool $send - * - * @return bool */ - public function setItem(int $index, Item $item, bool $send = true) : bool; + public function setItem(int $index, Item $item, bool $send = true) : void; /** * Stores the given Items in the inventory. This will try to fill @@ -182,10 +179,8 @@ interface Inventory{ * * @param int $index * @param bool $send - * - * @return bool */ - public function clear(int $index, bool $send = true) : bool; + public function clear(int $index, bool $send = true) : void; /** * Clears all the slots diff --git a/src/pocketmine/inventory/PlayerInventory.php b/src/pocketmine/inventory/PlayerInventory.php index e6b93a44c..8d91a5c15 100644 --- a/src/pocketmine/inventory/PlayerInventory.php +++ b/src/pocketmine/inventory/PlayerInventory.php @@ -119,16 +119,10 @@ class PlayerInventory extends BaseInventory{ * Sets the item in the currently-held slot to the specified item. * * @param Item $item - * - * @return bool */ - public function setItemInHand(Item $item) : bool{ - if($this->setItem($this->getHeldItemIndex(), $item)){ - $this->sendHeldItem($this->holder->getViewers()); - return true; - } - - return false; + public function setItemInHand(Item $item) : void{ + $this->setItem($this->getHeldItemIndex(), $item); + $this->sendHeldItem($this->holder->getViewers()); } /**