36
36
import org .bukkit .Bukkit ;
37
37
import org .bukkit .Material ;
38
38
import org .bukkit .inventory .Inventory ;
39
+ import org .bukkit .inventory .ItemStack ;
39
40
import org .bukkit .plugin .java .JavaPlugin ;
40
41
import org .jetbrains .annotations .NotNull ;
41
42
42
- public class GUI {
43
+ import java . util . List ;
43
44
45
+ public final class GUI {
46
+
47
+ private static final String INCREASE_DECREASE_LORE = "\n §7Left click to increase\n §7Right click to decrease" ;
48
+ private static final ItemStack WHITE_DECORATION = Items .create (Material .WHITE_STAINED_GLASS_PANE , 1 , "§7" , "" );
49
+ private static final ItemStack LIME_DECORATION = Items .create (Material .LIME_STAINED_GLASS_PANE , 1 , "§7" , "" );
50
+ private static final ItemStack YELLOW_DECORATION = Items .create (Material .YELLOW_STAINED_GLASS_PANE , 1 , "§7" , "" );
51
+ private static final ItemStack RED_DECORATION = Items .create (Material .RED_STAINED_GLASS_PANE , 1 , "§7" , "" );
52
+ private static final ItemStack ORANGE_DECORATION = Items .create (Material .ORANGE_STAINED_GLASS_PANE , 1 , "§7" , "" );
53
+ private static final ItemStack EMPTY_SLOT = Items .create (Material .BARRIER , 1 , "§cEmpty Slot" , "\n §7Click with a block to set" );
44
54
private static final BetterGoPaint plugin = JavaPlugin .getPlugin (BetterGoPaint .class );
45
55
56
+ private GUI () {
57
+ throw new UnsupportedOperationException ("This class cannot be instantiated" );
58
+ }
59
+
46
60
public static @ NotNull Inventory create (PlayerBrush pb ) {
47
61
Inventory inv = Bukkit .createInventory (null , 54 , Component .text ("goPaint Menu" , NamedTextColor .DARK_BLUE ));
48
62
update (inv , pb );
@@ -64,7 +78,7 @@ public class GUI {
64
78
65
79
private static void formatDefault (@ NotNull Inventory inventory ) {
66
80
for (int slot = 0 ; slot < inventory .getSize (); slot ++) {
67
- inventory .setItem (slot , Items . create ( Material . GRAY_STAINED_GLASS_PANE , 1 , "§7" , "" ) );
81
+ inventory .setItem (slot , LIME_DECORATION );
68
82
}
69
83
}
70
84
@@ -73,145 +87,129 @@ public static void update(@NotNull Inventory inventory, @NotNull PlayerBrush pla
73
87
74
88
// FILLER
75
89
formatDefault (inventory );
76
-
77
90
// goPaint toggle
78
- if (playerBrush .enabled ()) {
79
- inventory .setItem (1 , Items .create (Material .LIME_STAINED_GLASS_PANE , 1 , "§7" , "" ));
80
- inventory .setItem (10 , Items .create (Settings .settings ().generic .DEFAULT_BRUSH , 1 , "§6goPaint Brush" ,
81
- "§a§lEnabled\n \n §7Left click with item to export\n §7Right click to toggle"
82
- ));
83
- inventory .setItem (19 , Items .create (Material .LIME_STAINED_GLASS_PANE , 1 , "§7" , "" ));
84
- } else {
85
- inventory .setItem (1 , Items .create (Material .RED_STAINED_GLASS_PANE , 1 , "§7" , "" ));
86
- inventory .setItem (10 , Items .create (Settings .settings ().generic .DEFAULT_BRUSH , 1 , "§6goPaint Brush" ,
87
- "§c§lDisabled\n \n §7Left click with item to export\n §7Right click to toggle"
88
- ));
89
- inventory .setItem (19 , Items .create (Material .RED_STAINED_GLASS_PANE , 1 , "§7" , "" ));
90
- }
91
-
91
+ setPaintToggle (inventory , playerBrush );
92
92
// Brushes + Chance
93
- inventory .setItem (2 , Items .create (Material .ORANGE_STAINED_GLASS_PANE , 1 , "§7" , "" ));
94
-
93
+ inventory .setItem (2 , ORANGE_DECORATION );
95
94
96
95
String clicks = "\n §7Shift click to select\n §7Click to cycle brush\n \n " ;
97
96
98
97
inventory .setItem (11 , Items .createHead (brush .getHead (), 1 , "§6Selected Brush type" ,
99
98
clicks + plugin .getBrushManager ().getBrushLore (brush )
100
99
));
101
- inventory .setItem (20 , Items . create ( Material . ORANGE_STAINED_GLASS_PANE , 1 , "§7" , "" ) );
100
+ inventory .setItem (20 , ORANGE_DECORATION );
102
101
103
102
// chance
104
103
if (brush instanceof SprayBrush ) {
105
- inventory .setItem (3 , Items . create ( Material . WHITE_STAINED_GLASS_PANE , 1 , "§7" , "" ) );
104
+ inventory .setItem (3 , WHITE_DECORATION );
106
105
inventory .setItem (12 , Items .create (Material .GOLD_NUGGET , 1 ,
107
106
"§6Place chance: §e" + playerBrush .chance () + "%" ,
108
- " \n §7Left click to increase \n §7Right click to decrease"
107
+ INCREASE_DECREASE_LORE
109
108
));
110
- inventory .setItem (21 , Items . create ( Material . WHITE_STAINED_GLASS_PANE , 1 , "§7" , "" ) );
109
+ inventory .setItem (21 , WHITE_DECORATION );
111
110
}
112
111
113
112
// axis
114
113
if (brush instanceof DiscBrush ) {
115
- inventory .setItem (3 , Items . create ( Material . WHITE_STAINED_GLASS_PANE , 1 , "§7" , "" ) );
114
+ inventory .setItem (3 , WHITE_DECORATION );
116
115
inventory .setItem (12 , Items .create (Material .COMPASS , 1 ,
117
116
"§6Axis: §e" + playerBrush .axis (), "\n §7Click to change"
118
117
));
119
- inventory .setItem (21 , Items . create ( Material . WHITE_STAINED_GLASS_PANE , 1 , "§7" , "" ) );
118
+ inventory .setItem (21 , WHITE_DECORATION );
120
119
}
121
120
122
121
123
122
// thickness
124
123
if (brush instanceof OverlayBrush || brush instanceof UnderlayBrush ) {
125
- inventory .setItem (3 , Items . create ( Material . WHITE_STAINED_GLASS_PANE , 1 , "§7" , "" ) );
124
+ inventory .setItem (3 , WHITE_DECORATION );
126
125
inventory .setItem (12 , Items .create (Material .BOOK , 1 ,
127
126
"§6Layer Thickness: §e" + playerBrush .thickness (),
128
- " \n §7Left click to increase \n §7Right click to decrease"
127
+ INCREASE_DECREASE_LORE
129
128
));
130
- inventory .setItem (21 , Items . create ( Material . WHITE_STAINED_GLASS_PANE , 1 , "§7" , "" ) );
129
+ inventory .setItem (21 , WHITE_DECORATION );
131
130
}
132
131
133
132
// angle settings
134
133
if (brush instanceof AngleBrush ) {
135
- inventory .setItem (3 , Items . create ( Material . WHITE_STAINED_GLASS_PANE , 1 , "§7" , "" ) );
134
+ inventory .setItem (3 , WHITE_DECORATION );
136
135
inventory .setItem (12 , Items .create (Material .DAYLIGHT_DETECTOR , 1 ,
137
136
"§6Angle Check Distance: §e" + playerBrush .angleDistance (),
138
- " \n §7Left click to increase \n §7Right click to decrease"
137
+ INCREASE_DECREASE_LORE
139
138
));
140
- inventory .setItem (21 , Items .create (Material .WHITE_STAINED_GLASS_PANE , 1 , "§7" , "" ));
141
-
142
- inventory .setItem (4 , Items .create (Material .WHITE_STAINED_GLASS_PANE , 1 , "§7" , "" ));
139
+ inventory .setItem (21 , WHITE_DECORATION );
140
+ inventory .setItem (4 , WHITE_DECORATION );
143
141
inventory .setItem (13 , Items .create (Material .BLAZE_ROD , 1 ,
144
142
"§6Maximum Angle: §e" + playerBrush .angleHeightDifference () + "°" ,
145
143
"\n §7Left click to increase\n §7Right click to decrease\n §7Shift click to change by 15"
146
144
));
147
- inventory .setItem (22 , Items . create ( Material . WHITE_STAINED_GLASS_PANE , 1 , "§7" , "" ) );
145
+ inventory .setItem (22 , WHITE_DECORATION );
148
146
}
149
147
150
148
// fracture settings
151
149
if (brush instanceof FractureBrush ) {
152
- inventory .setItem (3 , Items . create ( Material . WHITE_STAINED_GLASS_PANE , 1 , "§7" , "" ) );
150
+ inventory .setItem (3 , WHITE_DECORATION );
153
151
inventory .setItem (12 , Items .create (Material .DAYLIGHT_DETECTOR , 1 ,
154
152
"§6Fracture Check Distance: §e" + playerBrush .fractureDistance (),
155
- " \n §7Left click to increase \n §7Right click to decrease"
153
+ INCREASE_DECREASE_LORE
156
154
));
157
- inventory .setItem (21 , Items . create ( Material . WHITE_STAINED_GLASS_PANE , 1 , "§7" , "" ) );
155
+ inventory .setItem (21 , WHITE_DECORATION );
158
156
}
159
157
160
158
// angle settings
161
159
if (brush instanceof GradientBrush ) {
162
- inventory .setItem (4 , Items . create ( Material . WHITE_STAINED_GLASS_PANE , 1 , "§7" , "" ) );
160
+ inventory .setItem (4 , WHITE_DECORATION );
163
161
inventory .setItem (13 , Items .create (Material .MAGMA_CREAM , 1 ,
164
162
"§6Mixing Strength: §e" + playerBrush .mixingStrength () + "%" ,
165
- " \n §7Left click to increase \n §7Right click to decrease"
163
+ INCREASE_DECREASE_LORE
166
164
));
167
- inventory .setItem (22 , Items . create ( Material . WHITE_STAINED_GLASS_PANE , 1 , "§7" , "" ) );
165
+ inventory .setItem (22 , WHITE_DECORATION );
168
166
}
169
167
170
168
if (brush instanceof SplatterBrush || brush instanceof PaintBrush || brush instanceof GradientBrush ) {
171
- inventory .setItem (3 , Items . create ( Material . WHITE_STAINED_GLASS_PANE , 1 , "§7" , "" ) );
169
+ inventory .setItem (3 , WHITE_DECORATION );
172
170
inventory .setItem (12 , Items .create (Material .BLAZE_POWDER , 1 ,
173
171
"§6Falloff Strength: §e" + playerBrush .falloffStrength () + "%" ,
174
- " \n §7Left click to increase \n §7Right click to decrease"
172
+ INCREASE_DECREASE_LORE
175
173
));
176
- inventory .setItem (21 , Items . create ( Material . WHITE_STAINED_GLASS_PANE , 1 , "§7" , "" ) );
174
+ inventory .setItem (21 , WHITE_DECORATION );
177
175
}
178
176
179
177
180
178
// Size
181
- inventory .setItem (5 , Items . create ( Material . WHITE_STAINED_GLASS_PANE , 1 , "§7" , "" ) );
179
+ inventory .setItem (5 , WHITE_DECORATION );
182
180
inventory .setItem (14 , Items .create (Material .BROWN_MUSHROOM , 1 ,
183
181
"§6Brush Size: §e" + playerBrush .size (),
184
182
"\n §7Left click to increase\n §7Right click to decrease\n §7Shift click to change by 10"
185
183
));
186
- inventory .setItem (23 , Items . create ( Material . WHITE_STAINED_GLASS_PANE , 1 , "§7" , "" ) );
184
+ inventory .setItem (23 , WHITE_DECORATION );
187
185
188
186
// Mask toggle
189
- if (playerBrush .maskEnabled ()) {
190
- inventory .setItem (6 , Items .create (Material .LIME_STAINED_GLASS_PANE , 1 , "§7" , "" ));
191
- inventory .setItem (15 , Items .create (Material .JACK_O_LANTERN , 1 ,
192
- "§6Mask" ,
193
- "§a§lEnabled\n \n §7Click to toggle"
194
- ));
195
- inventory .setItem (24 , Items .create (Material .LIME_STAINED_GLASS_PANE , 1 , "§7" , "" ));
196
- } else {
197
- inventory .setItem (6 , Items .create (Material .RED_STAINED_GLASS_PANE , 1 , "§7" , "" ));
198
- inventory .setItem (15 , Items .create (Material .CARVED_PUMPKIN , 1 , "§6Mask" , "§c§lDisabled\n \n §7Click to toggle" ));
199
- inventory .setItem (24 , Items .create (Material .RED_STAINED_GLASS_PANE , 1 , "§7" , "" ));
200
- }
187
+ setMaskItems (inventory , playerBrush );
201
188
202
189
// Surface Mode toggle
203
190
addSurfaceModeSwitch (inventory , playerBrush );
204
191
205
192
// Place Block
206
193
for (int x = 37 ; x <= 41 ; x ++) {
207
- inventory .setItem (x , Items . create ( Material . YELLOW_STAINED_GLASS_PANE , 1 , "§7" , "" ) );
194
+ inventory .setItem (x , YELLOW_DECORATION );
208
195
}
209
196
for (int x = 46 ; x <= 50 ; x ++) {
210
- inventory .setItem (x , Items . create ( Material . BARRIER , 1 , "§cEmpty Slot" , " \n §7Click with a block to set" ) );
197
+ inventory .setItem (x , EMPTY_SLOT );
211
198
}
199
+
200
+ // Block Change
201
+ setBlockChangeItems (inventory , playerBrush );
202
+
203
+ // Mask Block
204
+ inventory .setItem (43 , YELLOW_DECORATION );
205
+ inventory .setItem (52 , Items .create (playerBrush .mask (), 1 , "§6Current Mask" , "\n §7Left click with a block to change" ));
206
+ }
207
+
208
+ private static void setBlockChangeItems (@ NotNull Inventory inventory , @ NotNull PlayerBrush playerBrush ) {
209
+ final List <Material > blocks = playerBrush .blocks ();
210
+ if (blocks .isEmpty ()) return ;
212
211
int x = 46 ;
213
- int size = playerBrush .blocks ().size ();
214
- int chance = size == 0 ? 0 : 100 / size ;
212
+ int chance = blocks .isEmpty () ? 0 : 100 / blocks .size ();
215
213
for (Material material : playerBrush .blocks ()) {
216
214
if (chance > 64 ) {
217
215
inventory .setItem (x , Items .create (material , 1 ,
@@ -226,30 +224,70 @@ public static void update(@NotNull Inventory inventory, @NotNull PlayerBrush pla
226
224
}
227
225
x ++;
228
226
}
227
+ }
229
228
230
- // Mask Block
231
- inventory .setItem (43 , Items .create (Material .YELLOW_STAINED_GLASS_PANE , 1 , "§7" , "" ));
232
- inventory .setItem (52 , Items .create (playerBrush .mask (), 1 , "§6Current Mask" , "\n §7Left click with a block to change" ));
229
+ /**
230
+ * Set the relevant {@link ItemStack}'s into an {@link Inventory} to represent the goPaint toggle
231
+ *
232
+ * @param inventory the inventory to set the items in
233
+ * @param playerBrush the {@link PlayerBrush} to get the goPaint status from
234
+ */
235
+ private static void setPaintToggle (@ NotNull Inventory inventory , @ NotNull PlayerBrush playerBrush ) {
236
+ final String lore = "§a§lEnabled\n \n §7Left click with item to export\n §7Right click to toggle" ;
237
+ final String displayName = "§6goPaint Brush" ;
238
+ final boolean hasBrushEnabled = playerBrush .enabled ();
239
+ inventory .setItem (1 , hasBrushEnabled ? LIME_DECORATION : RED_DECORATION );
240
+ inventory .setItem (10 , Items .create (Settings .settings ().generic .DEFAULT_BRUSH , 1 , displayName , lore ));
241
+ inventory .setItem (19 , hasBrushEnabled ? LIME_DECORATION : RED_DECORATION );
242
+ }
243
+
244
+ /**
245
+ * Set the relevant {@link ItemStack}'s into an {@link Inventory} to represent the mask toggle
246
+ *
247
+ * @param inventory the inventory to set the items in
248
+ * @param playerBrush the {@link PlayerBrush} to get the mask status from
249
+ */
250
+ private static void setMaskItems (@ NotNull Inventory inventory , @ NotNull PlayerBrush playerBrush ) {
251
+ if (playerBrush .maskEnabled ()) {
252
+ inventory .setItem (6 , LIME_DECORATION );
253
+ inventory .setItem (15 , Items .create (Material .JACK_O_LANTERN , 1 ,
254
+ "§6Mask" ,
255
+ "§a§lEnabled\n \n §7Click to toggle"
256
+ ));
257
+ inventory .setItem (24 , LIME_DECORATION );
258
+ return ;
259
+ }
260
+ final ItemStack mask = Items .create (Material .CARVED_PUMPKIN , 1 , "§6Mask" , "§c§lDisabled\n \n §7Click to toggle" );
261
+ inventory .setItem (6 , RED_DECORATION );
262
+ inventory .setItem (15 , mask );
263
+ inventory .setItem (24 , RED_DECORATION );
233
264
}
234
265
235
- private static void addSurfaceModeSwitch (Inventory inv , PlayerBrush playerBrush ) {
236
- Material pane = switch (playerBrush .surfaceMode ()) {
237
- case DIRECT -> Material .LIME_STAINED_GLASS_PANE ;
238
- case DISABLED -> Material .RED_STAINED_GLASS_PANE ;
239
- case RELATIVE -> Material .ORANGE_STAINED_GLASS_PANE ;
266
+ /**
267
+ * Add the surface mode switch to the {@link Inventory}.
268
+ *
269
+ * @param inv the inventory to add the switch to
270
+ * @param playerBrush the {@link PlayerBrush} to get the surface mode from
271
+ */
272
+ private static void addSurfaceModeSwitch (@ NotNull Inventory inv , @ NotNull PlayerBrush playerBrush ) {
273
+ // Reuses the constant for the pane to reduce object creation
274
+ ItemStack pane = switch (playerBrush .surfaceMode ()) {
275
+ case DIRECT -> LIME_DECORATION ;
276
+ case DISABLED -> RED_DECORATION ;
277
+ case RELATIVE -> ORANGE_DECORATION ;
240
278
};
241
279
String color = switch (playerBrush .surfaceMode ()) {
242
280
case DIRECT -> "§a" ;
243
281
case DISABLED -> "§c" ;
244
282
case RELATIVE -> "§6" ;
245
283
};
246
284
247
- inv .setItem (7 , Items . create ( pane , 1 , "§7" , "" ) );
285
+ inv .setItem (7 , pane );
248
286
inv .setItem (16 , Items .create (Material .LIGHT_WEIGHTED_PRESSURE_PLATE , 1 ,
249
287
"§6Surface Mode" ,
250
288
color + "§l" + playerBrush .surfaceMode ().getName () + "\n \n §7Click to toggle"
251
289
));
252
- inv .setItem (25 , Items . create ( pane , 1 , "§7" , "" ) );
290
+ inv .setItem (25 , pane );
253
291
}
254
292
255
293
}
0 commit comments