add typehints to Metadatable interface and implementations, fix missing return for Block->hasMetadata() reported in #1285

This commit is contained in:
Dylan K. Taylor 2017-08-10 18:02:01 +01:00
parent 82fd3b540e
commit e8bd0c3e09
6 changed files with 35 additions and 37 deletions

View File

@ -119,20 +119,20 @@ class OfflinePlayer implements IPlayer, Metadatable{
return $this->namedtag instanceof CompoundTag; return $this->namedtag instanceof CompoundTag;
} }
public function setMetadata($metadataKey, MetadataValue $metadataValue){ public function setMetadata(string $metadataKey, MetadataValue $newMetadataValue){
$this->server->getPlayerMetadata()->setMetadata($this, $metadataKey, $metadataValue); $this->server->getPlayerMetadata()->setMetadata($this, $metadataKey, $newMetadataValue);
} }
public function getMetadata($metadataKey){ public function getMetadata(string $metadataKey){
return $this->server->getPlayerMetadata()->getMetadata($this, $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); return $this->server->getPlayerMetadata()->hasMetadata($this, $metadataKey);
} }
public function removeMetadata($metadataKey, Plugin $plugin){ public function removeMetadata(string $metadataKey, Plugin $owningPlugin){
$this->server->getPlayerMetadata()->removeMetadata($this, $metadataKey, $plugin); $this->server->getPlayerMetadata()->removeMetadata($this, $metadataKey, $owningPlugin);
} }

View File

@ -3855,20 +3855,20 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
} }
} }
public function setMetadata($metadataKey, MetadataValue $metadataValue){ public function setMetadata(string $metadataKey, MetadataValue $newMetadataValue){
$this->server->getPlayerMetadata()->setMetadata($this, $metadataKey, $metadataValue); $this->server->getPlayerMetadata()->setMetadata($this, $metadataKey, $newMetadataValue);
} }
public function getMetadata($metadataKey){ public function getMetadata(string $metadataKey){
return $this->server->getPlayerMetadata()->getMetadata($this, $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); return $this->server->getPlayerMetadata()->hasMetadata($this, $metadataKey);
} }
public function removeMetadata($metadataKey, Plugin $plugin){ public function removeMetadata(string $metadataKey, Plugin $owningPlugin){
$this->server->getPlayerMetadata()->removeMetadata($this, $metadataKey, $plugin); $this->server->getPlayerMetadata()->removeMetadata($this, $metadataKey, $owningPlugin);
} }
public function onChunkChanged(Chunk $chunk){ public function onChunkChanged(Chunk $chunk){

View File

@ -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)); 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){ 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){ if($this->getLevel() instanceof Level){
return $this->getLevel()->getBlockMetadata()->getMetadata($this, $metadataKey); return $this->getLevel()->getBlockMetadata()->getMetadata($this, $metadataKey);
} }
@ -844,15 +844,17 @@ class Block extends Position implements BlockIds, Metadatable{
return null; return null;
} }
public function hasMetadata($metadataKey){ public function hasMetadata(string $metadataKey) : bool{
if($this->getLevel() instanceof Level){ 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){ if($this->getLevel() instanceof Level){
$this->getLevel()->getBlockMetadata()->removeMetadata($this, $metadataKey, $plugin); $this->getLevel()->getBlockMetadata()->removeMetadata($this, $metadataKey, $owningPlugin);
} }
} }
} }

View File

@ -1872,19 +1872,19 @@ abstract class Entity extends Location implements Metadatable{
$this->close(); $this->close();
} }
public function setMetadata($metadataKey, MetadataValue $metadataValue){ public function setMetadata(string $metadataKey, MetadataValue $metadataValue){
$this->server->getEntityMetadata()->setMetadata($this, $metadataKey, $metadataValue); $this->server->getEntityMetadata()->setMetadata($this, $metadataKey, $metadataValue);
} }
public function getMetadata($metadataKey){ public function getMetadata(string $metadataKey){
return $this->server->getEntityMetadata()->getMetadata($this, $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); 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); $this->server->getEntityMetadata()->removeMetadata($this, $metadataKey, $plugin);
} }

View File

@ -2907,20 +2907,20 @@ class Level implements ChunkManager, Metadatable{
} }
} }
public function setMetadata($metadataKey, MetadataValue $metadataValue){ public function setMetadata(string $metadataKey, MetadataValue $newMetadataValue){
$this->server->getLevelMetadata()->setMetadata($this, $metadataKey, $metadataValue); $this->server->getLevelMetadata()->setMetadata($this, $metadataKey, $newMetadataValue);
} }
public function getMetadata($metadataKey){ public function getMetadata(string $metadataKey){
return $this->server->getLevelMetadata()->getMetadata($this, $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); return $this->server->getLevelMetadata()->hasMetadata($this, $metadataKey);
} }
public function removeMetadata($metadataKey, Plugin $plugin){ public function removeMetadata(string $metadataKey, Plugin $owningPlugin){
$this->server->getLevelMetadata()->removeMetadata($this, $metadataKey, $plugin); $this->server->getLevelMetadata()->removeMetadata($this, $metadataKey, $owningPlugin);
} }
public function addEntityMotion(int $chunkX, int $chunkZ, int $entityId, float $x, float $y, float $z){ public function addEntityMotion(int $chunkX, int $chunkZ, int $entityId, float $x, float $y, float $z){

View File

@ -32,10 +32,8 @@ interface Metadatable{
* *
* @param string $metadataKey * @param string $metadataKey
* @param MetadataValue $newMetadataValue * @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 * Returns a list of previously set metadata values from the implementing
@ -45,7 +43,7 @@ interface Metadatable{
* *
* @return MetadataValue[] * @return MetadataValue[]
*/ */
public function getMetadata($metadataKey); public function getMetadata(string $metadataKey);
/** /**
* Tests to see whether the implementing object contains the given * Tests to see whether the implementing object contains the given
@ -55,7 +53,7 @@ interface Metadatable{
* *
* @return bool * @return bool
*/ */
public function hasMetadata($metadataKey); public function hasMetadata(string $metadataKey) : bool;
/** /**
* Removes the given metadata value from the implementing object's * Removes the given metadata value from the implementing object's
@ -63,9 +61,7 @@ interface Metadatable{
* *
* @param string $metadataKey * @param string $metadataKey
* @param Plugin $owningPlugin * @param Plugin $owningPlugin
*
* @return void
*/ */
public function removeMetadata($metadataKey, Plugin $owningPlugin); public function removeMetadata(string $metadataKey, Plugin $owningPlugin);
} }