Added API methods to determine if a block or item is already registered

This commit is contained in:
Dylan K. Taylor
2017-09-11 16:22:55 +01:00
parent aaa3b6e59a
commit 07268e4b37
2 changed files with 23 additions and 2 deletions

View File

@ -256,7 +256,7 @@ class ItemFactory{
*/
public static function registerItem(Item $item, bool $override = false){
$id = $item->getId();
if(!$override and self::$list[$id] !== null){
if(!$override and self::isRegistered($id)){
throw new \RuntimeException("Trying to overwrite an already registered item");
}
@ -350,4 +350,14 @@ class ItemFactory{
return $item;
}
}
/**
* Returns whether the specified item ID is already registered in the item factory.
*
* @param int $id
* @return bool
*/
public static function isRegistered(int $id) : bool{
return self::$list[$id] !== null;
}
}