mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 17:59:48 +00:00
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:
@ -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 [];
|
||||
}
|
||||
|
Reference in New Issue
Block a user