mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 17:59:48 +00:00
Added extra Exceptions
This commit is contained in:
@ -43,45 +43,45 @@ class BlockMetadataStore extends MetadataStore{
|
||||
|
||||
public function getMetadata($block, $metadataKey){
|
||||
if($block instanceof Block){
|
||||
throw new \Exception("Object must be a Block");
|
||||
throw new \InvalidArgumentException("Object must be a Block");
|
||||
}
|
||||
if($block->getLevel() === $this->owningLevel){
|
||||
return parent::getMetadata($block, $metadataKey);
|
||||
}else{
|
||||
throw new \Exception("Block does not belong to world " . $this->owningLevel->getName());
|
||||
throw new \InvalidStateException("Block does not belong to world " . $this->owningLevel->getName());
|
||||
}
|
||||
}
|
||||
|
||||
public function hasMetadata($block, $metadataKey){
|
||||
if($block instanceof Block){
|
||||
throw new \Exception("Object must be a Block");
|
||||
throw new \InvalidArgumentException("Object must be a Block");
|
||||
}
|
||||
if($block->getLevel() === $this->owningLevel){
|
||||
return parent::hasMetadata($block, $metadataKey);
|
||||
}else{
|
||||
throw new \Exception("Block does not belong to world " . $this->owningLevel->getName());
|
||||
throw new \InvalidStateException("Block does not belong to world " . $this->owningLevel->getName());
|
||||
}
|
||||
}
|
||||
|
||||
public function removeMetadata($block, $metadataKey, Plugin $owningPlugin){
|
||||
if($block instanceof Block){
|
||||
throw new \Exception("Object must be a Block");
|
||||
throw new \InvalidArgumentException("Object must be a Block");
|
||||
}
|
||||
if($block->getLevel() === $this->owningLevel){
|
||||
parent::hasMetadata($block, $metadataKey, $owningPlugin);
|
||||
}else{
|
||||
throw new \Exception("Block does not belong to world " . $this->owningLevel->getName());
|
||||
throw new \InvalidStateException("Block does not belong to world " . $this->owningLevel->getName());
|
||||
}
|
||||
}
|
||||
|
||||
public function setMetadata($block, $metadataKey, MetadataValue $newMetadatavalue){
|
||||
if($block instanceof Block){
|
||||
throw new \Exception("Object must be a Block");
|
||||
throw new \InvalidArgumentException("Object must be a Block");
|
||||
}
|
||||
if($block->getLevel() === $this->owningLevel){
|
||||
parent::setMetadata($block, $metadataKey, $newMetadatavalue);
|
||||
}else{
|
||||
throw new \Exception("Block does not belong to world " . $this->owningLevel->getName());
|
||||
throw new \InvalidStateException("Block does not belong to world " . $this->owningLevel->getName());
|
||||
}
|
||||
}
|
||||
}
|
@ -25,6 +25,7 @@
|
||||
namespace pocketmine\metadata;
|
||||
|
||||
use pocketmine\plugin\Plugin;
|
||||
use pocketmine\utils\PluginException;
|
||||
|
||||
abstract class MetadataStore{
|
||||
/** @var \WeakMap[] */
|
||||
@ -42,7 +43,7 @@ abstract class MetadataStore{
|
||||
public function setMetadata($subject, $metadataKey, MetadataValue $newMetadataValue){
|
||||
$owningPlugin = $newMetadataValue->getOwningPlugin();
|
||||
if($owningPlugin === null){
|
||||
throw new \Exception("Plugin cannot be null");
|
||||
throw new PluginException("Plugin cannot be null");
|
||||
}
|
||||
|
||||
$key = $this->disambiguate($subject, $metadataKey);
|
||||
|
Reference in New Issue
Block a user