Skip to content
This repository has been archived by the owner on Nov 2, 2021. It is now read-only.

Commit

Permalink
Removed previous and next buttons if not enough achievements in category
Browse files Browse the repository at this point in the history
Related to discussions in #251.
  • Loading branch information
PyvesB committed Oct 30, 2017
1 parent 9c369a9 commit 4aa56b1
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/main/java/com/hm/achievement/gui/CategoryGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,11 @@ private void displayPage(String categoryName, Player player, Map<String, Long> s
int pageToDisplay = getPageToDisplay(requestedPage, achievementPaths.size());
int pageStart = MAX_PER_PAGE * (pageToDisplay - 1);
int pageEnd = Math.min(MAX_PER_PAGE * pageToDisplay, achievementPaths.size());
int navigationItems = achievementPaths.size() > MAX_PER_PAGE ? 3 : 1;

// Create a new chest-like inventory as small as possible whilst still containing all page achievements and
// navigation items.
int guiSize = nextMultipleOf9(achievementPaths.size() + 4, MAX_PER_PAGE);
// Create a new chest-like inventory as small as possible whilst still containing the category item, all page
// achievements and the navigation items.
int guiSize = nextMultipleOf9(achievementPaths.size() + navigationItems + 1, MAX_PER_PAGE);
Inventory inventory = Bukkit.createInventory(null, guiSize, langListGUITitle + " " + pageToDisplay);
// Persist clicked item (ie. category's item in the main GUI) as first item in the category GUI.
inventory.setItem(0, clickedItem);
Expand Down Expand Up @@ -210,9 +211,13 @@ private void displayPage(String categoryName, Player player, Map<String, Long> s
previousSubcategory = subcategory;
}
// Add navigation items.
inventory.setItem(pageEnd - pageStart + 1, previousButton);
inventory.setItem(pageEnd - pageStart + 2, nextButton);
inventory.setItem(pageEnd - pageStart + 3, backButton);
if (navigationItems > 1) {
inventory.setItem(pageEnd - pageStart + 1, previousButton);
inventory.setItem(pageEnd - pageStart + 2, nextButton);
inventory.setItem(pageEnd - pageStart + 3, backButton);
} else {
inventory.setItem(pageEnd - pageStart + 1, backButton);
}

// Display page.
player.openInventory(inventory);
Expand Down

0 comments on commit 4aa56b1

Please sign in to comment.