From d4fe0043759bbc743b7268f1ee612e7c1b731103 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 23 Mar 2019 12:20:35 +0000 Subject: [PATCH] More consistent fluency in Item API --- src/pocketmine/item/Armor.php | 5 ++++- src/pocketmine/item/Banner.php | 5 ++++- src/pocketmine/item/Durable.php | 5 ++++- src/pocketmine/item/WritableBook.php | 31 +++++++++++++++------------- src/pocketmine/item/WrittenBook.php | 15 +++++++++++--- 5 files changed, 41 insertions(+), 20 deletions(-) diff --git a/src/pocketmine/item/Armor.php b/src/pocketmine/item/Armor.php index 4f8812b214..f2ceb5adfa 100644 --- a/src/pocketmine/item/Armor.php +++ b/src/pocketmine/item/Armor.php @@ -83,9 +83,12 @@ abstract class Armor extends Durable{ * Sets the dyed colour of this armour piece. This generally only applies to leather armour. * * @param Color $color + * + * @return $this */ - public function setCustomColor(Color $color) : void{ + public function setCustomColor(Color $color) : self{ $this->getNamedTag()->setInt(self::TAG_CUSTOM_COLOR, Binary::signInt($color->toARGB())); + return $this; } /** diff --git a/src/pocketmine/item/Banner.php b/src/pocketmine/item/Banner.php index 469e0f3b2b..08126eb023 100644 --- a/src/pocketmine/item/Banner.php +++ b/src/pocketmine/item/Banner.php @@ -77,8 +77,10 @@ class Banner extends Item{ /** * @param Deque|BannerPattern[] $patterns + * + * @return $this */ - public function setPatterns(Deque $patterns) : void{ + public function setPatterns(Deque $patterns) : self{ $tag = new ListTag(); /** @var BannerPattern $pattern */ foreach($patterns as $pattern){ @@ -88,6 +90,7 @@ class Banner extends Item{ ); } $this->getNamedTag()->setTag(self::TAG_PATTERNS, $tag); + return $this; } public function getFuelTime() : int{ diff --git a/src/pocketmine/item/Durable.php b/src/pocketmine/item/Durable.php index b30610fca4..68e40e87d7 100644 --- a/src/pocketmine/item/Durable.php +++ b/src/pocketmine/item/Durable.php @@ -48,9 +48,12 @@ abstract class Durable extends Item{ * Sets whether the item will take damage when used. * * @param bool $value + * + * @return $this */ - public function setUnbreakable(bool $value = true) : void{ + public function setUnbreakable(bool $value = true) : self{ $this->getNamedTag()->setByte("Unbreakable", $value ? 1 : 0); + return $this; } /** diff --git a/src/pocketmine/item/WritableBook.php b/src/pocketmine/item/WritableBook.php index cc1a311cf7..bb97e726e2 100644 --- a/src/pocketmine/item/WritableBook.php +++ b/src/pocketmine/item/WritableBook.php @@ -75,13 +75,11 @@ class WritableBook extends Item{ * @param int $pageId * @param string $pageText * - * @return bool indicating whether the page was created or not. + * @return $this */ - public function setPageText(int $pageId, string $pageText) : bool{ - $created = false; + public function setPageText(int $pageId, string $pageText) : self{ if(!$this->pageExists($pageId)){ $this->addPage($pageId); - $created = true; } /** @var CompoundTag[]|ListTag $pagesTag */ @@ -92,7 +90,7 @@ class WritableBook extends Item{ $this->getNamedTag()->setTag(self::TAG_PAGES, $pagesTag); - return $created; + return $this; } /** @@ -100,8 +98,10 @@ class WritableBook extends Item{ * Creates a new page for every page between the given ID and existing pages that doesn't yet exist. * * @param int $pageId + * + * @return $this */ - public function addPage(int $pageId) : void{ + public function addPage(int $pageId) : self{ if($pageId < 0){ throw new \InvalidArgumentException("Page number \"$pageId\" is out of range"); } @@ -116,6 +116,7 @@ class WritableBook extends Item{ } $this->getNamedTag()->setTag(self::TAG_PAGES, $pagesTag); + return $this; } /** @@ -123,13 +124,13 @@ class WritableBook extends Item{ * * @param int $pageId * - * @return bool indicating success + * @return $this */ - public function deletePage(int $pageId) : bool{ + public function deletePage(int $pageId) : self{ $pagesTag = $this->getPagesTag(); $pagesTag->remove($pageId); - return true; + return $this; } /** @@ -138,9 +139,9 @@ class WritableBook extends Item{ * @param int $pageId * @param string $pageText * - * @return bool indicating success + * @return $this */ - public function insertPage(int $pageId, string $pageText = "") : bool{ + public function insertPage(int $pageId, string $pageText = "") : self{ $pagesTag = $this->getPagesTag(); $pagesTag->insert($pageId, CompoundTag::create() @@ -150,7 +151,7 @@ class WritableBook extends Item{ $this->getNamedTag()->setTag(self::TAG_PAGES, $pagesTag); - return true; + return $this; } /** @@ -197,12 +198,14 @@ class WritableBook extends Item{ } /** - * * @param CompoundTag[] $pages + * + * @return $this */ - public function setPages(array $pages) : void{ + public function setPages(array $pages) : self{ $nbt = $this->getNamedTag(); $nbt->setTag(self::TAG_PAGES, new ListTag($pages, NBT::TAG_Compound)); $this->setNamedTag($nbt); + return $this; } } diff --git a/src/pocketmine/item/WrittenBook.php b/src/pocketmine/item/WrittenBook.php index 1be3b5025f..37c4dd02de 100644 --- a/src/pocketmine/item/WrittenBook.php +++ b/src/pocketmine/item/WrittenBook.php @@ -56,14 +56,17 @@ class WrittenBook extends WritableBook{ * Sets the generation of a book. * * @param int $generation + * + * @return $this */ - public function setGeneration(int $generation) : void{ + public function setGeneration(int $generation) : self{ if($generation < 0 or $generation > 3){ throw new \InvalidArgumentException("Generation \"$generation\" is out of range"); } $namedTag = $this->getNamedTag(); $namedTag->setInt(self::TAG_GENERATION, $generation); $this->setNamedTag($namedTag); + return $this; } /** @@ -81,11 +84,14 @@ class WrittenBook extends WritableBook{ * Sets the author of this book. * * @param string $authorName + * + * @return $this */ - public function setAuthor(string $authorName) : void{ + public function setAuthor(string $authorName) : self{ $namedTag = $this->getNamedTag(); $namedTag->setString(self::TAG_AUTHOR, $authorName); $this->setNamedTag($namedTag); + return $this; } /** @@ -101,10 +107,13 @@ class WrittenBook extends WritableBook{ * Sets the author of this book. * * @param string $title + * + * @return $this */ - public function setTitle(string $title) : void{ + public function setTitle(string $title) : self{ $namedTag = $this->getNamedTag(); $namedTag->setString(self::TAG_TITLE, $title); $this->setNamedTag($namedTag); + return $this; } }