mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-08 19:02:59 +00:00
Revamp MetadataStore API (#2477)
This would be a lot less messy if we had generics, but no tango.
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user