Skip to content

Commit f8b9f89

Browse files
authored
Only render pagination items if needed
Fixes #1
1 parent 3fb191f commit f8b9f89

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/main/java/com/samjakob/spigui/SGMenu.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -615,9 +615,11 @@ public Inventory getInventory() {
615615
if (isAutomaticPaginationEnabled() != null) {
616616
isAutomaticPaginationEnabled = isAutomaticPaginationEnabled();
617617
}
618+
619+
boolean needsPagination = getMaxPage() > 0 && isAutomaticPaginationEnabled;
618620

619621
Inventory inventory = Bukkit.createInventory(this, (
620-
(getMaxPage() > 0 && isAutomaticPaginationEnabled)
622+
(needsPagination)
621623
// Pagination enabled: add the bottom toolbar row.
622624
? getPageSize() + 9
623625
// Pagination not required or disabled.
@@ -644,19 +646,21 @@ public Inventory getInventory() {
644646
}
645647

646648
// Render the pagination items.
647-
SGPaginationButtonBuilder paginationButtonBuilder = spiGUI.getDefaultPaginationButtonBuilder();
648-
if (getPaginationButtonBuilder() != null) {
649-
paginationButtonBuilder = getPaginationButtonBuilder();
650-
}
649+
if (needsPagination) {
650+
SGPaginationButtonBuilder paginationButtonBuilder = spiGUI.getDefaultPaginationButtonBuilder();
651+
if (getPaginationButtonBuilder() != null) {
652+
paginationButtonBuilder = getPaginationButtonBuilder();
653+
}
651654

652-
int pageSize = getPageSize();
653-
for (int i = pageSize; i < pageSize + 9; i++) {
654-
int offset = i - pageSize;
655+
int pageSize = getPageSize();
656+
for (int i = pageSize; i < pageSize + 9; i++) {
657+
int offset = i - pageSize;
655658

656-
SGButton paginationButton = paginationButtonBuilder.buildPaginationButton(
657-
SGPaginationButtonType.forSlot(offset),this
658-
);
659-
inventory.setItem(i, paginationButton != null ? paginationButton.getIcon() : null);
659+
SGButton paginationButton = paginationButtonBuilder.buildPaginationButton(
660+
SGPaginationButtonType.forSlot(offset),this
661+
);
662+
inventory.setItem(i, paginationButton != null ? paginationButton.getIcon() : null);
663+
}
660664
}
661665

662666
return inventory;

0 commit comments

Comments
 (0)