metadata: populate missing return type information

This commit is contained in:
Dylan K. Taylor 2020-01-19 17:06:48 +00:00
parent 36cde9f352
commit e419d76367
7 changed files with 92 additions and 0 deletions

View File

@ -42,6 +42,12 @@ class BlockMetadataStore extends MetadataStore{
return $block->x . ":" . $block->y . ":" . $block->z . ":" . $metadataKey;
}
/**
* @param Block $subject
* @param string $metadataKey
*
* @return MetadataValue[]
*/
public function getMetadata(Block $subject, string $metadataKey){
return $this->getMetadataInternal($this->disambiguate($subject, $metadataKey));
}
@ -50,10 +56,24 @@ class BlockMetadataStore extends MetadataStore{
return $this->hasMetadataInternal($this->disambiguate($subject, $metadataKey));
}
/**
* @param Block $subject
* @param string $metadataKey
* @param Plugin $owningPlugin
*
* @return void
*/
public function removeMetadata(Block $subject, string $metadataKey, Plugin $owningPlugin){
$this->removeMetadataInternal($this->disambiguate($subject, $metadataKey), $owningPlugin);
}
/**
* @param Block $subject
* @param string $metadataKey
* @param MetadataValue $newMetadataValue
*
* @return void
*/
public function setMetadata(Block $subject, string $metadataKey, MetadataValue $newMetadataValue){
$this->setMetadataInternal($this->disambiguate($subject, $metadataKey), $newMetadataValue);
}

View File

@ -32,6 +32,12 @@ class EntityMetadataStore extends MetadataStore{
return $entity->getId() . ":" . $metadataKey;
}
/**
* @param Entity $subject
* @param string $metadataKey
*
* @return MetadataValue[]
*/
public function getMetadata(Entity $subject, string $metadataKey){
return $this->getMetadataInternal($this->disambiguate($subject, $metadataKey));
}
@ -40,10 +46,24 @@ class EntityMetadataStore extends MetadataStore{
return $this->hasMetadataInternal($this->disambiguate($subject, $metadataKey));
}
/**
* @param Entity $subject
* @param string $metadataKey
* @param Plugin $owningPlugin
*
* @return void
*/
public function removeMetadata(Entity $subject, string $metadataKey, Plugin $owningPlugin){
$this->removeMetadataInternal($this->disambiguate($subject, $metadataKey), $owningPlugin);
}
/**
* @param Entity $subject
* @param string $metadataKey
* @param MetadataValue $newMetadataValue
*
* @return void
*/
public function setMetadata(Entity $subject, string $metadataKey, MetadataValue $newMetadataValue){
$this->setMetadataInternal($this->disambiguate($subject, $metadataKey), $newMetadataValue);
}

View File

@ -33,6 +33,12 @@ class LevelMetadataStore extends MetadataStore{
return strtolower($level->getName()) . ":" . $metadataKey;
}
/**
* @param Level $subject
* @param string $metadataKey
*
* @return MetadataValue[]
*/
public function getMetadata(Level $subject, string $metadataKey){
return $this->getMetadataInternal($this->disambiguate($subject, $metadataKey));
}
@ -41,10 +47,24 @@ class LevelMetadataStore extends MetadataStore{
return $this->hasMetadataInternal($this->disambiguate($subject, $metadataKey));
}
/**
* @param Level $subject
* @param string $metadataKey
* @param Plugin $owningPlugin
*
* @return void
*/
public function removeMetadata(Level $subject, string $metadataKey, Plugin $owningPlugin){
$this->removeMetadataInternal($this->disambiguate($subject, $metadataKey), $owningPlugin);
}
/**
* @param Level $subject
* @param string $metadataKey
* @param MetadataValue $newMetadataValue
*
* @return void
*/
public function setMetadata(Level $subject, string $metadataKey, MetadataValue $newMetadataValue){
$this->setMetadataInternal($this->disambiguate($subject, $metadataKey), $newMetadataValue);
}

View File

@ -37,6 +37,8 @@ abstract class MetadataStore{
*
* @param string $key
* @param MetadataValue $newMetadataValue
*
* @return void
*/
protected function setMetadataInternal(string $key, MetadataValue $newMetadataValue){
$owningPlugin = $newMetadataValue->getOwningPlugin();
@ -82,6 +84,8 @@ abstract class MetadataStore{
*
* @param string $key
* @param Plugin $owningPlugin
*
* @return void
*/
protected function removeMetadataInternal(string $key, Plugin $owningPlugin){
if(isset($this->metadataMap[$key])){
@ -98,6 +102,8 @@ abstract class MetadataStore{
* be recalculated the next time it is accessed.
*
* @param Plugin $owningPlugin
*
* @return void
*/
public function invalidateAll(Plugin $owningPlugin){
/** @var \SplObjectStorage|MetadataValue[] $values */

View File

@ -50,6 +50,8 @@ abstract class MetadataValue{
/**
* Invalidates this metadata item, forcing it to recompute when next
* accessed.
*
* @return void
*/
abstract public function invalidate();
}

View File

@ -32,6 +32,8 @@ interface Metadatable{
*
* @param string $metadataKey
* @param MetadataValue $newMetadataValue
*
* @return void
*/
public function setMetadata(string $metadataKey, MetadataValue $newMetadataValue);
@ -61,6 +63,8 @@ interface Metadatable{
*
* @param string $metadataKey
* @param Plugin $owningPlugin
*
* @return void
*/
public function removeMetadata(string $metadataKey, Plugin $owningPlugin);

View File

@ -33,6 +33,12 @@ class PlayerMetadataStore extends MetadataStore{
return strtolower($player->getName()) . ":" . $metadataKey;
}
/**
* @param IPlayer $subject
* @param string $metadataKey
*
* @return MetadataValue[]
*/
public function getMetadata(IPlayer $subject, string $metadataKey){
return $this->getMetadataInternal($this->disambiguate($subject, $metadataKey));
}
@ -41,10 +47,24 @@ class PlayerMetadataStore extends MetadataStore{
return $this->hasMetadataInternal($this->disambiguate($subject, $metadataKey));
}
/**
* @param IPlayer $subject
* @param string $metadataKey
* @param Plugin $owningPlugin
*
* @return void
*/
public function removeMetadata(IPlayer $subject, string $metadataKey, Plugin $owningPlugin){
$this->removeMetadataInternal($this->disambiguate($subject, $metadataKey), $owningPlugin);
}
/**
* @param IPlayer $subject
* @param string $metadataKey
* @param MetadataValue $newMetadataValue
*
* @return void
*/
public function setMetadata(IPlayer $subject, string $metadataKey, MetadataValue $newMetadataValue){
$this->setMetadataInternal($this->disambiguate($subject, $metadataKey), $newMetadataValue);
}