null and void typehints

This commit is contained in:
Dylan K. Taylor
2017-09-21 12:54:04 +01:00
parent d89b8cf12e
commit f01ce8e994
21 changed files with 56 additions and 56 deletions

View File

@ -56,7 +56,7 @@ class AnvilInventory extends ContainerInventory{
return $this->holder; return $this->holder;
} }
public function onClose(Player $who){ public function onClose(Player $who) : void{
parent::onClose($who); parent::onClose($who);
for($i = 0; $i < 2; ++$i){ for($i = 0; $i < 2; ++$i){

View File

@ -106,7 +106,7 @@ abstract class BaseInventory implements Inventory{
* @param Item[] $items * @param Item[] $items
* @param bool $send * @param bool $send
*/ */
public function setContents(array $items, bool $send = true){ public function setContents(array $items, bool $send = true) : void{
if(count($items) > $this->getSize()){ if(count($items) > $this->getSize()){
$items = array_slice($items, 0, $this->getSize(), true); $items = array_slice($items, 0, $this->getSize(), true);
} }
@ -180,7 +180,7 @@ abstract class BaseInventory implements Inventory{
return $slots; return $slots;
} }
public function remove(Item $item){ public function remove(Item $item) : void{
$checkDamage = !$item->hasAnyDamageValue(); $checkDamage = !$item->hasAnyDamageValue();
$checkTags = $item->hasCompoundTag(); $checkTags = $item->hasCompoundTag();
@ -334,7 +334,7 @@ abstract class BaseInventory implements Inventory{
return $this->setItem($index, ItemFactory::get(Item::AIR, 0, 0), $send); return $this->setItem($index, ItemFactory::get(Item::AIR, 0, 0), $send);
} }
public function clearAll(){ public function clearAll() : void{
for($i = 0, $size = $this->getSize(); $i < $size; ++$i){ for($i = 0, $size = $this->getSize(); $i < $size; ++$i){
$this->clear($i, false); $this->clear($i, false);
} }
@ -353,7 +353,7 @@ abstract class BaseInventory implements Inventory{
return $this->holder; return $this->holder;
} }
public function setMaxStackSize(int $size){ public function setMaxStackSize(int $size) : void{
$this->maxStackSize = $size; $this->maxStackSize = $size;
} }
@ -367,19 +367,19 @@ abstract class BaseInventory implements Inventory{
return true; return true;
} }
public function close(Player $who){ public function close(Player $who) : void{
$this->onClose($who); $this->onClose($who);
} }
public function onOpen(Player $who){ public function onOpen(Player $who) : void{
$this->viewers[spl_object_hash($who)] = $who; $this->viewers[spl_object_hash($who)] = $who;
} }
public function onClose(Player $who){ public function onClose(Player $who) : void{
unset($this->viewers[spl_object_hash($who)]); unset($this->viewers[spl_object_hash($who)]);
} }
public function onSlotChange(int $index, Item $before, bool $send){ public function onSlotChange(int $index, Item $before, bool $send) : void{
if($send){ if($send){
$this->sendSlot($index, $this->getViewers()); $this->sendSlot($index, $this->getViewers());
} }
@ -389,7 +389,7 @@ abstract class BaseInventory implements Inventory{
/** /**
* @param Player|Player[] $target * @param Player|Player[] $target
*/ */
public function sendContents($target){ public function sendContents($target) : void{
if($target instanceof Player){ if($target instanceof Player){
$target = [$target]; $target = [$target];
} }
@ -415,7 +415,7 @@ abstract class BaseInventory implements Inventory{
* @param int $index * @param int $index
* @param Player|Player[] $target * @param Player|Player[] $target
*/ */
public function sendSlot(int $index, $target){ public function sendSlot(int $index, $target) : void{
if($target instanceof Player){ if($target instanceof Player){
$target = [$target]; $target = [$target];
} }

View File

@ -62,7 +62,7 @@ class ChestInventory extends ContainerInventory{
return $this->holder; return $this->holder;
} }
public function onOpen(Player $who){ public function onOpen(Player $who) : void{
parent::onOpen($who); parent::onOpen($who);
if(count($this->getViewers()) === 1 and ($level = $this->getHolder()->getLevel()) instanceof Level){ if(count($this->getViewers()) === 1 and ($level = $this->getHolder()->getLevel()) instanceof Level){
@ -71,7 +71,7 @@ class ChestInventory extends ContainerInventory{
} }
} }
public function onClose(Player $who){ public function onClose(Player $who) : void{
if(count($this->getViewers()) === 1 and ($level = $this->getHolder()->getLevel()) instanceof Level){ if(count($this->getViewers()) === 1 and ($level = $this->getHolder()->getLevel()) instanceof Level){
$this->broadcastBlockEventPacket(1, 0); //chest close $this->broadcastBlockEventPacket(1, 0); //chest close
$level->broadcastLevelSoundEvent($this->getHolder()->add(0.5, 0.5, 0.5), LevelSoundEventPacket::SOUND_CHEST_CLOSED); $level->broadcastLevelSoundEvent($this->getHolder()->add(0.5, 0.5, 0.5), LevelSoundEventPacket::SOUND_CHEST_CLOSED);

View File

@ -29,7 +29,7 @@ use pocketmine\network\mcpe\protocol\ContainerOpenPacket;
use pocketmine\Player; use pocketmine\Player;
abstract class ContainerInventory extends BaseInventory{ abstract class ContainerInventory extends BaseInventory{
public function onOpen(Player $who){ public function onOpen(Player $who) : void{
parent::onOpen($who); parent::onOpen($who);
$pk = new ContainerOpenPacket(); $pk = new ContainerOpenPacket();
$pk->windowId = $who->getWindowId($this); $pk->windowId = $who->getWindowId($this);
@ -48,7 +48,7 @@ abstract class ContainerInventory extends BaseInventory{
$this->sendContents($who); $this->sendContents($who);
} }
public function onClose(Player $who){ public function onClose(Player $who) : void{
$pk = new ContainerClosePacket(); $pk = new ContainerClosePacket();
$pk->windowId = $who->getWindowId($this); $pk->windowId = $who->getWindowId($this);
$who->dataPacket($pk); $who->dataPacket($pk);

View File

@ -43,11 +43,11 @@ class CraftingGrid extends BaseInventory{
return "Crafting"; return "Crafting";
} }
public function sendSlot(int $index, $target){ public function sendSlot(int $index, $target) : void{
//we can't send a slot of a client-sided inventory window //we can't send a slot of a client-sided inventory window
} }
public function sendContents($target){ public function sendContents($target) : void{
//we can't send the contents of a client-sided inventory window //we can't send the contents of a client-sided inventory window
} }
} }

View File

@ -92,7 +92,7 @@ class CraftingManager{
/** /**
* Rebuilds the cached CraftingDataPacket. * Rebuilds the cached CraftingDataPacket.
*/ */
public function buildCraftingDataCache(){ public function buildCraftingDataCache() : void{
Timings::$craftingDataCacheRebuildTimer->startTiming(); Timings::$craftingDataCacheRebuildTimer->startTiming();
$pk = new CraftingDataPacket(); $pk = new CraftingDataPacket();
$pk->cleanRecipes = true; $pk->cleanRecipes = true;
@ -150,7 +150,7 @@ class CraftingManager{
* @param UUID $id * @param UUID $id
* @return CraftingRecipe|null * @return CraftingRecipe|null
*/ */
public function getRecipe(UUID $id){ public function getRecipe(UUID $id) : ?CraftingRecipe{
$index = $id->toBinary(); $index = $id->toBinary();
return $this->recipes[$index] ?? null; return $this->recipes[$index] ?? null;
} }
@ -181,7 +181,7 @@ class CraftingManager{
/** /**
* @param ShapedRecipe $recipe * @param ShapedRecipe $recipe
*/ */
public function registerShapedRecipe(ShapedRecipe $recipe){ public function registerShapedRecipe(ShapedRecipe $recipe) : void{
$result = $recipe->getResult(); $result = $recipe->getResult();
/** @var Item[][] $ingredients */ /** @var Item[][] $ingredients */
@ -205,7 +205,7 @@ class CraftingManager{
/** /**
* @param ShapelessRecipe $recipe * @param ShapelessRecipe $recipe
*/ */
public function registerShapelessRecipe(ShapelessRecipe $recipe){ public function registerShapelessRecipe(ShapelessRecipe $recipe) : void{
$result = $recipe->getResult(); $result = $recipe->getResult();
$hash = ""; $hash = "";
$ingredients = $recipe->getIngredientList(); $ingredients = $recipe->getIngredientList();
@ -220,7 +220,7 @@ class CraftingManager{
/** /**
* @param FurnaceRecipe $recipe * @param FurnaceRecipe $recipe
*/ */
public function registerFurnaceRecipe(FurnaceRecipe $recipe){ public function registerFurnaceRecipe(FurnaceRecipe $recipe) : void{
$input = $recipe->getInput(); $input = $recipe->getInput();
$this->furnaceRecipes[$input->getId() . ":" . ($input->hasAnyDamageValue() ? "?" : $input->getDamage())] = $recipe; $this->furnaceRecipes[$input->getId() . ":" . ($input->hasAnyDamageValue() ? "?" : $input->getDamage())] = $recipe;
$this->craftingDataCache = null; $this->craftingDataCache = null;
@ -287,7 +287,7 @@ class CraftingManager{
/** /**
* @param Recipe $recipe * @param Recipe $recipe
*/ */
public function registerRecipe(Recipe $recipe){ public function registerRecipe(Recipe $recipe) : void{
if($recipe instanceof CraftingRecipe){ if($recipe instanceof CraftingRecipe){
$result = $recipe->getResult(); $result = $recipe->getResult();
$recipe->setId($uuid = UUID::fromData((string) ++self::$RECIPE_COUNT, (string) $result->getId(), (string) $result->getDamage(), (string) $result->getCount(), $result->getCompoundTag())); $recipe->setId($uuid = UUID::fromData((string) ++self::$RECIPE_COUNT, (string) $result->getId(), (string) $result->getDamage(), (string) $result->getCount(), $result->getCompoundTag()));

View File

@ -31,7 +31,7 @@ interface CraftingRecipe extends Recipe{
/** /**
* @return UUID|null * @return UUID|null
*/ */
public function getId(); public function getId() : ?UUID;
/** /**
* @param UUID $id * @param UUID $id

View File

@ -86,7 +86,7 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{
* @param Item[] $items * @param Item[] $items
* @param bool $send * @param bool $send
*/ */
public function setContents(array $items, bool $send = true){ public function setContents(array $items, bool $send = true) : void{
$size = $this->getSize(); $size = $this->getSize();
if(count($items) > $size){ if(count($items) > $size){
$items = array_slice($items, 0, $size, true); $items = array_slice($items, 0, $size, true);
@ -109,7 +109,7 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{
} }
} }
public function onOpen(Player $who){ public function onOpen(Player $who) : void{
parent::onOpen($who); parent::onOpen($who);
if(count($this->getViewers()) === 1){ if(count($this->getViewers()) === 1){
@ -125,7 +125,7 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{
} }
} }
public function onClose(Player $who){ public function onClose(Player $who) : void{
if(count($this->getViewers()) === 1){ if(count($this->getViewers()) === 1){
$pk = new BlockEventPacket(); $pk = new BlockEventPacket();
$pk->x = $this->right->getHolder()->getX(); $pk->x = $this->right->getHolder()->getX();

View File

@ -56,7 +56,7 @@ class EnchantInventory extends ContainerInventory{
return $this->holder; return $this->holder;
} }
public function onClose(Player $who){ public function onClose(Player $who) : void{
parent::onClose($who); parent::onClose($who);
for($i = 0; $i < 2; ++$i){ for($i = 0; $i < 2; ++$i){

View File

@ -103,7 +103,7 @@ class FurnaceInventory extends ContainerInventory{
return $this->setItem(0, $item); return $this->setItem(0, $item);
} }
public function onSlotChange(int $index, Item $before, bool $send){ public function onSlotChange(int $index, Item $before, bool $send) : void{
parent::onSlotChange($index, $before, $send); parent::onSlotChange($index, $before, $send);
$this->getHolder()->scheduleUpdate(); $this->getHolder()->scheduleUpdate();

View File

@ -63,7 +63,7 @@ class FurnaceRecipe implements Recipe{
return clone $this->output; return clone $this->output;
} }
public function registerToCraftingManager(CraftingManager $manager){ public function registerToCraftingManager(CraftingManager $manager) : void{
$manager->registerFurnaceRecipe($this); $manager->registerFurnaceRecipe($this);
} }
} }

View File

@ -45,7 +45,7 @@ interface Inventory{
/** /**
* @param int $size * @param int $size
*/ */
public function setMaxStackSize(int $size); public function setMaxStackSize(int $size) : void;
/** /**
* @return string * @return string
@ -116,18 +116,18 @@ interface Inventory{
* @param Item[] $items * @param Item[] $items
* @param bool $send * @param bool $send
*/ */
public function setContents(array $items, bool $send = true); public function setContents(array $items, bool $send = true) : void;
/** /**
* @param Player|Player[] $target * @param Player|Player[] $target
*/ */
public function sendContents($target); public function sendContents($target) : void;
/** /**
* @param int $index * @param int $index
* @param Player|Player[] $target * @param Player|Player[] $target
*/ */
public function sendSlot(int $index, $target); public function sendSlot(int $index, $target) : void;
/** /**
* Checks if the inventory contains any Item with the same material data. * Checks if the inventory contains any Item with the same material data.
@ -174,7 +174,7 @@ interface Inventory{
* *
* @param Item $item * @param Item $item
*/ */
public function remove(Item $item); public function remove(Item $item) : void;
/** /**
* Will clear a specific slot * Will clear a specific slot
@ -189,7 +189,7 @@ interface Inventory{
/** /**
* Clears all the slots * Clears all the slots
*/ */
public function clearAll(); public function clearAll() : void;
/** /**
* Gets all the Players viewing the inventory * Gets all the Players viewing the inventory
@ -207,7 +207,7 @@ interface Inventory{
/** /**
* @param Player $who * @param Player $who
*/ */
public function onOpen(Player $who); public function onOpen(Player $who) : void;
/** /**
* Tries to open the inventory to a player * Tries to open the inventory to a player
@ -218,17 +218,17 @@ interface Inventory{
*/ */
public function open(Player $who) : bool; public function open(Player $who) : bool;
public function close(Player $who); public function close(Player $who) : void;
/** /**
* @param Player $who * @param Player $who
*/ */
public function onClose(Player $who); public function onClose(Player $who) : void;
/** /**
* @param int $index * @param int $index
* @param Item $before * @param Item $before
* @param bool $send * @param bool $send
*/ */
public function onSlotChange(int $index, Item $before, bool $send); public function onSlotChange(int $index, Item $before, bool $send) : void;
} }

View File

@ -204,7 +204,7 @@ class PlayerInventory extends EntityInventory{
} }
} }
public function onSlotChange(int $index, Item $before, bool $send){ public function onSlotChange(int $index, Item $before, bool $send) : void{
$holder = $this->getHolder(); $holder = $this->getHolder();
if($holder instanceof Player and !$holder->spawned){ if($holder instanceof Player and !$holder->spawned){
return; return;
@ -280,7 +280,7 @@ class PlayerInventory extends EntityInventory{
return parent::doSetItemEvents($index, $newItem); return parent::doSetItemEvents($index, $newItem);
} }
public function clearAll(){ public function clearAll() : void{
parent::clearAll(); parent::clearAll();
for($i = $this->getSize(), $m = $i + 4; $i < $m; ++$i){ for($i = $this->getSize(), $m = $i + 4; $i < $m; ++$i){

View File

@ -32,5 +32,5 @@ interface Recipe{
*/ */
public function getResult() : Item; public function getResult() : Item;
public function registerToCraftingManager(CraftingManager $manager); public function registerToCraftingManager(CraftingManager $manager) : void;
} }

View File

@ -129,7 +129,7 @@ class ShapedRecipe implements CraftingRecipe{
/** /**
* @return UUID|null * @return UUID|null
*/ */
public function getId(){ public function getId() : ?UUID{
return $this->id; return $this->id;
} }
@ -192,7 +192,7 @@ class ShapedRecipe implements CraftingRecipe{
return $this->shape; return $this->shape;
} }
public function registerToCraftingManager(CraftingManager $manager){ public function registerToCraftingManager(CraftingManager $manager) : void{
$manager->registerShapedRecipe($this); $manager->registerShapedRecipe($this);
} }

View File

@ -43,7 +43,7 @@ class ShapelessRecipe implements CraftingRecipe{
/** /**
* @return UUID|null * @return UUID|null
*/ */
public function getId(){ public function getId() : ?UUID{
return $this->id; return $this->id;
} }
@ -136,7 +136,7 @@ class ShapelessRecipe implements CraftingRecipe{
return $count; return $count;
} }
public function registerToCraftingManager(CraftingManager $manager){ public function registerToCraftingManager(CraftingManager $manager) : void{
$manager->registerShapelessRecipe($this); $manager->registerShapelessRecipe($this);
} }

View File

@ -237,7 +237,7 @@ class InventoryTransaction{
return $this->matchItems($needItems, $haveItems) and count($this->actions) > 0 and count($haveItems) === 0 and count($needItems) === 0; return $this->matchItems($needItems, $haveItems) and count($this->actions) > 0 and count($haveItems) === 0 and count($needItems) === 0;
} }
protected function handleFailed(){ protected function handleFailed() : void{
foreach($this->actions as $action){ foreach($this->actions as $action){
$action->onExecuteFail($this->source); $action->onExecuteFail($this->source);
} }

View File

@ -74,11 +74,11 @@ class CreativeInventoryAction extends InventoryAction{
return true; return true;
} }
public function onExecuteSuccess(Player $source){ public function onExecuteSuccess(Player $source) : void{
} }
public function onExecuteFail(Player $source){ public function onExecuteFail(Player $source) : void{
} }

View File

@ -61,11 +61,11 @@ class DropItemAction extends InventoryAction{
return $source->dropItem($this->targetItem); return $source->dropItem($this->targetItem);
} }
public function onExecuteSuccess(Player $source){ public function onExecuteSuccess(Player $source) : void{
} }
public function onExecuteFail(Player $source){ public function onExecuteFail(Player $source) : void{
} }
} }

View File

@ -112,13 +112,13 @@ abstract class InventoryAction{
* *
* @param Player $source * @param Player $source
*/ */
abstract public function onExecuteSuccess(Player $source); abstract public function onExecuteSuccess(Player $source) : void;
/** /**
* Performs additional actions when this inventory-action did not complete successfully. * Performs additional actions when this inventory-action did not complete successfully.
* *
* @param Player $source * @param Player $source
*/ */
abstract public function onExecuteFail(Player $source); abstract public function onExecuteFail(Player $source) : void;
} }

View File

@ -104,7 +104,7 @@ class SlotChangeAction extends InventoryAction{
* *
* @param Player $source * @param Player $source
*/ */
public function onExecuteSuccess(Player $source){ public function onExecuteSuccess(Player $source) : void{
$viewers = $this->inventory->getViewers(); $viewers = $this->inventory->getViewers();
unset($viewers[spl_object_hash($source)]); unset($viewers[spl_object_hash($source)]);
$this->inventory->sendSlot($this->inventorySlot, $viewers); $this->inventory->sendSlot($this->inventorySlot, $viewers);
@ -115,7 +115,7 @@ class SlotChangeAction extends InventoryAction{
* *
* @param Player $source * @param Player $source
*/ */
public function onExecuteFail(Player $source){ public function onExecuteFail(Player $source) : void{
$this->inventory->sendSlot($this->inventorySlot, $source); $this->inventory->sendSlot($this->inventorySlot, $source);
} }
} }