Item->getNamedTag() now always returns a CompoundTag object, removed lots of boilerplate code

This change resulted from many complaints and ugly boilerplate code because getNamedTag() is only ever used when you want to read from the tag or modify it. If you have code that depends on this returning null, you should use hasCompoundTag() instead.
This commit is contained in:
Dylan K. Taylor
2017-10-08 12:41:57 +01:00
parent 00bf190e54
commit e8453b7872
3 changed files with 19 additions and 69 deletions

View File

@ -90,7 +90,7 @@ class WritableBook extends Item{
if($pageId < 0){
throw new \InvalidArgumentException("Page number \"$pageId\" is out of range");
}
$namedTag = $this->getCorrectedNamedTag();
$namedTag = $this->getNamedTag();
if(!isset($namedTag->pages) or !($namedTag->pages instanceof ListTag)){
$namedTag->pages = new ListTag("pages", []);
@ -137,7 +137,7 @@ class WritableBook extends Item{
* @return bool indicating success
*/
public function insertPage(int $pageId, string $pageText = "") : bool{
$namedTag = $this->getCorrectedNamedTag();
$namedTag = $this->getNamedTag();
if(!isset($namedTag->pages) or !($namedTag->pages instanceof ListTag)){
$namedTag->pages = new ListTag("pages", []);
}
@ -169,13 +169,6 @@ class WritableBook extends Item{
return true;
}
/**
* @return CompoundTag
*/
protected function getCorrectedNamedTag() : CompoundTag{
return $this->getNamedTag() ?? new CompoundTag();
}
public function getMaxStackSize() : int{
return 1;
}
@ -216,7 +209,7 @@ class WritableBook extends Item{
* @return CompoundTag[]
*/
public function getPages() : array{
$namedTag = $this->getCorrectedNamedTag();
$namedTag = $this->getNamedTag();
if(!isset($namedTag->pages)){
return [];
}