Skip to content

Commit 54c5366

Browse files
committed
somewhat intelligle support for paginated menus
1 parent ea86a2e commit 54c5366

4 files changed

Lines changed: 51 additions & 8 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SimpAPI v4.1.8
1+
# SimpAPI v4.1.9
22
****
33
SimpAPI, finally a good API that can make coding MC Plugins much easier and less painful.
44
This API includes all of my primary utilities like *Menu Manager*, *Command Manager*, *ColorTranslator*, and more.
@@ -25,7 +25,7 @@ JavaDocs: https://kodysimpson.github.io/SimpAPI/index.html
2525
<dependency>
2626
<groupId>com.github.KodySimpson</groupId>
2727
<artifactId>SimpAPI</artifactId>
28-
<version>4.1.8</version>
28+
<version>4.1.9</version>
2929
</dependency>
3030
```
3131

@@ -51,7 +51,7 @@ repositories {
5151
Groovy/Kotlin:
5252
```groovy
5353
dependencies {
54-
implementation 'com.github.KodySimpson:SimpAPI:4.1.8'
54+
implementation 'com.github.KodySimpson:SimpAPI:4.1.9'
5555
}
5656
```
5757

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.85</version>
9+
<version>4.1.9</version>
1010
<packaging>jar</packaging>
1111

1212
<name>SimpAPI</name>

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +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());
69+
protected void reload() {
70+
for (int i = 0; i < inventory.getSize(); i++){
71+
inventory.setItem(i, null);
72+
}
73+
setMenuItems();
7274
}
7375

7476
//Overridden method from the InventoryHolder interface

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

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
public abstract class PaginatedMenu extends Menu {
99

10+
//The items being paginated
1011
protected List<Object> data;
1112

1213
//Keep track of what page the menu is on
@@ -22,11 +23,21 @@ public PaginatedMenu(PlayerMenuUtility playerMenuUtility) {
2223
super(playerMenuUtility);
2324
}
2425

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+
*/
2530
public abstract <T> List<T> getData();
2631

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+
*/
2735
public abstract void loopCode(Object object);
2836

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
40+
*/
3041
protected void addMenuBorder(){
3142
inventory.setItem(48, makeItem(Material.DARK_OAK_BUTTON, ChatColor.GREEN + "Left"));
3243

@@ -54,6 +65,9 @@ protected void addMenuBorder(){
5465
}
5566
}
5667

68+
/**
69+
* 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+
*/
5771
@Override
5872
public void setMenuItems() {
5973

@@ -64,6 +78,7 @@ public void setMenuItems() {
6478
if (data != null && !data.isEmpty()) {
6579
for (int i = 0; i < getMaxItemsPerPage(); i++) {
6680
index = getMaxItemsPerPage() * page + i;
81+
System.out.println(index);
6782
if (index >= data.size()) break;
6883
if (data.get(index) != null) {
6984
loopCode(data.get(index)); //run the code defined by the user
@@ -74,6 +89,32 @@ public void setMenuItems() {
7489

7590
}
7691

92+
/**
93+
* @return true if successful, false if already on the first page
94+
*/
95+
public boolean prevPage(){
96+
if (page == 0){
97+
return false;
98+
}else{
99+
page = page - 1;
100+
reload();
101+
return true;
102+
}
103+
}
104+
105+
/**
106+
* @return true if successful, false if already on the last page
107+
*/
108+
public boolean nextPage(){
109+
if (!((index + 1) >= getData().size())) {
110+
page = page + 1;
111+
reload();
112+
return true;
113+
} else {
114+
return false;
115+
}
116+
}
117+
77118
public int getMaxItemsPerPage() {
78119
return maxItemsPerPage;
79120
}

0 commit comments

Comments
 (0)