12
12
13
13
@ SuppressWarnings ("unused" )
14
14
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
17
19
protected MenuType type = MenuType .CHEST ;
18
- protected final EnumSet <Modifier > modifiers ;
19
- protected Consumer <G > menuConsumer ;
20
20
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 ;
26
28
29
+ /**
30
+ * Sets the title of the menu.
31
+ *
32
+ * @param title the title to be set
33
+ * @return the builder for chaining
34
+ */
27
35
public B title (@ NonNull String title ) {
28
- this .title = ChatColor . translateAlternateColorCodes ( '&' , title ) ;
36
+ this .title = title ;
29
37
return (B ) this ;
30
38
}
31
39
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
+ */
32
46
public B rows (int rows ) {
33
47
checkRows (rows );
34
48
this .rows = rows ;
35
49
return (B ) this ;
36
50
}
37
51
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
+ */
38
58
public B type (MenuType type ) {
39
59
this .type = type ;
40
60
return (B ) this ;
41
61
}
42
62
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
+ */
43
69
public B addModifier (@ NonNull Modifier modifier ) {
44
70
modifiers .add (modifier );
45
71
return (B ) this ;
46
72
}
47
73
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
+ */
48
80
public B removeModifier (@ NonNull Modifier modifier ) {
49
81
modifiers .remove (modifier );
50
82
return (B ) this ;
51
83
}
52
84
85
+ /**
86
+ * Add all the modifiers of {@link Modifier} to the list of modifiers.
87
+ * @return the builder for chaining
88
+ */
53
89
public B addAllModifiers () {
54
90
modifiers .addAll (Modifier .ALL );
55
91
return (B ) this ;
@@ -59,14 +95,29 @@ public B addAllModifiers() {
59
95
return menuConsumer ;
60
96
}
61
97
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
+ */
62
103
public void setMenuConsumer (@ NonNull Consumer <G > menuConsumer ) {
63
104
this .menuConsumer = menuConsumer ;
64
105
}
65
106
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
+ */
66
114
public abstract G create ();
67
115
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
+ "\n Rows: " + rows +
120
+ "\n Fix: Rows must be 1-6"
121
+ );
71
122
}
72
123
}
0 commit comments