Skip to content

Commit a1d3434

Browse files
Fix a few Bugs
no errors or anything, but the last slot would always be ignored because it's rows * 9 - 1 but it should be rows * 9. Also remove the unnecessary math: (excluding the - 1) (rows * 9) + 9 - 9 to rows * 9
1 parent 316b5d9 commit a1d3434

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

src/main/java/me/flame/menus/menu/layout/MenuLayoutBuilder.java

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,14 @@ public static MenuLayoutBuilder bind(Map<Character, MenuItem> itemMap) {
6969
* @param title the title of the menu
7070
* @return the created menu
7171
*/
72-
public Menu createMenu(String title) {
72+
public @NotNull Menu createMenu(String title) {
7373
if (patterns == null)
74-
throw new IllegalStateException("No patterns specified. Use the pattern() method before creating the menu.");
74+
throw new IllegalStateException("No patterns specified. \nFix: use the pattern() method before creating the menu.");
75+
else if (rows > 6 || rows < 1)
76+
throw new IllegalStateException("Patterns array has too many rows (" + rows + "). \nFix: Reduce/increase the amount of strings in the array of pattern()");
7577
Menu menu = Menu.create(title, rows);
7678

77-
int size = ((rows * 9) + 9) - 10;
79+
int size = rows * 9;
7880
for (int i = 0; i < size; i++) {
7981
int row = i / 9;
8082
int col = i % 9;
@@ -95,10 +97,12 @@ public Menu createMenu(String title) {
9597
*/
9698
public Menu createMenu(String title, EnumSet<Modifier> modifiers) {
9799
if (patterns == null)
98-
throw new IllegalStateException("No patterns specified. Use the pattern() method before creating the menu.");
100+
throw new IllegalStateException("No patterns specified. \nFix: use the pattern() method before creating the menu.");
101+
else if (rows > 6 || rows < 1)
102+
throw new IllegalStateException("Patterns array has too many rows (" + rows + "). \nFix: Reduce/increase the amount of strings in the array of pattern()");
99103
Menu menu = Menu.create(title, rows, modifiers);
100104

101-
int size = ((rows * 9) + 9) - 10;
105+
int size = rows * 9;
102106
for (int i = 0; i < size; i++) {
103107
int row = i / 9;
104108
int col = i % 9;
@@ -121,10 +125,12 @@ public Menu createMenu(String title, EnumSet<Modifier> modifiers) {
121125
*/
122126
public PaginatedMenu createPaginated(String title, int pages) {
123127
if (patterns == null)
124-
throw new IllegalStateException("No patterns specified. Use the pattern() method before creating the menu.");
128+
throw new IllegalStateException("No patterns specified. \nFix: use the pattern() method before creating the menu.");
129+
else if (rows > 6 || rows < 1)
130+
throw new IllegalStateException("Patterns array has too many rows (" + rows + "). \nFix: Reduce/increase the amount of strings in the array of pattern()");
125131
PaginatedMenu menu = PaginatedMenu.create(title, rows, pages);
126132

127-
int size = ((rows * 9) + 9) - 10;
133+
int size = rows * 9;
128134
for (int i = 0; i < size; i++) {
129135
int row = i / 9;
130136
int col = i % 9;
@@ -147,10 +153,12 @@ public PaginatedMenu createPaginated(String title, int pages) {
147153
*/
148154
public PaginatedMenu createPaginated(String title, int pages, EnumSet<Modifier> modifiers) {
149155
if (patterns == null)
150-
throw new IllegalStateException("No patterns specified. Use the pattern() method before creating the menu.");
156+
throw new IllegalStateException("No patterns specified. \nFix: use the pattern() method before creating the menu.");
157+
else if (rows > 6 || rows < 1)
158+
throw new IllegalStateException("Patterns array has too many rows (" + rows + "). \nFix: Reduce/increase the amount of strings in the array of pattern()");
151159
PaginatedMenu menu = PaginatedMenu.create(title, rows, pages, modifiers);
152160

153-
int size = ((rows * 9) + 9) - 10;
161+
int size = rows * 9;
154162
for (int i = 0; i < size; i++) {
155163
int row = i / 9;
156164
int col = i % 9;
@@ -166,16 +174,17 @@ public PaginatedMenu createPaginated(String title, int pages, EnumSet<Modifier>
166174

167175
/**
168176
* Creates a paginated menu with the given title and populates it with items.
169-
*
170177
* @param title the title of the paginated menu
171178
* @return the created paginated menu
172179
*/
173180
public PaginatedMenu createPaginated(String title) {
174181
if (patterns == null)
175-
throw new IllegalStateException("No patterns specified. Use the pattern() method before creating the menu.");
182+
throw new IllegalStateException("No patterns specified. \nFix: use the pattern() method before creating the menu.");
183+
else if (rows > 6 || rows < 1)
184+
throw new IllegalStateException("Patterns array has too many rows (" + rows + "). \nFix: Reduce/increase the amount of strings in the array of pattern()");
176185
PaginatedMenu menu = PaginatedMenu.create(title, rows, 3);
177186

178-
int size = ((rows * 9) + 9) - 10;
187+
int size = rows * 9;
179188
for (int i = 0; i < size; i++) {
180189
int row = i / 9;
181190
int col = i % 9;

0 commit comments

Comments
 (0)