@@ -109,6 +109,7 @@ public List<MenuItem> getPageableItems() {
109
109
public PageableChestMenu setPageableItems (List <MenuItem > items ) {
110
110
this .pageableItems .clear ();
111
111
pageableItems .addAll (items );
112
+ this .page = 0 ;
112
113
requireUpdate (null );
113
114
return this ;
114
115
}
@@ -144,12 +145,34 @@ public Map.Entry<Integer, Integer> getPageableItemSlot(MenuItem item) {
144
145
* Get the quantity of pages of this menu.
145
146
* The quantity is defined by the amount
146
147
* of items inserted.
148
+ *
147
149
* @return the quantity of pages of this menu.
148
150
*/
149
151
public int getPageCount () {
150
152
return (int ) Math .max (1 , Math .ceil (this .pageableItems .size () / (double ) itemSlots .length ));
151
153
}
152
154
155
+ /**
156
+ * Get the current page the player
157
+ * is in.
158
+ *
159
+ * @param player the player to check the
160
+ * page.
161
+ * @return the current page index.
162
+ */
163
+ public int getCurrentPage (Player player ) {
164
+ if (this .fatherMenu != null && this .fatherMenu .inventory != null && this .fatherMenu .inventory .getViewers ().contains (player )) {
165
+ return this .fatherMenu .page ;
166
+ } else if (this .inventory != null && this .inventory .getViewers ().contains (player )) {
167
+ return this .page ;
168
+ } else {
169
+ Optional <PageableChestMenu > menu = mirrorMenus .stream ().filter (m -> m .inventory != null && m .inventory .getViewers ().contains (player )).findFirst ();
170
+ if (menu .isPresent ()) return menu .get ().page ;
171
+ }
172
+
173
+ return 0 ;
174
+ }
175
+
153
176
/**
154
177
* Set the item used to go to the next page.
155
178
* This item is only shown if there is enough items
@@ -281,11 +304,15 @@ public MenuItem getItem(Integer slot) {
281
304
282
305
@ Override
283
306
public void open (Player player ) {
307
+ open (player , 0 );
308
+ }
309
+
310
+ public void open (Player player , int page ) {
284
311
if (this .inventory == null || !super .hasViewers ()) {
285
- this .page = 0 ;
312
+ this .page = Math . min ( getPageCount () - 1 , page ) ;
286
313
requireUpdate (null );
287
314
super .open (player );
288
- } else new PageableChestMenu (this ).open (player );
315
+ } else new PageableChestMenu (this ).open (player , page );
289
316
}
290
317
291
318
@ Override
0 commit comments