Skip to content

Commit

Permalink
Fetch upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubix327 committed Oct 15, 2022
2 parents 8948904 + 2217f0a commit e2ba31d
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/main/java/org/mineacademy/fo/menu/MenuPagged.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,23 +313,21 @@ private void setButtons() {
*/
public Button formPreviousButton() {
return new Button() {
final boolean canGo = MenuPagged.this.currentPage > 1;
final boolean canGo = getCurrentPage() > 1;

@Override
public void onClickedInMenu(final Player player, final AdvancedMenu menu, final ClickType click) {
if (this.canGo) {
MenuPagged.this.currentPage = MathUtil.range(MenuPagged.this.currentPage - 1, 1, MenuPagged.this.pages.size());

MenuPagged.this.updatePage();
setCurrentPage(MathUtil.range(getCurrentPage() - 1, 1, getPages().size()));
}
}

@Override
public ItemStack getItem() {
final int previousPage = MenuPagged.this.currentPage - 1;
final int previousPage = getCurrentPage() - 1;

return ItemCreator
.of(this.canGo ? activePageButton : inactivePageButton)
.of(this.canGo ? MenuPagged.getActivePageButton() : MenuPagged.getInactivePageButton())
.name(previousPage == 0 ? SimpleLocalization.Menu.PAGE_FIRST : SimpleLocalization.Menu.PAGE_PREVIOUS.replace("{page}", String.valueOf(previousPage)))
.make();
}
Expand All @@ -344,29 +342,38 @@ public ItemStack getItem() {
*/
public Button formNextButton() {
return new Button() {
final boolean canGo = MenuPagged.this.currentPage < MenuPagged.this.pages.size();
final boolean canGo = getCurrentPage() < getPages().size();

@Override
public void onClickedInMenu(final Player player, final AdvancedMenu menu, final ClickType click) {
if (this.canGo) {
MenuPagged.this.currentPage = MathUtil.range(MenuPagged.this.currentPage + 1, 1, MenuPagged.this.pages.size());

MenuPagged.this.updatePage();
setCurrentPage(MathUtil.range(getCurrentPage() + 1, 1, getPages().size()));
}
}

@Override
public ItemStack getItem() {
final boolean lastPage = MenuPagged.this.currentPage == MenuPagged.this.pages.size();
final boolean lastPage = getCurrentPage() == getPages().size();

return ItemCreator
.of(this.canGo ? activePageButton : inactivePageButton)
.name(lastPage ? SimpleLocalization.Menu.PAGE_LAST : SimpleLocalization.Menu.PAGE_NEXT.replace("{page}", String.valueOf(MenuPagged.this.currentPage + 1)))
.of(this.canGo ? MenuPagged.getActivePageButton() : MenuPagged.getInactivePageButton())
.name(lastPage ? SimpleLocalization.Menu.PAGE_LAST : SimpleLocalization.Menu.PAGE_NEXT.replace("{page}", String.valueOf(getCurrentPage() + 1)))
.make();
}
};
}

/**
* Shows items for the current page
*
* @param currentPage
*/
protected void setCurrentPage(int currentPage) {
this.currentPage = currentPage;

this.updatePage();
}

// Reinits the menu and plays the anvil sound
private void updatePage() {
this.setButtons();
Expand Down

0 comments on commit e2ba31d

Please sign in to comment.