1
1
package me .flame .menus .menu ;
2
2
3
- import com .google .common .collect .Lists ;
4
3
import lombok .Getter ;
5
4
import lombok .Setter ;
6
5
import lombok .val ;
30
29
31
30
import static org .bukkit .ChatColor .translateAlternateColorCodes ;
32
31
32
+ // changed
33
+
33
34
@ SuppressWarnings ({ "unused" , "BooleanMethodIsAlwaysInverted" ,
34
35
"unchecked" , "UnusedReturnValue" })
35
36
public abstract class BaseMenu <M extends BaseMenu <M >>
@@ -107,6 +108,20 @@ public MenuIterator iterator(MenuIterator.IterationDirection direction) {
107
108
return new MenuIterator (0 , 0 , direction , this );
108
109
}
109
110
111
+ /**
112
+ * Get a LIST iterator of the items in the menu
113
+ * @param direction the direction of the iteration
114
+ * @return the list iterator
115
+ */
116
+ public MenuIterator iterator (int startingRow , int startingCol , MenuIterator .IterationDirection direction ) {
117
+ return new MenuIterator (
118
+ startingRow ,
119
+ startingCol ,
120
+ direction ,
121
+ this
122
+ );
123
+ }
124
+
110
125
/**
111
126
* Get a stream loop of the items in the menu
112
127
* @return the stream
@@ -124,18 +139,6 @@ public Stream<MenuItem> parallelStream() {
124
139
return itemMap .values ().parallelStream ();
125
140
}
126
141
127
- /**
128
- * Loop through the items in the menu (aka everything from "itemMap.values()")
129
- * <p>
130
- * It continues until there are no elements left or the action throws an exception
131
- * @param action The action to be performed for each element
132
- */
133
- public void forEach (Consumer <? super MenuItem > action ) {
134
- for (Map .Entry <Integer , MenuItem > entry : this .itemMap .entrySet ()) {
135
- action .accept (entry .getValue ());
136
- }
137
- }
138
-
139
142
private void recreateInventory () {
140
143
this .rows ++;
141
144
this .size = rows * 9 ;
@@ -310,7 +313,7 @@ public M addItem(MenuItem item) {
310
313
if (!dynamicSizing || this .rows >= 6 || type != MenuType .CHEST ) return (M ) this ;
311
314
recreateInventory ();
312
315
}
313
- itemMap .put (size , item );
316
+ itemMap .put (size + 1 , item );
314
317
return (M ) this ;
315
318
}
316
319
@@ -434,6 +437,18 @@ public boolean hasItem(@NotNull Slot slot) {
434
437
return itemMap .get (slot .getSlot ()) != null ;
435
438
}
436
439
440
+ public boolean hasItem (int slot ) {
441
+ return itemMap .get (slot ) != null ;
442
+ }
443
+
444
+ public boolean hasItem (ItemStack item ) {
445
+ return getItem (itemOne -> itemOne .getItemStack ().equals (item )) != null ;
446
+ }
447
+
448
+ public boolean hasItem (MenuItem item ) {
449
+ return getItem (itemOne -> itemOne .equals (item )) != null ;
450
+ }
451
+
437
452
/**
438
453
* get the itemStack from the list of items in the menu from the provided description of the itemStack
439
454
* <p></p>
0 commit comments