diff --git a/gui/base/src/main/java/it/angrybear/yagl/guis/DataGUI.java b/gui/base/src/main/java/it/angrybear/yagl/guis/DataGUI.java index dd5f31bb..22b4e818 100644 --- a/gui/base/src/main/java/it/angrybear/yagl/guis/DataGUI.java +++ b/gui/base/src/main/java/it/angrybear/yagl/guis/DataGUI.java @@ -136,12 +136,19 @@ public void open(@NotNull Viewer viewer, int page) { } private @NotNull GUI fillContents(final @NotNull GUI gui, final int page) { - int emptySlots = gui.emptySlots().size(); + int emptySlots = emptySlots().size(); + if (this.previousPage.isPresent()) emptySlots--; + if (this.nextPage.isPresent()) emptySlots--; int min = emptySlots * page; - int max = emptySlots * (page + 1); - int size = this.data.size(); - for (int i = Math.min(min, size); i < Math.min(max, size); i++) - gui.addContent(this.dataConverter.apply(this.data.get(i))); + if (min >= this.data.size()) + throw new IllegalArgumentException(String.format("No such page '%s'", page)); + if (page > 0) min++; + int size = Math.min(gui.emptySlots().size() + min, this.data.size()); + for (int i = min; i < size; i++) { + T data = this.data.get(i); + GUIContent content = this.dataConverter.apply(data); + gui.addContent(content); + } return gui; }