3838
3939public class ParcelSendingGui implements GuiView {
4040
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 ;
4152 private final Plugin plugin ;
4253 private final BukkitScheduler scheduler ;
4354 private final PluginConfiguration config ;
@@ -104,7 +115,7 @@ public void show(Player player) {
104115 .setHandler ((p , result ) -> {
105116 String name = result .getLineWithoutColor (1 );
106117
107- if (name .isEmpty () || name . isBlank ()) {
118+ if (name .isBlank ()) {
108119 this .announcer .sendMessage (player , settings .messages .parcelNameCannotBeEmpty );
109120 return Collections .emptyList ();
110121 }
@@ -120,7 +131,7 @@ public void show(Player player) {
120131 lore .add (this .config .guiSettings .parcelNameSetLine .replace ("{NAME}" , this .state .getParcelName () == null
121132 ? "None" : this .state .getParcelName ()));
122133
123- this .gui .updateItem (21 , nameItem
134+ this .gui .updateItem (NAME_ITEM_SLOT , nameItem
124135 .setLore (lore )
125136 .toItemStack ());
126137 return List .of (SignGUIAction .runSync ((JavaPlugin ) this .plugin , () -> this .gui .open (player )));
@@ -154,7 +165,7 @@ public void show(Player player) {
154165
155166 lore .add (this .config .guiSettings .parcelDescriptionSetLine .replace ("{DESCRIPTION}" , description ));
156167
157- this .gui .updateItem (22 , descriptionItem
168+ this .gui .updateItem (DESCRIPTION_ITEM_SLOT , descriptionItem
158169 .setLore (lore )
159170 .toItemStack ());
160171 return List .of (SignGUIAction .runSync ((JavaPlugin ) this .plugin , () -> this .gui .open (player )));
@@ -248,12 +259,12 @@ public void show(Player player) {
248259 this .gui .setItem (slot , cornerItem );
249260 }
250261
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 (
257268 this .plugin ,
258269 this .scheduler ,
259270 this .config ,
@@ -264,7 +275,7 @@ public void show(Player player) {
264275 this .state
265276 ).show (player )));
266277
267- this .gui .setItem (30 , guiSettings .parcelDestinationLockerItem .toGuiItem (event -> new DestinationSelectionGui (
278+ this .gui .setItem (DESTINATION_ITEM_SLOT , guiSettings .parcelDestinationLockerItem .toGuiItem (event -> new DestinationSelectionGui (
268279 this .plugin ,
269280 this .scheduler ,
270281 this .config ,
@@ -274,13 +285,23 @@ public void show(Player player) {
274285 this .state
275286 ).show (player )));
276287
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 );
281292
282293 this .setSelected (this .gui , this .state .getSize () == null ? ParcelSize .SMALL : this .state .getSize ());
283294
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+
284305 this .gui .open (player );
285306 }
286307
@@ -293,10 +314,10 @@ private void setSelected(Gui gui, ParcelSize size) {
293314 ConfigItem largeButton = size == ParcelSize .LARGE ? settings .selectedLargeParcelSizeItem : settings .largeParcelSizeItem ;
294315 ConfigItem priorityButton = this .state .isPriority () ? settings .selectedPriorityItem : settings .priorityItem ;
295316
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 ());
300321 }
301322
302323 private void setSelected (Gui gui , boolean priority ) {
@@ -305,31 +326,51 @@ private void setSelected(Gui gui, boolean priority) {
305326
306327 ConfigItem priorityButton = priority ? settings .selectedPriorityItem : settings .priorityItem ;
307328
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 ));
309350 }
310351
311352 public void updateReceiverItem (Player player , String receiverName ) {
312353 this .announcer .sendMessage (player , this .config .messages .parcelReceiverSet );
313354
314355 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 ());
316357 return ;
317358 }
318359
319360 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 ));
321362 }
322363
323364 public void updateDestinationItem (Player player , String destinationLockerDesc ) {
324365 this .announcer .sendMessage (player , this .config .messages .parcelDestinationSet );
325366
326367 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 ());
328369 return ;
329370 }
330371
331372 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 ));
333374 }
334375
335376 private @ NotNull ItemStack createActiveItem (ConfigItem item , String appendLore ) {
0 commit comments