Inventory: remove redundant return values

This commit is contained in:
Dylan K. Taylor 2019-05-20 16:30:00 +01:00
parent c21a25efb9
commit d6ce3f82b1
7 changed files with 29 additions and 58 deletions

View File

@ -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);
}
}

View File

@ -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{

View File

@ -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();
}
/**

View File

@ -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{

View File

@ -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);
}
}

View File

@ -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

View File

@ -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());
}
/**