Skip to content

Commit

Permalink
Address #126
Browse files Browse the repository at this point in the history
  • Loading branch information
Muqsit committed Mar 17, 2024
1 parent 99545a4 commit f9e0125
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/muqsit/chestshop/category/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion src/muqsit/chestshop/category/CategoryPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}

Expand Down Expand Up @@ -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)){
Expand Down

0 comments on commit f9e0125

Please sign in to comment.