Revamp MetadataStore API (#2477)

This would be a lot less messy if we had generics, but no tango.
This commit is contained in:
Dylan K. Taylor
2018-10-12 12:16:21 +01:00
committed by GitHub
parent a0ab996b9f
commit 6579930638
5 changed files with 75 additions and 89 deletions

View File

@ -24,14 +24,27 @@ declare(strict_types=1);
namespace pocketmine\metadata;
use pocketmine\level\Level;
use pocketmine\plugin\Plugin;
class LevelMetadataStore extends MetadataStore{
public function disambiguate(Metadatable $level, string $metadataKey) : string{
if(!($level instanceof Level)){
throw new \InvalidArgumentException("Argument must be a Level instance");
}
private function disambiguate(Level $level, string $metadataKey) : string{
return strtolower($level->getName()) . ":" . $metadataKey;
}
public function getMetadata(Level $subject, string $metadataKey){
return $this->getMetadataInternal($this->disambiguate($subject, $metadataKey));
}
public function hasMetadata(Level $subject, string $metadataKey) : bool{
return $this->hasMetadataInternal($this->disambiguate($subject, $metadataKey));
}
public function removeMetadata(Level $subject, string $metadataKey, Plugin $owningPlugin){
$this->removeMetadataInternal($this->disambiguate($subject, $metadataKey), $owningPlugin);
}
public function setMetadata(Level $subject, string $metadataKey, MetadataValue $newMetadataValue){
$this->setMetadataInternal($this->disambiguate($subject, $metadataKey), $newMetadataValue);
}
}