fix page errors when less than a full page

This commit is contained in:
jascotty2 2019-09-10 09:44:59 -05:00
parent 721ad26106
commit 493ee0a0e6
3 changed files with 4 additions and 5 deletions

View File

@ -46,7 +46,7 @@ public class SongodaCore {
* Whenever we make a major change to the core GUI, updater,
* or other function used by the core, increment this number
*/
private final static int coreRevision = 4;
private final static int coreRevision = 5;
private final static int updaterVersion = 1;
private final static Set<PluginInfo> registeredPlugins = new HashSet<>();

View File

@ -636,7 +636,7 @@ public class Gui {
}
public void setPage(int page) {
int lastPage = page;
int lastPage = this.page;
this.page = Math.max(1, Math.min(pages, page));
if(pager != null && this.page != lastPage) {
pager.onPageChange(new GuiPageEvent(this, guiManager, lastPage, page));

View File

@ -7,7 +7,6 @@ import com.songoda.core.gui.methods.Clickable;
import java.util.List;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent;
@ -134,14 +133,14 @@ public class SimplePagedGui extends Gui {
rowsPerPage = useHeader ? 4 : 5;
maxCellSlot = (this.cellItems.isEmpty() ? 0 : this.cellItems.keySet().stream().max(Integer::compare).get()) + 1;
int maxRows = (int) Math.ceil(maxCellSlot / 9.);
pages = (int) Math.ceil(maxRows / rowsPerPage);
pages = (int) Math.max(1, Math.ceil(maxRows / (double) rowsPerPage));
this.setRows(maxRows + (useHeader ? 1 : 0));
// create inventory view
createInventory();
// populate and return the display inventory
page = Math.min(page, pages);
setPage(Math.min(page, pages));
update();
return inventory;
}