mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-12 22:45:28 +00:00
null and void typehints
This commit is contained in:
parent
d89b8cf12e
commit
f01ce8e994
@ -56,7 +56,7 @@ class AnvilInventory extends ContainerInventory{
|
||||
return $this->holder;
|
||||
}
|
||||
|
||||
public function onClose(Player $who){
|
||||
public function onClose(Player $who) : void{
|
||||
parent::onClose($who);
|
||||
|
||||
for($i = 0; $i < 2; ++$i){
|
||||
|
@ -106,7 +106,7 @@ abstract class BaseInventory implements Inventory{
|
||||
* @param Item[] $items
|
||||
* @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()){
|
||||
$items = array_slice($items, 0, $this->getSize(), true);
|
||||
}
|
||||
@ -180,7 +180,7 @@ abstract class BaseInventory implements Inventory{
|
||||
return $slots;
|
||||
}
|
||||
|
||||
public function remove(Item $item){
|
||||
public function remove(Item $item) : void{
|
||||
$checkDamage = !$item->hasAnyDamageValue();
|
||||
$checkTags = $item->hasCompoundTag();
|
||||
|
||||
@ -334,7 +334,7 @@ abstract class BaseInventory implements Inventory{
|
||||
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){
|
||||
$this->clear($i, false);
|
||||
}
|
||||
@ -353,7 +353,7 @@ abstract class BaseInventory implements Inventory{
|
||||
return $this->holder;
|
||||
}
|
||||
|
||||
public function setMaxStackSize(int $size){
|
||||
public function setMaxStackSize(int $size) : void{
|
||||
$this->maxStackSize = $size;
|
||||
}
|
||||
|
||||
@ -367,19 +367,19 @@ abstract class BaseInventory implements Inventory{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function close(Player $who){
|
||||
public function close(Player $who) : void{
|
||||
$this->onClose($who);
|
||||
}
|
||||
|
||||
public function onOpen(Player $who){
|
||||
public function onOpen(Player $who) : void{
|
||||
$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)]);
|
||||
}
|
||||
|
||||
public function onSlotChange(int $index, Item $before, bool $send){
|
||||
public function onSlotChange(int $index, Item $before, bool $send) : void{
|
||||
if($send){
|
||||
$this->sendSlot($index, $this->getViewers());
|
||||
}
|
||||
@ -389,7 +389,7 @@ abstract class BaseInventory implements Inventory{
|
||||
/**
|
||||
* @param Player|Player[] $target
|
||||
*/
|
||||
public function sendContents($target){
|
||||
public function sendContents($target) : void{
|
||||
if($target instanceof Player){
|
||||
$target = [$target];
|
||||
}
|
||||
@ -415,7 +415,7 @@ abstract class BaseInventory implements Inventory{
|
||||
* @param int $index
|
||||
* @param Player|Player[] $target
|
||||
*/
|
||||
public function sendSlot(int $index, $target){
|
||||
public function sendSlot(int $index, $target) : void{
|
||||
if($target instanceof Player){
|
||||
$target = [$target];
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ class ChestInventory extends ContainerInventory{
|
||||
return $this->holder;
|
||||
}
|
||||
|
||||
public function onOpen(Player $who){
|
||||
public function onOpen(Player $who) : void{
|
||||
parent::onOpen($who);
|
||||
|
||||
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){
|
||||
$this->broadcastBlockEventPacket(1, 0); //chest close
|
||||
$level->broadcastLevelSoundEvent($this->getHolder()->add(0.5, 0.5, 0.5), LevelSoundEventPacket::SOUND_CHEST_CLOSED);
|
||||
|
@ -29,7 +29,7 @@ use pocketmine\network\mcpe\protocol\ContainerOpenPacket;
|
||||
use pocketmine\Player;
|
||||
|
||||
abstract class ContainerInventory extends BaseInventory{
|
||||
public function onOpen(Player $who){
|
||||
public function onOpen(Player $who) : void{
|
||||
parent::onOpen($who);
|
||||
$pk = new ContainerOpenPacket();
|
||||
$pk->windowId = $who->getWindowId($this);
|
||||
@ -48,7 +48,7 @@ abstract class ContainerInventory extends BaseInventory{
|
||||
$this->sendContents($who);
|
||||
}
|
||||
|
||||
public function onClose(Player $who){
|
||||
public function onClose(Player $who) : void{
|
||||
$pk = new ContainerClosePacket();
|
||||
$pk->windowId = $who->getWindowId($this);
|
||||
$who->dataPacket($pk);
|
||||
|
@ -43,11 +43,11 @@ class CraftingGrid extends BaseInventory{
|
||||
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
|
||||
}
|
||||
|
||||
public function sendContents($target){
|
||||
public function sendContents($target) : void{
|
||||
//we can't send the contents of a client-sided inventory window
|
||||
}
|
||||
}
|
@ -92,7 +92,7 @@ class CraftingManager{
|
||||
/**
|
||||
* Rebuilds the cached CraftingDataPacket.
|
||||
*/
|
||||
public function buildCraftingDataCache(){
|
||||
public function buildCraftingDataCache() : void{
|
||||
Timings::$craftingDataCacheRebuildTimer->startTiming();
|
||||
$pk = new CraftingDataPacket();
|
||||
$pk->cleanRecipes = true;
|
||||
@ -150,7 +150,7 @@ class CraftingManager{
|
||||
* @param UUID $id
|
||||
* @return CraftingRecipe|null
|
||||
*/
|
||||
public function getRecipe(UUID $id){
|
||||
public function getRecipe(UUID $id) : ?CraftingRecipe{
|
||||
$index = $id->toBinary();
|
||||
return $this->recipes[$index] ?? null;
|
||||
}
|
||||
@ -181,7 +181,7 @@ class CraftingManager{
|
||||
/**
|
||||
* @param ShapedRecipe $recipe
|
||||
*/
|
||||
public function registerShapedRecipe(ShapedRecipe $recipe){
|
||||
public function registerShapedRecipe(ShapedRecipe $recipe) : void{
|
||||
$result = $recipe->getResult();
|
||||
|
||||
/** @var Item[][] $ingredients */
|
||||
@ -205,7 +205,7 @@ class CraftingManager{
|
||||
/**
|
||||
* @param ShapelessRecipe $recipe
|
||||
*/
|
||||
public function registerShapelessRecipe(ShapelessRecipe $recipe){
|
||||
public function registerShapelessRecipe(ShapelessRecipe $recipe) : void{
|
||||
$result = $recipe->getResult();
|
||||
$hash = "";
|
||||
$ingredients = $recipe->getIngredientList();
|
||||
@ -220,7 +220,7 @@ class CraftingManager{
|
||||
/**
|
||||
* @param FurnaceRecipe $recipe
|
||||
*/
|
||||
public function registerFurnaceRecipe(FurnaceRecipe $recipe){
|
||||
public function registerFurnaceRecipe(FurnaceRecipe $recipe) : void{
|
||||
$input = $recipe->getInput();
|
||||
$this->furnaceRecipes[$input->getId() . ":" . ($input->hasAnyDamageValue() ? "?" : $input->getDamage())] = $recipe;
|
||||
$this->craftingDataCache = null;
|
||||
@ -287,7 +287,7 @@ class CraftingManager{
|
||||
/**
|
||||
* @param Recipe $recipe
|
||||
*/
|
||||
public function registerRecipe(Recipe $recipe){
|
||||
public function registerRecipe(Recipe $recipe) : void{
|
||||
if($recipe instanceof CraftingRecipe){
|
||||
$result = $recipe->getResult();
|
||||
$recipe->setId($uuid = UUID::fromData((string) ++self::$RECIPE_COUNT, (string) $result->getId(), (string) $result->getDamage(), (string) $result->getCount(), $result->getCompoundTag()));
|
||||
|
@ -31,7 +31,7 @@ interface CraftingRecipe extends Recipe{
|
||||
/**
|
||||
* @return UUID|null
|
||||
*/
|
||||
public function getId();
|
||||
public function getId() : ?UUID;
|
||||
|
||||
/**
|
||||
* @param UUID $id
|
||||
|
@ -86,7 +86,7 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{
|
||||
* @param Item[] $items
|
||||
* @param bool $send
|
||||
*/
|
||||
public function setContents(array $items, bool $send = true){
|
||||
public function setContents(array $items, bool $send = true) : void{
|
||||
$size = $this->getSize();
|
||||
if(count($items) > $size){
|
||||
$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);
|
||||
|
||||
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){
|
||||
$pk = new BlockEventPacket();
|
||||
$pk->x = $this->right->getHolder()->getX();
|
||||
|
@ -56,7 +56,7 @@ class EnchantInventory extends ContainerInventory{
|
||||
return $this->holder;
|
||||
}
|
||||
|
||||
public function onClose(Player $who){
|
||||
public function onClose(Player $who) : void{
|
||||
parent::onClose($who);
|
||||
|
||||
for($i = 0; $i < 2; ++$i){
|
||||
|
@ -103,7 +103,7 @@ class FurnaceInventory extends ContainerInventory{
|
||||
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);
|
||||
|
||||
$this->getHolder()->scheduleUpdate();
|
||||
|
@ -63,7 +63,7 @@ class FurnaceRecipe implements Recipe{
|
||||
return clone $this->output;
|
||||
}
|
||||
|
||||
public function registerToCraftingManager(CraftingManager $manager){
|
||||
public function registerToCraftingManager(CraftingManager $manager) : void{
|
||||
$manager->registerFurnaceRecipe($this);
|
||||
}
|
||||
}
|
@ -45,7 +45,7 @@ interface Inventory{
|
||||
/**
|
||||
* @param int $size
|
||||
*/
|
||||
public function setMaxStackSize(int $size);
|
||||
public function setMaxStackSize(int $size) : void;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
@ -116,18 +116,18 @@ interface Inventory{
|
||||
* @param Item[] $items
|
||||
* @param bool $send
|
||||
*/
|
||||
public function setContents(array $items, bool $send = true);
|
||||
public function setContents(array $items, bool $send = true) : void;
|
||||
|
||||
/**
|
||||
* @param Player|Player[] $target
|
||||
*/
|
||||
public function sendContents($target);
|
||||
public function sendContents($target) : void;
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
* @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.
|
||||
@ -174,7 +174,7 @@ interface Inventory{
|
||||
*
|
||||
* @param Item $item
|
||||
*/
|
||||
public function remove(Item $item);
|
||||
public function remove(Item $item) : void;
|
||||
|
||||
/**
|
||||
* Will clear a specific slot
|
||||
@ -189,7 +189,7 @@ interface Inventory{
|
||||
/**
|
||||
* Clears all the slots
|
||||
*/
|
||||
public function clearAll();
|
||||
public function clearAll() : void;
|
||||
|
||||
/**
|
||||
* Gets all the Players viewing the inventory
|
||||
@ -207,7 +207,7 @@ interface Inventory{
|
||||
/**
|
||||
* @param Player $who
|
||||
*/
|
||||
public function onOpen(Player $who);
|
||||
public function onOpen(Player $who) : void;
|
||||
|
||||
/**
|
||||
* Tries to open the inventory to a player
|
||||
@ -218,17 +218,17 @@ interface Inventory{
|
||||
*/
|
||||
public function open(Player $who) : bool;
|
||||
|
||||
public function close(Player $who);
|
||||
public function close(Player $who) : void;
|
||||
|
||||
/**
|
||||
* @param Player $who
|
||||
*/
|
||||
public function onClose(Player $who);
|
||||
public function onClose(Player $who) : void;
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
* @param Item $before
|
||||
* @param bool $send
|
||||
*/
|
||||
public function onSlotChange(int $index, Item $before, bool $send);
|
||||
public function onSlotChange(int $index, Item $before, bool $send) : void;
|
||||
}
|
||||
|
@ -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();
|
||||
if($holder instanceof Player and !$holder->spawned){
|
||||
return;
|
||||
@ -280,7 +280,7 @@ class PlayerInventory extends EntityInventory{
|
||||
return parent::doSetItemEvents($index, $newItem);
|
||||
}
|
||||
|
||||
public function clearAll(){
|
||||
public function clearAll() : void{
|
||||
parent::clearAll();
|
||||
|
||||
for($i = $this->getSize(), $m = $i + 4; $i < $m; ++$i){
|
||||
|
@ -32,5 +32,5 @@ interface Recipe{
|
||||
*/
|
||||
public function getResult() : Item;
|
||||
|
||||
public function registerToCraftingManager(CraftingManager $manager);
|
||||
public function registerToCraftingManager(CraftingManager $manager) : void;
|
||||
}
|
@ -129,7 +129,7 @@ class ShapedRecipe implements CraftingRecipe{
|
||||
/**
|
||||
* @return UUID|null
|
||||
*/
|
||||
public function getId(){
|
||||
public function getId() : ?UUID{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
@ -192,7 +192,7 @@ class ShapedRecipe implements CraftingRecipe{
|
||||
return $this->shape;
|
||||
}
|
||||
|
||||
public function registerToCraftingManager(CraftingManager $manager){
|
||||
public function registerToCraftingManager(CraftingManager $manager) : void{
|
||||
$manager->registerShapedRecipe($this);
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ class ShapelessRecipe implements CraftingRecipe{
|
||||
/**
|
||||
* @return UUID|null
|
||||
*/
|
||||
public function getId(){
|
||||
public function getId() : ?UUID{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
@ -136,7 +136,7 @@ class ShapelessRecipe implements CraftingRecipe{
|
||||
return $count;
|
||||
}
|
||||
|
||||
public function registerToCraftingManager(CraftingManager $manager){
|
||||
public function registerToCraftingManager(CraftingManager $manager) : void{
|
||||
$manager->registerShapelessRecipe($this);
|
||||
}
|
||||
|
||||
|
@ -237,7 +237,7 @@ class InventoryTransaction{
|
||||
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){
|
||||
$action->onExecuteFail($this->source);
|
||||
}
|
||||
|
@ -74,11 +74,11 @@ class CreativeInventoryAction extends InventoryAction{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function onExecuteSuccess(Player $source){
|
||||
public function onExecuteSuccess(Player $source) : void{
|
||||
|
||||
}
|
||||
|
||||
public function onExecuteFail(Player $source){
|
||||
public function onExecuteFail(Player $source) : void{
|
||||
|
||||
}
|
||||
|
||||
|
@ -61,11 +61,11 @@ class DropItemAction extends InventoryAction{
|
||||
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{
|
||||
|
||||
}
|
||||
}
|
@ -112,13 +112,13 @@ abstract class InventoryAction{
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* @param Player $source
|
||||
*/
|
||||
abstract public function onExecuteFail(Player $source);
|
||||
abstract public function onExecuteFail(Player $source) : void;
|
||||
|
||||
}
|
@ -104,7 +104,7 @@ class SlotChangeAction extends InventoryAction{
|
||||
*
|
||||
* @param Player $source
|
||||
*/
|
||||
public function onExecuteSuccess(Player $source){
|
||||
public function onExecuteSuccess(Player $source) : void{
|
||||
$viewers = $this->inventory->getViewers();
|
||||
unset($viewers[spl_object_hash($source)]);
|
||||
$this->inventory->sendSlot($this->inventorySlot, $viewers);
|
||||
@ -115,7 +115,7 @@ class SlotChangeAction extends InventoryAction{
|
||||
*
|
||||
* @param Player $source
|
||||
*/
|
||||
public function onExecuteFail(Player $source){
|
||||
public function onExecuteFail(Player $source) : void{
|
||||
$this->inventory->sendSlot($this->inventorySlot, $source);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user