Skip to content

Commit cbba7dd

Browse files
Fix at BaseMenu#addItem(MenuItem)
It was the only addItem method that was 0 indexed and also the only method I tested when adding items haha and even woody was advertised to be 1 indexed
1 parent 0c01b31 commit cbba7dd

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

src/main/java/me/flame/menus/menu/BaseMenu.java

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package me.flame.menus.menu;
22

3-
import com.google.common.collect.Lists;
43
import lombok.Getter;
54
import lombok.Setter;
65
import lombok.val;
@@ -30,6 +29,8 @@
3029

3130
import static org.bukkit.ChatColor.translateAlternateColorCodes;
3231

32+
// changed
33+
3334
@SuppressWarnings({ "unused", "BooleanMethodIsAlwaysInverted",
3435
"unchecked", "UnusedReturnValue" })
3536
public abstract class BaseMenu<M extends BaseMenu<M>>
@@ -107,6 +108,20 @@ public MenuIterator iterator(MenuIterator.IterationDirection direction) {
107108
return new MenuIterator(0, 0, direction, this);
108109
}
109110

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+
110125
/**
111126
* Get a stream loop of the items in the menu
112127
* @return the stream
@@ -124,18 +139,6 @@ public Stream<MenuItem> parallelStream() {
124139
return itemMap.values().parallelStream();
125140
}
126141

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-
139142
private void recreateInventory() {
140143
this.rows++;
141144
this.size = rows * 9;
@@ -310,7 +313,7 @@ public M addItem(MenuItem item) {
310313
if (!dynamicSizing || this.rows >= 6 || type != MenuType.CHEST) return (M) this;
311314
recreateInventory();
312315
}
313-
itemMap.put(size, item);
316+
itemMap.put(size + 1, item);
314317
return (M) this;
315318
}
316319

@@ -434,6 +437,18 @@ public boolean hasItem(@NotNull Slot slot) {
434437
return itemMap.get(slot.getSlot()) != null;
435438
}
436439

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+
437452
/**
438453
* get the itemStack from the list of items in the menu from the provided description of the itemStack
439454
* <p></p>

0 commit comments

Comments
 (0)