@@ -37,7 +37,7 @@ public final class PaginatedMenu extends BaseMenu<PaginatedMenu> {
37
37
38
38
private static final BukkitScheduler sch = Bukkit .getScheduler ();
39
39
40
- public PaginatedMenu updateTitle (String title ) {
40
+ PaginatedMenu updateTitle (String title , Inventory inventory ) {
41
41
String colorizedTitle = translateAlternateColorCodes ('&' , title );
42
42
Inventory updatedInventory = type == MenuType .CHEST
43
43
? Bukkit .createInventory (this , size , colorizedTitle )
@@ -52,6 +52,10 @@ public PaginatedMenu updateTitle(String title) {
52
52
return this ;
53
53
}
54
54
55
+ public PaginatedMenu updateTitle (String title ) {
56
+ return this .updateTitle (title , getInventory ());
57
+ }
58
+
55
59
public <T extends Decorator > T getPageDecorator (Class <T > pageClass ) {
56
60
return pageClass .cast (pageDecorator );
57
61
}
@@ -64,16 +68,6 @@ public void addPage() {
64
68
pageList .add (Page .of (this ));
65
69
}
66
70
67
- @ Override
68
- public PaginatedMenu update () {
69
- this .updating = true ;
70
- this .recreateItems ();
71
- List <HumanEntity > entities = ImmutableList .copyOf (inventory .getViewers ());
72
- entities .forEach (e -> ((Player ) e ).updateInventory ());
73
- this .updating = false ;
74
- return this ;
75
- }
76
-
77
71
/**
78
72
* Main constructor to provide a way to create PaginatedMenu
79
73
*
@@ -123,6 +117,20 @@ public static PaginatedMenu create(String title, int rows, int pages, EnumSet<Mo
123
117
public static PaginatedMenu create (String title , MenuType type , int pages , EnumSet <Modifier > modifiers ) {
124
118
return new PaginatedMenu (type , pages , title , modifiers );
125
119
}
120
+
121
+ PaginatedMenu update (Inventory inventory ) {
122
+ this .updating = true ;
123
+ recreateItems (inventory );
124
+ List <HumanEntity > entities = new ArrayList <>(inventory .getViewers ());
125
+ entities .forEach (e -> ((Player ) e ).updateInventory ());
126
+ this .updating = false ;
127
+ return this ;
128
+ }
129
+
130
+ @ Override
131
+ public PaginatedMenu update () {
132
+ return this .update (getInventory ());
133
+ }
126
134
127
135
/**
128
136
* Sets the next page item for the given slot with the provided item stack.
@@ -267,25 +275,23 @@ public void updateItem(@NotNull Slot slot, @NotNull final MenuItem item) {
267
275
}
268
276
269
277
@ Override
270
- public PaginatedMenu removeItems (@ NotNull final MenuItem ... item ) {
271
- currentPage .removeItem (item );
272
- return this ;
273
- }
274
-
275
- @ Override
276
- public PaginatedMenu removeItems (@ NotNull final ItemStack ... item ) {
278
+ public PaginatedMenu removeItem (@ NotNull final MenuItem ... item ) {
277
279
currentPage .removeItem (item );
278
280
return this ;
279
281
}
280
282
283
+ /**
284
+ * @param itemStacks the items to remove
285
+ * @return the object for chaining
286
+ */
281
287
@ Override
282
- public PaginatedMenu removeItem (@ NotNull final ItemStack item ) {
283
- currentPage .removeItem (item );
288
+ public PaginatedMenu removeItem (@ NotNull List < MenuItem > itemStacks ) {
289
+ currentPage .removeItem (itemStacks . toArray ( new MenuItem [ 0 ]) );
284
290
return this ;
285
291
}
286
292
287
293
@ Override
288
- public PaginatedMenu removeItem (@ NotNull final MenuItem item ) {
294
+ public PaginatedMenu removeItem (@ NotNull final ItemStack ... item ) {
289
295
currentPage .removeItem (item );
290
296
return this ;
291
297
}
@@ -378,7 +384,7 @@ public void open(@NotNull final HumanEntity player, final int openPage) {
378
384
this .pageNum = openPage ;
379
385
this .currentPage = pageList .get (openPage );
380
386
381
- recreateItems ();
387
+ update ();
382
388
player .openInventory (inventory );
383
389
}
384
390
@@ -411,8 +417,7 @@ public int getPagesSize() {
411
417
return pageList .size ();
412
418
}
413
419
414
- @ Override
415
- protected void recreateItems () {
420
+ protected void recreateItems (Inventory inventory ) {
416
421
final int endIndex = currentPage .size ();
417
422
418
423
for (int i = 0 ; i < endIndex ; i ++) {
@@ -432,7 +437,7 @@ public boolean next() {
432
437
pageNum ++;
433
438
this .currentPage = pageList .get (pageNum );
434
439
435
- recreateItems ();
440
+ update ();
436
441
return true ;
437
442
}
438
443
@@ -447,7 +452,7 @@ public boolean previous() {
447
452
pageNum --;
448
453
this .currentPage = pageList .get (pageNum );
449
454
450
- recreateItems ();
455
+ update ();
451
456
return true ;
452
457
}
453
458
@@ -462,7 +467,7 @@ public boolean page(int pageNum) {
462
467
this .pageNum = pageNum ;
463
468
this .currentPage = pageList .get (pageNum );
464
469
465
- recreateItems ();
470
+ update ();
466
471
return true ;
467
472
}
468
473
0 commit comments