Skip to content

Commit

Permalink
Fixed max page calculation on edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Jakob Mearns committed Dec 18, 2017
1 parent a0d24a3 commit f01fb44
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions com/cloutteam/samjakob/gui/types/PaginatedGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void setButton(int slot, GUIButton button){

@Override
public Inventory getInventory() {
Inventory inventory = Bukkit.createInventory(this, (getMaxPage() > 1) ? 54 : 45, name);
Inventory inventory = Bukkit.createInventory(this, (getMaxPage() > 0) ? 54 : 45, name);
// Include pagination
GUIButton backButton = new GUIButton(ItemBuilder.start(Material.ARROW).name(PREVIOUS_PAGE).build());
GUIButton pageIndicator = new GUIButton(ItemBuilder.start(Material.NAME_TAG)
Expand Down Expand Up @@ -93,7 +93,7 @@ public Inventory getInventory() {

if(currentPage > 0)
toolbarItems.put(3, backButton);
if(getMaxPage() > 1)
if(getMaxPage() > 0)
toolbarItems.put(4, pageIndicator);
if(currentPage < getMaxPage())
toolbarItems.put(5, nextButton);
Expand Down Expand Up @@ -145,7 +145,7 @@ public boolean previousPage(){
}

public int getMaxPage(){
return (int) Math.ceil(items.size() / 45);
return items.size() % 45 == 0 ? Math.round(items.size() / 45) - 1 : (int) Math.ceil(items.size() / 45);
}

public static void prepare(JavaPlugin plugin){
Expand Down

0 comments on commit f01fb44

Please sign in to comment.