@@ -143,6 +143,10 @@ public InventoryGui createPostUi(String playerName, List<PostalPackage> packages
143143 }
144144
145145 public InventoryGui createParcelPostUi () {
146+ return createParcelPostUi (null );
147+ }
148+
149+ public InventoryGui createParcelPostUi (@ javax .annotation .Nullable OfflinePlayer recipient ) {
146150 String [] rows = new String []{
147151 " " ,
148152 " ddddddd " ,
@@ -154,13 +158,14 @@ public InventoryGui createParcelPostUi() {
154158 // blank space = panes
155159 // b = back, p = post parcel, e = exit
156160 Inventory storageInv = this .plugin .getServer ().createInventory (null , 9 * 3 );
161+ UUID recipientUuid = recipient != null && recipient .hasPlayedBefore () ? recipient .getUniqueId () : null ;
157162 InventoryGui gui = createGui (
158163 this .messageContainer .messageFor ("menu.parcel.drop" ),
159164 rows ,
160165 elementPanes (' ' ),
161166 elementDrop ('d' , storageInv ),
162167 elementBack ('b' , player -> returnAndClearItems (player , storageInv )),
163- elementPost ('p' , storageInv )
168+ elementPost ('p' , storageInv , recipientUuid )
164169 );
165170 gui .setCloseAction (close -> handleInventoryClose (close , storageInv ));
166171 return gui ;
@@ -413,7 +418,7 @@ private GuiElement elementPrevious(char c) {
413418 LegacyComponentSerializer .legacySection ().serialize (displayName ));
414419 }
415420
416- private GuiElement elementPost (char c , Inventory storageInv ) {
421+ private GuiElement elementPost (char c , Inventory storageInv , @ javax . annotation . Nullable UUID recipientUuid ) {
417422 ItemStack itemStack = this .itemFactory .createSendPackageButton ();
418423 ItemMeta meta = itemStack .getItemMeta ();
419424 Component displayName = this .messageContainer .messageFor ("menu.main.post-parcel" )
@@ -422,7 +427,7 @@ private GuiElement elementPost(char c, Inventory storageInv) {
422427 itemStack .setItemMeta (meta );
423428 StaticGuiElement element = new StaticGuiElement (c , itemStack );
424429 element .setAction (action -> {
425- processPost (action , element , itemStack , storageInv );
430+ processPost (action , element , itemStack , storageInv , recipientUuid );
426431 return true ;
427432 });
428433 return element ;
@@ -432,9 +437,9 @@ private void processPost(
432437 GuiElement .Click action ,
433438 StaticGuiElement element ,
434439 ItemStack display ,
435- Inventory storageInv ) {
436- // Don't clear the storage inv, items will be added back
437- if (!(action .getWhoClicked () instanceof Conversable conversable )) {
440+ Inventory storageInv ,
441+ @ javax . annotation . Nullable UUID recipientUuid ) {
442+ if (!(action .getWhoClicked () instanceof Player player )) {
438443 return ;
439444 }
440445 List <ItemStack > items = new ArrayList <>();
@@ -455,6 +460,36 @@ private void processPost(
455460 }
456461 // Clear the storage inv here
457462 storageInv .clear ();
463+
464+ if (recipientUuid != null ) {
465+ // Send directly to pre-specified recipient (no prompt)
466+ OfflinePlayer recipient = this .plugin .getServer ().getOfflinePlayer (recipientUuid );
467+ if (!recipient .hasPlayedBefore ()) {
468+ String name = recipient .getName () != null ? recipient .getName () : recipientUuid .toString ();
469+ player .sendMessage (this .messageContainer .messageFor ("prompt.post-parcel.unknown-player" )
470+ .replaceText (builder -> builder .matchLiteral ("%player%" ).replacement (name )));
471+ InventoryUtil .addItems (player , items );
472+ return ;
473+ }
474+ if (player .getUniqueId ().equals (recipientUuid )) {
475+ player .sendMessage (this .messageContainer .messageFor ("prompt.post-parcel.send-parcel-self" ));
476+ InventoryUtil .addItems (player , items );
477+ return ;
478+ }
479+ var response = this .economy .withdrawPlayer (player , this .postSettings .postPrice ());
480+ if (!response .transactionSuccess ()) {
481+ player .sendMessage (this .messageContainer .messageFor ("prompt.post-parcel.insufficient-balance" ));
482+ InventoryUtil .addItems (player , items );
483+ return ;
484+ }
485+ this .postalPackageFactory .createAndPostPackage (player .getUniqueId (), recipientUuid , items , false );
486+ player .sendMessage (this .messageContainer .messageFor ("prompt.post-parcel.send-parcel-success" ));
487+ action .getGui ().close (player , true );
488+ return ;
489+ }
490+
491+ // No recipient: start conversation to ask for username
492+ Conversable conversable = (Conversable ) player ;
458493 // Copy the current history
459494 Deque <InventoryGui > history = new ArrayDeque <>(InventoryGui .getHistory (action .getWhoClicked ()));
460495 // Remove the current UI so it isn't added back
@@ -477,7 +512,6 @@ private void processPost(
477512 .buildConversation (conversable );
478513 conversation .addConversationAbandonedListener (event -> {
479514 if (!event .gracefulExit ()) {
480- // If the conversation is abandoned, give the items back to the player
481515 InventoryUtil .addItems (action .getWhoClicked (), items );
482516 }
483517 Conversable who = event .getContext ().getForWhom ();
@@ -488,7 +522,6 @@ private void processPost(
488522 }
489523 }
490524 });
491- // Start conversation to send
492525 conversation .begin ();
493526 }
494527
0 commit comments