Skip to content

Commit 2b747fb

Browse files
committed
working on pagination
1 parent d8f7026 commit 2b747fb

4 files changed

Lines changed: 30 additions & 4 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>me.kodysimpson</groupId>
88
<artifactId>SimpAPI</artifactId>
9-
<version>4.1.81</version>
9+
<version>4.1.84</version>
1010
<packaging>jar</packaging>
1111

1212
<name>SimpAPI</name>

src/main/java/me/kodysimpson/simpapi/menu/Menu.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ public void back() throws MenuManagerException, MenuManagerNotSetupException {
6666
MenuManager.openMenu(playerMenuUtility.lastMenu().getClass(), playerMenuUtility.getOwner());
6767
}
6868

69+
protected void reload() throws MenuManagerException, MenuManagerNotSetupException {
70+
p.closeInventory();
71+
MenuManager.openMenu(this.getClass(), playerMenuUtility.getOwner());
72+
}
73+
6974
//Overridden method from the InventoryHolder interface
7075
@Override
7176
public @NotNull Inventory getInventory() {

src/main/java/me/kodysimpson/simpapi/menu/MenuManager.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,7 @@ public static void openMenu(Class<? extends Menu> menuClass, Player player) thro
7979
try {
8080
menuClass.getConstructor(PlayerMenuUtility.class).newInstance(getPlayerMenuUtility(player)).open();
8181
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
82-
System.out.println(e);
83-
System.out.println("STACK TRACEEEEE");
8482
e.printStackTrace();
85-
System.out.println("ENDING STACK TRAAACEEEE");
8683
throw new MenuManagerException();
8784
}
8885
}

src/main/java/me/kodysimpson/simpapi/menu/PaginatedMenu.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ public PaginatedMenu(PlayerMenuUtility playerMenuUtility) {
2222
super(playerMenuUtility);
2323
}
2424

25+
public abstract List<Object> getData();
26+
27+
public abstract void loopCode(Object object);
28+
2529
//Set the border and menu buttons for the menu
2630
public void addMenuBorder(){
2731
inventory.setItem(48, makeItem(Material.DARK_OAK_BUTTON, ChatColor.GREEN + "Left"));
@@ -50,6 +54,26 @@ public void addMenuBorder(){
5054
}
5155
}
5256

57+
@Override
58+
public void setMenuItems() {
59+
60+
addMenuBorder();
61+
62+
List<Object> data = getData();
63+
64+
if (data != null && !data.isEmpty()) {
65+
for (int i = 0; i < getMaxItemsPerPage(); i++) {
66+
index = getMaxItemsPerPage() * page + i;
67+
if (index >= data.size()) break;
68+
if (data.get(index) != null) {
69+
loopCode(data.get(index)); //run the code defined by the user
70+
}
71+
}
72+
}
73+
74+
75+
}
76+
5377
public int getMaxItemsPerPage() {
5478
return maxItemsPerPage;
5579
}

0 commit comments

Comments
 (0)