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

@ -63,7 +63,7 @@ class WrittenBook extends WritableBook{
if($generation < 0 or $generation > 3){
throw new \InvalidArgumentException("Generation \"$generation\" is out of range");
}
$namedTag = $this->getCorrectedNamedTag();
$namedTag = $this->getNamedTag();
if(isset($namedTag->generation)){
$namedTag->generation->setValue($generation);
@ -93,7 +93,7 @@ class WrittenBook extends WritableBook{
* @param string $authorName
*/
public function setAuthor(string $authorName) : void{
$namedTag = $this->getCorrectedNamedTag();
$namedTag = $this->getNamedTag();
if(isset($namedTag->author)){
$namedTag->author->setValue($authorName);
}else{
@ -120,7 +120,7 @@ class WrittenBook extends WritableBook{
* @param string $title
*/
public function setTitle(string $title) : void{
$namedTag = $this->getCorrectedNamedTag();
$namedTag = $this->getNamedTag();
if(isset($namedTag->title)){
$namedTag->title->setValue($title);
}else{