Skip to content

Commit 02caa38

Browse files
committed
Quick Iterator Fixes
1 parent 7305600 commit 02caa38

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/main/java/me/flame/menus/menu/iterator/MenuIterator.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import me.flame.menus.menu.BaseMenu;
44
import me.flame.menus.menu.Slot;
55
import org.jetbrains.annotations.NotNull;
6+
import org.jetbrains.annotations.Nullable;
67

78
/**
89
*
@@ -30,24 +31,34 @@ public MenuIterator(int startingRow, int startingCol,
3031
this.direction = direction;
3132
}
3233

33-
public Slot nextSlot(boolean emptyOnly) {
34-
34+
public @Nullable Slot nextSlot(boolean emptyOnly) {
3535

3636
if(!emptyOnly) {
3737
Slot newPos = direction.shift(currentPosition, menu.getRows());
38+
if(newPos.getRow() >= menu.getRows() || newPos.getRow() < 0
39+
|| newPos.getColumn() > 8 || newPos.getColumn() < 0) {
40+
return null;
41+
}
3842
currentPosition = newPos;
3943
return newPos;
4044
}
4145

4246
while(menu.getOptionalItem(currentPosition).isPresent()) {
43-
currentPosition = direction.shift(currentPosition, menu.getRows());
47+
Slot shiftedPos = direction.shift(currentPosition, menu.getRows());
48+
49+
if(shiftedPos.getRow() >= menu.getRows() || shiftedPos.getRow() < 0
50+
|| shiftedPos.getColumn() > 8 || shiftedPos.getColumn() < 0) {
51+
return null;
52+
}
53+
54+
currentPosition = shiftedPos;
4455
}
4556

4657
//when it becomes empty
4758
return currentPosition;
4859
}
4960

50-
public Slot nextSlot() {
61+
public @Nullable Slot nextSlot() {
5162
return nextSlot(false);
5263
}
5364

0 commit comments

Comments
 (0)