From 0b1a9ba062bf43bb53f6d99e499e17cfc42c793c Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 16 Oct 2017 16:14:44 +0100 Subject: [PATCH] Added more typehints to Tile namespace --- src/pocketmine/tile/Bed.php | 2 +- src/pocketmine/tile/Chest.php | 10 +++++----- src/pocketmine/tile/EnchantTable.php | 2 +- src/pocketmine/tile/FlowerPot.php | 2 +- src/pocketmine/tile/Furnace.php | 6 +++--- src/pocketmine/tile/ItemFrame.php | 2 +- src/pocketmine/tile/Sign.php | 4 ++-- src/pocketmine/tile/Skull.php | 2 +- src/pocketmine/tile/Spawnable.php | 6 +++--- src/pocketmine/tile/Tile.php | 12 ++++++------ 10 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/pocketmine/tile/Bed.php b/src/pocketmine/tile/Bed.php index c7548b369..611d76d3f 100644 --- a/src/pocketmine/tile/Bed.php +++ b/src/pocketmine/tile/Bed.php @@ -49,7 +49,7 @@ class Bed extends Spawnable{ $this->onChanged(); } - public function addAdditionalSpawnData(CompoundTag $nbt){ + public function addAdditionalSpawnData(CompoundTag $nbt) : void{ $nbt->color = $this->namedtag->color; } diff --git a/src/pocketmine/tile/Chest.php b/src/pocketmine/tile/Chest.php index d9eb9da0a..f938a7299 100644 --- a/src/pocketmine/tile/Chest.php +++ b/src/pocketmine/tile/Chest.php @@ -58,7 +58,7 @@ class Chest extends Spawnable implements InventoryHolder, Container, Nameable{ } } - public function close(){ + public function close() : void{ if($this->closed === false){ $this->inventory->removeAllViewers(true); @@ -74,7 +74,7 @@ class Chest extends Spawnable implements InventoryHolder, Container, Nameable{ } } - public function saveNBT(){ + public function saveNBT() : void{ $this->namedtag->Items->setValue([]); for($index = 0; $index < $this->getSize(); ++$index){ $this->setItem($index, $this->inventory->getItem($index)); @@ -93,7 +93,7 @@ class Chest extends Spawnable implements InventoryHolder, Container, Nameable{ * * @return int */ - protected function getSlotIndex(int $index){ + protected function getSlotIndex(int $index) : int{ foreach($this->namedtag->Items as $i => $slot){ if($slot->Slot->getValue() === $index){ return (int) $i; @@ -200,7 +200,7 @@ class Chest extends Spawnable implements InventoryHolder, Container, Nameable{ /** * @return Chest|null */ - public function getPair(){ + public function getPair() : ?Chest{ if($this->isPaired()){ $tile = $this->getLevel()->getTile(new Vector3($this->namedtag->pairx->getValue(), $this->y, $this->namedtag->pairz->getValue())); if($tile instanceof Chest){ @@ -253,7 +253,7 @@ class Chest extends Spawnable implements InventoryHolder, Container, Nameable{ return true; } - public function addAdditionalSpawnData(CompoundTag $nbt){ + public function addAdditionalSpawnData(CompoundTag $nbt) : void{ if($this->isPaired()){ $nbt->pairx = $this->namedtag->pairx; $nbt->pairz = $this->namedtag->pairz; diff --git a/src/pocketmine/tile/EnchantTable.php b/src/pocketmine/tile/EnchantTable.php index 863e02c85..c8b2f56b8 100644 --- a/src/pocketmine/tile/EnchantTable.php +++ b/src/pocketmine/tile/EnchantTable.php @@ -39,7 +39,7 @@ class EnchantTable extends Spawnable implements Nameable{ return "Enchanting Table"; } - public function addAdditionalSpawnData(CompoundTag $nbt){ + public function addAdditionalSpawnData(CompoundTag $nbt) : void{ if($this->hasName()){ $nbt->CustomName = $this->namedtag->CustomName; } diff --git a/src/pocketmine/tile/FlowerPot.php b/src/pocketmine/tile/FlowerPot.php index 0044682e4..eaeabb3a5 100644 --- a/src/pocketmine/tile/FlowerPot.php +++ b/src/pocketmine/tile/FlowerPot.php @@ -85,7 +85,7 @@ class FlowerPot extends Spawnable{ return $this->getItem()->isNull(); } - public function addAdditionalSpawnData(CompoundTag $nbt){ + public function addAdditionalSpawnData(CompoundTag $nbt) : void{ $nbt->item = $this->namedtag->item; $nbt->mData = $this->namedtag->mData; } diff --git a/src/pocketmine/tile/Furnace.php b/src/pocketmine/tile/Furnace.php index 5220dc787..6a995c4b2 100644 --- a/src/pocketmine/tile/Furnace.php +++ b/src/pocketmine/tile/Furnace.php @@ -87,7 +87,7 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{ return "Furnace"; } - public function close(){ + public function close() : void{ if($this->closed === false){ $this->inventory->removeAllViewers(true); $this->inventory = null; @@ -96,7 +96,7 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{ } } - public function saveNBT(){ + public function saveNBT() : void{ $this->namedtag->Items->setValue([]); for($index = 0; $index < $this->getSize(); ++$index){ $this->setItem($index, $this->inventory->getItem($index)); @@ -273,7 +273,7 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{ return $ret; } - public function addAdditionalSpawnData(CompoundTag $nbt){ + public function addAdditionalSpawnData(CompoundTag $nbt) : void{ $nbt->BurnTime = $this->namedtag->BurnTime; $nbt->CookTime = $this->namedtag->CookTime; diff --git a/src/pocketmine/tile/ItemFrame.php b/src/pocketmine/tile/ItemFrame.php index c4e6e8e05..22c28ffa5 100644 --- a/src/pocketmine/tile/ItemFrame.php +++ b/src/pocketmine/tile/ItemFrame.php @@ -85,7 +85,7 @@ class ItemFrame extends Spawnable{ $this->onChanged(); } - public function addAdditionalSpawnData(CompoundTag $nbt){ + public function addAdditionalSpawnData(CompoundTag $nbt) : void{ $nbt->ItemDropChance = $this->namedtag->ItemDropChance; $nbt->ItemRotation = $this->namedtag->ItemRotation; diff --git a/src/pocketmine/tile/Sign.php b/src/pocketmine/tile/Sign.php index a77930426..b9eea66d4 100644 --- a/src/pocketmine/tile/Sign.php +++ b/src/pocketmine/tile/Sign.php @@ -54,7 +54,7 @@ class Sign extends Spawnable{ parent::__construct($level, $nbt); } - public function saveNBT(){ + public function saveNBT() : void{ parent::saveNBT(); $this->namedtag->Text = new StringTag("Text", implode("\n", $this->text)); @@ -127,7 +127,7 @@ class Sign extends Spawnable{ return $this->text; } - public function addAdditionalSpawnData(CompoundTag $nbt){ + public function addAdditionalSpawnData(CompoundTag $nbt) : void{ $nbt->Text = new StringTag("Text", implode("\n", $this->text)); } diff --git a/src/pocketmine/tile/Skull.php b/src/pocketmine/tile/Skull.php index a3eb37997..fd9de63a2 100644 --- a/src/pocketmine/tile/Skull.php +++ b/src/pocketmine/tile/Skull.php @@ -57,7 +57,7 @@ class Skull extends Spawnable{ return $this->namedtag->SkullType->getValue(); } - public function addAdditionalSpawnData(CompoundTag $nbt){ + public function addAdditionalSpawnData(CompoundTag $nbt) : void{ $nbt->SkullType = $this->namedtag->SkullType; $nbt->Rot = $this->namedtag->Rot; } diff --git a/src/pocketmine/tile/Spawnable.php b/src/pocketmine/tile/Spawnable.php index 6a49b642b..37b15aff2 100644 --- a/src/pocketmine/tile/Spawnable.php +++ b/src/pocketmine/tile/Spawnable.php @@ -43,7 +43,7 @@ abstract class Spawnable extends Tile{ return $pk; } - public function spawnTo(Player $player){ + public function spawnTo(Player $player) : bool{ if($this->closed){ return false; } @@ -67,7 +67,7 @@ abstract class Spawnable extends Tile{ $this->level->addChunkPacket($this->chunk->getX(), $this->chunk->getZ(), $pk); } - protected function onChanged(){ + protected function onChanged() : void{ $this->spawnToAll(); if($this->chunk !== null){ @@ -96,7 +96,7 @@ abstract class Spawnable extends Tile{ * * @param CompoundTag $nbt */ - abstract public function addAdditionalSpawnData(CompoundTag $nbt); + abstract public function addAdditionalSpawnData(CompoundTag $nbt) : void; /** * Called when a player updates a block entity's NBT data diff --git a/src/pocketmine/tile/Tile.php b/src/pocketmine/tile/Tile.php index 14da34474..436aa9368 100644 --- a/src/pocketmine/tile/Tile.php +++ b/src/pocketmine/tile/Tile.php @@ -97,7 +97,7 @@ abstract class Tile extends Position{ * * @return Tile|null */ - public static function createTile($type, Level $level, CompoundTag $nbt, ...$args){ + public static function createTile($type, Level $level, CompoundTag $nbt, ...$args) : ?Tile{ if(isset(self::$knownTiles[$type])){ $class = self::$knownTiles[$type]; return new $class($level, $nbt, ...$args); @@ -149,11 +149,11 @@ abstract class Tile extends Position{ $this->getLevel()->addTile($this); } - public function getId(){ + public function getId() : int{ return $this->id; } - public function saveNBT(){ + public function saveNBT() : void{ $this->namedtag->id->setValue(static::getSaveId()); $this->namedtag->x->setValue($this->x); $this->namedtag->y->setValue($this->y); @@ -164,7 +164,7 @@ abstract class Tile extends Position{ return $this->namedtag; } - public function getCleanedNBT(){ + public function getCleanedNBT() : ?CompoundTag{ $this->saveNBT(); $tag = clone $this->namedtag; unset($tag->x, $tag->y, $tag->z, $tag->id); @@ -236,7 +236,7 @@ abstract class Tile extends Position{ return false; } - final public function scheduleUpdate(){ + final public function scheduleUpdate() : void{ $this->level->updateTiles[$this->id] = $this; } @@ -248,7 +248,7 @@ abstract class Tile extends Position{ $this->close(); } - public function close(){ + public function close() : void{ if(!$this->closed){ $this->closed = true; unset($this->level->updateTiles[$this->id]);