You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/main/java/me/kodysimpson/simpapi/menu/PaginatedMenu.java
+42-1Lines changed: 42 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,7 @@
7
7
8
8
publicabstractclassPaginatedMenuextendsMenu {
9
9
10
+
//The items being paginated
10
11
protectedList<Object> data;
11
12
12
13
//Keep track of what page the menu is on
@@ -22,11 +23,21 @@ public PaginatedMenu(PlayerMenuUtility playerMenuUtility) {
22
23
super(playerMenuUtility);
23
24
}
24
25
26
+
/**
27
+
* @param <T> The datatype of the data in the list
28
+
* @return A list of the data being paginated. usually this is a list of items but it can be anything
29
+
*/
25
30
publicabstract <T> List<T> getData();
26
31
32
+
/**
33
+
* @param object A single element of the data list that you do something with. It is recommended that you turn this into an item if it is not already and then put it into the inventory as you would with a normal Menu. You can execute any other logic in here as well.
34
+
*/
27
35
publicabstractvoidloopCode(Objectobject);
28
36
29
-
//Set the border and menu buttons for the menu
37
+
38
+
/**
39
+
* Set the border and menu buttons for the menu. Override this method to provide a custom menu border
* Place each item in the paginated menu, automatically coded by default but override if you want custom functionality. Calls the loopCode() method you define for each item returned in the getData() method
70
+
*/
57
71
@Override
58
72
publicvoidsetMenuItems() {
59
73
@@ -64,6 +78,7 @@ public void setMenuItems() {
64
78
if (data != null && !data.isEmpty()) {
65
79
for (inti = 0; i < getMaxItemsPerPage(); i++) {
66
80
index = getMaxItemsPerPage() * page + i;
81
+
System.out.println(index);
67
82
if (index >= data.size()) break;
68
83
if (data.get(index) != null) {
69
84
loopCode(data.get(index)); //run the code defined by the user
@@ -74,6 +89,32 @@ public void setMenuItems() {
74
89
75
90
}
76
91
92
+
/**
93
+
* @return true if successful, false if already on the first page
94
+
*/
95
+
publicbooleanprevPage(){
96
+
if (page == 0){
97
+
returnfalse;
98
+
}else{
99
+
page = page - 1;
100
+
reload();
101
+
returntrue;
102
+
}
103
+
}
104
+
105
+
/**
106
+
* @return true if successful, false if already on the last page
0 commit comments