Skip to content

Commit da77756

Browse files
Documentation, reformatting
1 parent 1c7d342 commit da77756

File tree

1 file changed

+64
-13
lines changed

1 file changed

+64
-13
lines changed

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

Lines changed: 64 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,44 +12,80 @@
1212

1313
@SuppressWarnings("unused")
1414
public abstract class BaseBuilder<G, B extends BaseBuilder<G, B>> {
15-
protected String title;
16-
protected int rows;
15+
@NotNull
16+
protected String title = "";
17+
18+
@NotNull
1719
protected MenuType type = MenuType.CHEST;
18-
protected final EnumSet<Modifier> modifiers;
19-
protected Consumer<G> menuConsumer;
2020

21-
BaseBuilder() {
22-
this.title = "";
23-
this.rows = 1;
24-
this.modifiers = EnumSet.noneOf(Modifier.class);
25-
}
21+
@NotNull
22+
protected final EnumSet<Modifier> modifiers = EnumSet.noneOf(Modifier.class);
23+
24+
@NotNull
25+
protected Consumer<G> menuConsumer = (event -> {});
26+
27+
protected int rows = 1;
2628

29+
/**
30+
* Sets the title of the menu.
31+
*
32+
* @param title the title to be set
33+
* @return the builder for chaining
34+
*/
2735
public B title(@NonNull String title) {
28-
this.title = ChatColor.translateAlternateColorCodes('&', title);
36+
this.title = title;
2937
return (B) this;
3038
}
3139

40+
/**
41+
* Sets the amount of rows of the menu.
42+
*
43+
* @param rows the amount of rows to be set
44+
* @return the builder for chaining
45+
*/
3246
public B rows(int rows) {
3347
checkRows(rows);
3448
this.rows = rows;
3549
return (B) this;
3650
}
3751

52+
/**
53+
* Sets the type of the menu.
54+
* @param type the type, ex. {@link MenuType#HOPPER}, {@link MenuType#FURNACE}, etc.
55+
* @apiNote By default, it is {@link MenuType#CHEST}.
56+
* @return the builder for chaining
57+
*/
3858
public B type(MenuType type) {
3959
this.type = type;
4060
return (B) this;
4161
}
4262

63+
/**
64+
* Adds a modifier to the list of modifiers.
65+
*
66+
* @param modifier the modifier to be added
67+
* @return the builder for chaining
68+
*/
4369
public B addModifier(@NonNull Modifier modifier) {
4470
modifiers.add(modifier);
4571
return (B) this;
4672
}
4773

74+
/**
75+
* Remove a modifier from the list of modifiers.
76+
*
77+
* @param modifier the modifier to be removed
78+
* @return the builder for chaining
79+
*/
4880
public B removeModifier(@NonNull Modifier modifier) {
4981
modifiers.remove(modifier);
5082
return (B) this;
5183
}
5284

85+
/**
86+
* Add all the modifiers of {@link Modifier} to the list of modifiers.
87+
* @return the builder for chaining
88+
*/
5389
public B addAllModifiers() {
5490
modifiers.addAll(Modifier.ALL);
5591
return (B) this;
@@ -59,14 +95,29 @@ public B addAllModifiers() {
5995
return menuConsumer;
6096
}
6197

98+
/**
99+
* Sets the menu consumer for this function.
100+
* @apiNote This consumer will be called when the menu is created via {@link #create()}.
101+
* @param menuConsumer the consumer to set
102+
*/
62103
public void setMenuConsumer(@NonNull Consumer<G> menuConsumer) {
63104
this.menuConsumer = menuConsumer;
64105
}
65106

107+
/**
108+
* Creates and returns an instance of G.
109+
* <p>
110+
* It can be a Menu, a PaginatedMenu, etc. (depending on the builder)
111+
*
112+
* @return an instance of G
113+
*/
66114
public abstract G create();
67115

68-
protected void checkRows(int rows) {
69-
if (rows <= 0) throw new IllegalArgumentException("Rows must be greater than 0");
70-
if (rows > 6) throw new IllegalArgumentException("Rows must be equal to 6 or less");
116+
protected static void checkRows(int rows) {
117+
if (rows <= 0 || rows > 6) throw new IllegalArgumentException(
118+
"Rows must be more than 1 or 6 and less" +
119+
"\nRows: " + rows +
120+
"\nFix: Rows must be 1-6"
121+
);
71122
}
72123
}

0 commit comments

Comments
 (0)