From e8bd0c3e09cfaaf77aa293654ed101d4735cea8e Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 10 Aug 2017 18:02:01 +0100 Subject: [PATCH] add typehints to Metadatable interface and implementations, fix missing return for Block->hasMetadata() reported in #1285 --- src/pocketmine/OfflinePlayer.php | 12 ++++++------ src/pocketmine/Player.php | 12 ++++++------ src/pocketmine/block/Block.php | 16 +++++++++------- src/pocketmine/entity/Entity.php | 8 ++++---- src/pocketmine/level/Level.php | 12 ++++++------ src/pocketmine/metadata/Metadatable.php | 12 ++++-------- 6 files changed, 35 insertions(+), 37 deletions(-) diff --git a/src/pocketmine/OfflinePlayer.php b/src/pocketmine/OfflinePlayer.php index 4f7b4105e..09d76dd40 100644 --- a/src/pocketmine/OfflinePlayer.php +++ b/src/pocketmine/OfflinePlayer.php @@ -119,20 +119,20 @@ class OfflinePlayer implements IPlayer, Metadatable{ return $this->namedtag instanceof CompoundTag; } - public function setMetadata($metadataKey, MetadataValue $metadataValue){ - $this->server->getPlayerMetadata()->setMetadata($this, $metadataKey, $metadataValue); + public function setMetadata(string $metadataKey, MetadataValue $newMetadataValue){ + $this->server->getPlayerMetadata()->setMetadata($this, $metadataKey, $newMetadataValue); } - public function getMetadata($metadataKey){ + public function getMetadata(string $metadataKey){ return $this->server->getPlayerMetadata()->getMetadata($this, $metadataKey); } - public function hasMetadata($metadataKey){ + public function hasMetadata(string $metadataKey) : bool{ return $this->server->getPlayerMetadata()->hasMetadata($this, $metadataKey); } - public function removeMetadata($metadataKey, Plugin $plugin){ - $this->server->getPlayerMetadata()->removeMetadata($this, $metadataKey, $plugin); + public function removeMetadata(string $metadataKey, Plugin $owningPlugin){ + $this->server->getPlayerMetadata()->removeMetadata($this, $metadataKey, $owningPlugin); } diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 05a4ac6fa..94d85aaa1 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -3855,20 +3855,20 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } } - public function setMetadata($metadataKey, MetadataValue $metadataValue){ - $this->server->getPlayerMetadata()->setMetadata($this, $metadataKey, $metadataValue); + public function setMetadata(string $metadataKey, MetadataValue $newMetadataValue){ + $this->server->getPlayerMetadata()->setMetadata($this, $metadataKey, $newMetadataValue); } - public function getMetadata($metadataKey){ + public function getMetadata(string $metadataKey){ return $this->server->getPlayerMetadata()->getMetadata($this, $metadataKey); } - public function hasMetadata($metadataKey){ + public function hasMetadata(string $metadataKey) : bool{ return $this->server->getPlayerMetadata()->hasMetadata($this, $metadataKey); } - public function removeMetadata($metadataKey, Plugin $plugin){ - $this->server->getPlayerMetadata()->removeMetadata($this, $metadataKey, $plugin); + public function removeMetadata(string $metadataKey, Plugin $owningPlugin){ + $this->server->getPlayerMetadata()->removeMetadata($this, $metadataKey, $owningPlugin); } public function onChunkChanged(Chunk $chunk){ diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index 764eb3dcf..fcc50afd6 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -830,13 +830,13 @@ class Block extends Position implements BlockIds, Metadatable{ return MovingObjectPosition::fromBlock($this->x, $this->y, $this->z, $f, $vector->add($this->x, $this->y, $this->z)); } - public function setMetadata($metadataKey, MetadataValue $metadataValue){ + public function setMetadata(string $metadataKey, MetadataValue $newMetadataValue){ if($this->getLevel() instanceof Level){ - $this->getLevel()->getBlockMetadata()->setMetadata($this, $metadataKey, $metadataValue); + $this->getLevel()->getBlockMetadata()->setMetadata($this, $metadataKey, $newMetadataValue); } } - public function getMetadata($metadataKey){ + public function getMetadata(string $metadataKey){ if($this->getLevel() instanceof Level){ return $this->getLevel()->getBlockMetadata()->getMetadata($this, $metadataKey); } @@ -844,15 +844,17 @@ class Block extends Position implements BlockIds, Metadatable{ return null; } - public function hasMetadata($metadataKey){ + public function hasMetadata(string $metadataKey) : bool{ if($this->getLevel() instanceof Level){ - $this->getLevel()->getBlockMetadata()->hasMetadata($this, $metadataKey); + return $this->getLevel()->getBlockMetadata()->hasMetadata($this, $metadataKey); } + + return false; } - public function removeMetadata($metadataKey, Plugin $plugin){ + public function removeMetadata(string $metadataKey, Plugin $owningPlugin){ if($this->getLevel() instanceof Level){ - $this->getLevel()->getBlockMetadata()->removeMetadata($this, $metadataKey, $plugin); + $this->getLevel()->getBlockMetadata()->removeMetadata($this, $metadataKey, $owningPlugin); } } } diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 0e1aa9924..4d690b8f8 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -1872,19 +1872,19 @@ abstract class Entity extends Location implements Metadatable{ $this->close(); } - public function setMetadata($metadataKey, MetadataValue $metadataValue){ + public function setMetadata(string $metadataKey, MetadataValue $metadataValue){ $this->server->getEntityMetadata()->setMetadata($this, $metadataKey, $metadataValue); } - public function getMetadata($metadataKey){ + public function getMetadata(string $metadataKey){ return $this->server->getEntityMetadata()->getMetadata($this, $metadataKey); } - public function hasMetadata($metadataKey){ + public function hasMetadata(string $metadataKey) : bool{ return $this->server->getEntityMetadata()->hasMetadata($this, $metadataKey); } - public function removeMetadata($metadataKey, Plugin $plugin){ + public function removeMetadata(string $metadataKey, Plugin $plugin){ $this->server->getEntityMetadata()->removeMetadata($this, $metadataKey, $plugin); } diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index b702e2941..136b78bcb 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -2907,20 +2907,20 @@ class Level implements ChunkManager, Metadatable{ } } - public function setMetadata($metadataKey, MetadataValue $metadataValue){ - $this->server->getLevelMetadata()->setMetadata($this, $metadataKey, $metadataValue); + public function setMetadata(string $metadataKey, MetadataValue $newMetadataValue){ + $this->server->getLevelMetadata()->setMetadata($this, $metadataKey, $newMetadataValue); } - public function getMetadata($metadataKey){ + public function getMetadata(string $metadataKey){ return $this->server->getLevelMetadata()->getMetadata($this, $metadataKey); } - public function hasMetadata($metadataKey){ + public function hasMetadata(string $metadataKey) : bool{ return $this->server->getLevelMetadata()->hasMetadata($this, $metadataKey); } - public function removeMetadata($metadataKey, Plugin $plugin){ - $this->server->getLevelMetadata()->removeMetadata($this, $metadataKey, $plugin); + public function removeMetadata(string $metadataKey, Plugin $owningPlugin){ + $this->server->getLevelMetadata()->removeMetadata($this, $metadataKey, $owningPlugin); } public function addEntityMotion(int $chunkX, int $chunkZ, int $entityId, float $x, float $y, float $z){ diff --git a/src/pocketmine/metadata/Metadatable.php b/src/pocketmine/metadata/Metadatable.php index b3e1c6c41..c43b9ce8e 100644 --- a/src/pocketmine/metadata/Metadatable.php +++ b/src/pocketmine/metadata/Metadatable.php @@ -32,10 +32,8 @@ interface Metadatable{ * * @param string $metadataKey * @param MetadataValue $newMetadataValue - * - * @return void */ - public function setMetadata($metadataKey, MetadataValue $newMetadataValue); + public function setMetadata(string $metadataKey, MetadataValue $newMetadataValue); /** * Returns a list of previously set metadata values from the implementing @@ -45,7 +43,7 @@ interface Metadatable{ * * @return MetadataValue[] */ - public function getMetadata($metadataKey); + public function getMetadata(string $metadataKey); /** * Tests to see whether the implementing object contains the given @@ -55,7 +53,7 @@ interface Metadatable{ * * @return bool */ - public function hasMetadata($metadataKey); + public function hasMetadata(string $metadataKey) : bool; /** * Removes the given metadata value from the implementing object's @@ -63,9 +61,7 @@ interface Metadatable{ * * @param string $metadataKey * @param Plugin $owningPlugin - * - * @return void */ - public function removeMetadata($metadataKey, Plugin $owningPlugin); + public function removeMetadata(string $metadataKey, Plugin $owningPlugin); } \ No newline at end of file