and more typehints

This commit is contained in:
Dylan K. Taylor
2017-07-14 10:56:51 +01:00
parent b9355387da
commit c3b8be3f60
119 changed files with 598 additions and 541 deletions

View File

@ -84,32 +84,32 @@ abstract class BaseInventory implements Inventory{
$this->slots = [];
}
public function getSize(){
public function getSize() : int{
return $this->size;
}
public function setSize($size){
$this->size = (int) $size;
public function setSize(int $size){
$this->size = $size;
}
public function getMaxStackSize(){
public function getMaxStackSize() : int{
return $this->maxStackSize;
}
public function getName(){
public function getName() : string{
return $this->name;
}
public function getTitle(){
public function getTitle() : string{
return $this->title;
}
public function getItem($index){
public function getItem(int $index) : Item{
assert($index >= 0, "Inventory slot should not be negative");
return isset($this->slots[$index]) ? clone $this->slots[$index] : Item::get(Item::AIR, 0, 0);
}
public function getContents(){
public function getContents() : array{
return $this->slots;
}
@ -134,7 +134,7 @@ abstract class BaseInventory implements Inventory{
}
}
public function setItem($index, Item $item){
public function setItem(int $index, Item $item) : bool{
$item = clone $item;
if($index < 0 or $index >= $this->size){
return false;
@ -159,7 +159,7 @@ abstract class BaseInventory implements Inventory{
return true;
}
public function contains(Item $item){
public function contains(Item $item) : bool{
$count = max(1, $item->getCount());
$checkDamage = !$item->hasAnyDamageValue();
$checkTags = $item->hasCompoundTag();
@ -175,7 +175,7 @@ abstract class BaseInventory implements Inventory{
return false;
}
public function all(Item $item){
public function all(Item $item) : array{
$slots = [];
$checkDamage = !$item->hasAnyDamageValue();
$checkTags = $item->hasCompoundTag();
@ -199,7 +199,7 @@ abstract class BaseInventory implements Inventory{
}
}
public function first(Item $item){
public function first(Item $item) : int{
$count = max(1, $item->getCount());
$checkDamage = !$item->hasAnyDamageValue();
$checkTags = $item->hasCompoundTag();
@ -213,7 +213,7 @@ abstract class BaseInventory implements Inventory{
return -1;
}
public function firstEmpty(){
public function firstEmpty() : int{
for($i = 0; $i < $this->size; ++$i){
if($this->getItem($i)->getId() === Item::AIR){
return $i;
@ -223,7 +223,7 @@ abstract class BaseInventory implements Inventory{
return -1;
}
public function canAddItem(Item $item){
public function canAddItem(Item $item) : bool{
$item = clone $item;
$checkDamage = !$item->hasAnyDamageValue();
$checkTags = $item->hasCompoundTag();
@ -245,7 +245,7 @@ abstract class BaseInventory implements Inventory{
return false;
}
public function addItem(Item ...$slots){
public function addItem(Item ...$slots) : array{
/** @var Item[] $itemSlots */
/** @var Item[] $slots */
$itemSlots = [];
@ -302,7 +302,7 @@ abstract class BaseInventory implements Inventory{
return $itemSlots;
}
public function removeItem(Item ...$slots){
public function removeItem(Item ...$slots) : array{
/** @var Item[] $itemSlots */
/** @var Item[] $slots */
$itemSlots = [];
@ -338,7 +338,7 @@ abstract class BaseInventory implements Inventory{
return $itemSlots;
}
public function clear($index){
public function clear(int $index) : bool{
if(isset($this->slots[$index])){
$item = Item::get(Item::AIR, 0, 0);
$old = $this->slots[$index];
@ -372,7 +372,7 @@ abstract class BaseInventory implements Inventory{
/**
* @return Player[]
*/
public function getViewers(){
public function getViewers() : array{
return $this->viewers;
}
@ -380,11 +380,11 @@ abstract class BaseInventory implements Inventory{
return $this->holder;
}
public function setMaxStackSize($size){
$this->maxStackSize = (int) $size;
public function setMaxStackSize(int $size){
$this->maxStackSize = $size;
}
public function open(Player $who){
public function open(Player $who) : bool{
$who->getServer()->getPluginManager()->callEvent($ev = new InventoryOpenEvent($this, $who));
if($ev->isCancelled()){
return false;
@ -459,7 +459,7 @@ abstract class BaseInventory implements Inventory{
}
}
public function getType(){
public function getType() : InventoryType{
return $this->type;
}