From f9e0125ecf1f4bbc696a586457008e0e61063738 Mon Sep 17 00:00:00 2001 From: Muqsit Date: Sun, 17 Mar 2024 21:22:33 +0000 Subject: [PATCH] Address #126 --- src/muqsit/chestshop/category/Category.php | 2 +- src/muqsit/chestshop/category/CategoryPage.php | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/muqsit/chestshop/category/Category.php b/src/muqsit/chestshop/category/Category.php index 0930d15..c5d4273 100644 --- a/src/muqsit/chestshop/category/Category.php +++ b/src/muqsit/chestshop/category/Category.php @@ -48,7 +48,7 @@ public function send(Player $player, int $page = 1) : bool{ public function addEntry(CategoryEntry $entry, bool $update = true) : void{ $page = $this->pages[count($this->pages) - 1] ?? null; - if($page === null){ + if($page === null || $page->isFull()){ $page = new CategoryPage(); $page->init($this->database, $this); $this->pages[] = $page; diff --git a/src/muqsit/chestshop/category/CategoryPage.php b/src/muqsit/chestshop/category/CategoryPage.php index fdeed1f..4d2d193 100644 --- a/src/muqsit/chestshop/category/CategoryPage.php +++ b/src/muqsit/chestshop/category/CategoryPage.php @@ -171,7 +171,7 @@ public function updatePageNumber(Category $category, int $page) : void{ } public function addEntry(CategoryEntry $entry, bool $update) : void{ - if(count($this->entries) === self::MAX_ENTRIES_PER_PAGE){ + if($this->isFull()){ throw new OverflowException("Cannot add more than " . self::MAX_ENTRIES_PER_PAGE . " entries to a page."); } @@ -211,6 +211,10 @@ public function isEmpty() : bool{ return count($this->entries) === 0; } + public function isFull() : bool{ + return count($this->entries) >= self::MAX_ENTRIES_PER_PAGE; + } + public function removeItem(Item $item) : bool{ foreach($this->entries as $slot => $entry){ if($entry->getItem()->equals($item)){