38
38
39
39
public class ParcelSendingGui implements GuiView {
40
40
41
+ private static final int RECEIVER_ITEM_SLOT = 23 ;
42
+ private static final int SMALL_BUTTON_SLOT = 12 ;
43
+ private static final int MEDIUM_BUTTON_SLOT = 13 ;
44
+ private static final int LARGE_BUTTON_SLOT = 14 ;
45
+ private static final int NAME_ITEM_SLOT = 21 ;
46
+ private static final int DESCRIPTION_ITEM_SLOT = 22 ;
47
+ private static final int DESTINATION_ITEM_SLOT = 30 ;
48
+ private static final int STORAGE_ITEM_SLOT = 37 ;
49
+ private static final int PRIORITY_BUTTON_SLOT = 42 ;
50
+ private static final int SUBMIT_ITEM_SLOT = 43 ;
51
+ private static final int CLOSE_ITEM_SLOT = 49 ;
41
52
private final Plugin plugin ;
42
53
private final BukkitScheduler scheduler ;
43
54
private final PluginConfiguration config ;
@@ -104,7 +115,7 @@ public void show(Player player) {
104
115
.setHandler ((p , result ) -> {
105
116
String name = result .getLineWithoutColor (1 );
106
117
107
- if (name .isEmpty () || name . isBlank ()) {
118
+ if (name .isBlank ()) {
108
119
this .announcer .sendMessage (player , settings .messages .parcelNameCannotBeEmpty );
109
120
return Collections .emptyList ();
110
121
}
@@ -120,7 +131,7 @@ public void show(Player player) {
120
131
lore .add (this .config .guiSettings .parcelNameSetLine .replace ("{NAME}" , this .state .getParcelName () == null
121
132
? "None" : this .state .getParcelName ()));
122
133
123
- this .gui .updateItem (21 , nameItem
134
+ this .gui .updateItem (NAME_ITEM_SLOT , nameItem
124
135
.setLore (lore )
125
136
.toItemStack ());
126
137
return List .of (SignGUIAction .runSync ((JavaPlugin ) this .plugin , () -> this .gui .open (player )));
@@ -154,7 +165,7 @@ public void show(Player player) {
154
165
155
166
lore .add (this .config .guiSettings .parcelDescriptionSetLine .replace ("{DESCRIPTION}" , description ));
156
167
157
- this .gui .updateItem (22 , descriptionItem
168
+ this .gui .updateItem (DESCRIPTION_ITEM_SLOT , descriptionItem
158
169
.setLore (lore )
159
170
.toItemStack ());
160
171
return List .of (SignGUIAction .runSync ((JavaPlugin ) this .plugin , () -> this .gui .open (player )));
@@ -248,12 +259,12 @@ public void show(Player player) {
248
259
this .gui .setItem (slot , cornerItem );
249
260
}
250
261
251
- this .gui .setItem (12 , smallButton .toGuiItem (event -> this .setSelected (this .gui , ParcelSize .SMALL )));
252
- this .gui .setItem (13 , mediumButton .toGuiItem (event -> this .setSelected (this .gui , ParcelSize .MEDIUM )));
253
- this .gui .setItem (14 , largeButton .toGuiItem (event -> this .setSelected (this .gui , ParcelSize .LARGE )));
254
- this .gui .setItem (21 , nameGuiItem );
255
- this .gui .setItem (22 , descriptionGuiItem );
256
- this .gui .setItem (23 , guiSettings .parcelReceiverItem .toGuiItem (event -> new ReceiverSelectionGui (
262
+ this .gui .setItem (SMALL_BUTTON_SLOT , smallButton .toGuiItem (event -> this .setSelected (this .gui , ParcelSize .SMALL )));
263
+ this .gui .setItem (MEDIUM_BUTTON_SLOT , mediumButton .toGuiItem (event -> this .setSelected (this .gui , ParcelSize .MEDIUM )));
264
+ this .gui .setItem (LARGE_BUTTON_SLOT , largeButton .toGuiItem (event -> this .setSelected (this .gui , ParcelSize .LARGE )));
265
+ this .gui .setItem (NAME_ITEM_SLOT , nameGuiItem );
266
+ this .gui .setItem (DESCRIPTION_ITEM_SLOT , descriptionGuiItem );
267
+ this .gui .setItem (RECEIVER_ITEM_SLOT , guiSettings .parcelReceiverItem .toGuiItem (event -> new ReceiverSelectionGui (
257
268
this .plugin ,
258
269
this .scheduler ,
259
270
this .config ,
@@ -264,7 +275,7 @@ public void show(Player player) {
264
275
this .state
265
276
).show (player )));
266
277
267
- this .gui .setItem (30 , guiSettings .parcelDestinationLockerItem .toGuiItem (event -> new DestinationSelectionGui (
278
+ this .gui .setItem (DESTINATION_ITEM_SLOT , guiSettings .parcelDestinationLockerItem .toGuiItem (event -> new DestinationSelectionGui (
268
279
this .plugin ,
269
280
this .scheduler ,
270
281
this .config ,
@@ -274,13 +285,23 @@ public void show(Player player) {
274
285
this .state
275
286
).show (player )));
276
287
277
- this .gui .setItem (37 , storageItem );
278
- this .gui .setItem (43 , submitItem );
279
- this .gui .setItem (42 , priorityItem .toGuiItem (event -> this .setSelected (this .gui , !this .state .isPriority ())));
280
- this .gui .setItem (49 , closeItem );
288
+ this .gui .setItem (STORAGE_ITEM_SLOT , storageItem );
289
+ this .gui .setItem (SUBMIT_ITEM_SLOT , submitItem );
290
+ this .gui .setItem (PRIORITY_BUTTON_SLOT , priorityItem .toGuiItem (event -> this .setSelected (this .gui , !this .state .isPriority ())));
291
+ this .gui .setItem (CLOSE_ITEM_SLOT , closeItem );
281
292
282
293
this .setSelected (this .gui , this .state .getSize () == null ? ParcelSize .SMALL : this .state .getSize ());
283
294
295
+ this .updateNameItem ();
296
+ this .updateDescriptionItem ();
297
+ this .userRepository .getUser (this .state .getReceiver ()).thenAccept (userOptional -> {
298
+ userOptional .ifPresent (user -> this .updateReceiverItem (player , user .name ()));
299
+ });
300
+ this .lockerRepository .findByUUID (this .state .getDestinationLocker ()).thenAccept (lockerOptional -> {
301
+ lockerOptional .ifPresent (locker -> this .updateDestinationItem (player , locker .description ()));
302
+ });
303
+
304
+
284
305
this .gui .open (player );
285
306
}
286
307
@@ -293,10 +314,10 @@ private void setSelected(Gui gui, ParcelSize size) {
293
314
ConfigItem largeButton = size == ParcelSize .LARGE ? settings .selectedLargeParcelSizeItem : settings .largeParcelSizeItem ;
294
315
ConfigItem priorityButton = this .state .isPriority () ? settings .selectedPriorityItem : settings .priorityItem ;
295
316
296
- gui .updateItem (12 , smallButton .toItemStack ());
297
- gui .updateItem (13 , mediumButton .toItemStack ());
298
- gui .updateItem (14 , largeButton .toItemStack ());
299
- gui .updateItem (42 , priorityButton .toItemStack ());
317
+ gui .updateItem (SMALL_BUTTON_SLOT , smallButton .toItemStack ());
318
+ gui .updateItem (MEDIUM_BUTTON_SLOT , mediumButton .toItemStack ());
319
+ gui .updateItem (LARGE_BUTTON_SLOT , largeButton .toItemStack ());
320
+ gui .updateItem (PRIORITY_BUTTON_SLOT , priorityButton .toItemStack ());
300
321
}
301
322
302
323
private void setSelected (Gui gui , boolean priority ) {
@@ -305,31 +326,51 @@ private void setSelected(Gui gui, boolean priority) {
305
326
306
327
ConfigItem priorityButton = priority ? settings .selectedPriorityItem : settings .priorityItem ;
307
328
308
- gui .updateItem (42 , priorityButton .toItemStack ());
329
+ gui .updateItem (PRIORITY_BUTTON_SLOT , priorityButton .toItemStack ());
330
+ }
331
+
332
+ public void updateNameItem () {
333
+ if (this .state .getParcelName () == null || this .state .getParcelName ().isEmpty ()) {
334
+ this .gui .updateItem (NAME_ITEM_SLOT , this .config .guiSettings .parcelNameItem .toItemStack ());
335
+ return ;
336
+ }
337
+
338
+ String line = this .config .guiSettings .parcelNameSetLine .replace ("{NAME}" , this .state .getParcelName ());
339
+ this .gui .updateItem (NAME_ITEM_SLOT , this .createActiveItem (this .config .guiSettings .parcelNameItem , line ));
340
+ }
341
+
342
+ public void updateDescriptionItem () {
343
+ if (this .state .getParcelDescription () == null || this .state .getParcelDescription ().isEmpty ()) {
344
+ this .gui .updateItem (DESCRIPTION_ITEM_SLOT , this .config .guiSettings .parcelDescriptionItem .toItemStack ());
345
+ return ;
346
+ }
347
+
348
+ String line = this .config .guiSettings .parcelDescriptionSetLine .replace ("{DESCRIPTION}" , this .state .getParcelDescription ());
349
+ this .gui .updateItem (DESCRIPTION_ITEM_SLOT , this .createActiveItem (this .config .guiSettings .parcelDescriptionItem , line ));
309
350
}
310
351
311
352
public void updateReceiverItem (Player player , String receiverName ) {
312
353
this .announcer .sendMessage (player , this .config .messages .parcelReceiverSet );
313
354
314
355
if (receiverName == null || receiverName .isEmpty ()) {
315
- this .gui .updateItem (23 , this .config .guiSettings .parcelReceiverItem .toItemStack ());
356
+ this .gui .updateItem (RECEIVER_ITEM_SLOT , this .config .guiSettings .parcelReceiverItem .toItemStack ());
316
357
return ;
317
358
}
318
359
319
360
String line = this .config .guiSettings .parcelReceiverGuiSetLine .replace ("{RECEIVER}" , receiverName );
320
- this .gui .updateItem (23 , this .createActiveItem (this .config .guiSettings .parcelReceiverItem , line ));
361
+ this .gui .updateItem (RECEIVER_ITEM_SLOT , this .createActiveItem (this .config .guiSettings .parcelReceiverItem , line ));
321
362
}
322
363
323
364
public void updateDestinationItem (Player player , String destinationLockerDesc ) {
324
365
this .announcer .sendMessage (player , this .config .messages .parcelDestinationSet );
325
366
326
367
if (destinationLockerDesc == null || destinationLockerDesc .isEmpty ()) {
327
- this .gui .updateItem (30 , this .config .guiSettings .parcelDestinationLockerItem .toItemStack ());
368
+ this .gui .updateItem (DESTINATION_ITEM_SLOT , this .config .guiSettings .parcelDestinationLockerItem .toItemStack ());
328
369
return ;
329
370
}
330
371
331
372
String line = this .config .guiSettings .parcelDestinationLockerSetLine .replace ("{DESCRIPTION}" , destinationLockerDesc );
332
- this .gui .updateItem (30 , this .createActiveItem (this .config .guiSettings .parcelDestinationLockerItem , line ));
373
+ this .gui .updateItem (DESTINATION_ITEM_SLOT , this .createActiveItem (this .config .guiSettings .parcelDestinationLockerItem , line ));
333
374
}
334
375
335
376
private @ NotNull ItemStack createActiveItem (ConfigItem item , String appendLore ) {
0 commit comments