2323import io .papermc .lib .PaperLib ;
2424import lombok .EqualsAndHashCode ;
2525import me .lucko .helper .serialize .BlockPosition ;
26+ import net .md_5 .bungee .api .chat .ComponentBuilder ;
27+ import net .md_5 .bungee .api .chat .TextComponent ;
28+ import net .md_5 .bungee .api .chat .TranslatableComponent ;
2629import org .bukkit .*;
2730import org .bukkit .block .Block ;
2831import org .bukkit .block .BlockFace ;
4346import org .jetbrains .annotations .Nullable ;
4447import org .maxgamer .quickshop .QuickShop ;
4548import org .maxgamer .quickshop .event .*;
49+ import org .maxgamer .quickshop .util .ComponentPackge ;
4650import org .maxgamer .quickshop .util .JsonUtil ;
4751import org .maxgamer .quickshop .util .PriceLimiter ;
4852import org .maxgamer .quickshop .util .Util ;
@@ -688,14 +692,13 @@ public boolean inventoryAvailable() {
688692 }
689693
690694 @ Override
691- public String [] getSignText () {
695+ public List < ComponentPackge > getSignText (@ NotNull String locale ) {
692696 Util .ensureThread (false );
693- String [] lines = new String [4 ];
694-
697+ List <ComponentPackge > lines = new ArrayList <>();
695698 //Line 1
696699 OfflinePlayer player = plugin .getServer ().getOfflinePlayer (this .getOwner ());
697700 String statusStringKey = inventoryAvailable () ? "signs.status-available" : "signs.status-unavailable" ;
698- lines [ 0 ] = plugin .text ().of ("signs.header" , this .ownerName (false ), plugin .text ().of (statusStringKey ).forLocale ()).forLocale ();
701+ lines . add ( new ComponentPackge ( TextComponent . fromLegacyText ( plugin .text ().of ("signs.header" , this .ownerName (false ), plugin .text ().of (statusStringKey ).forLocale (locale )).forLocale (locale ))) );
699702
700703 //Line 2
701704 String tradingStringKey ;
@@ -718,35 +721,48 @@ public String[] getSignText() {
718721 tradingStringKey = "MissingKey for shop type:" + shopType ;
719722 noRemainingStringKey = "MissingKey for shop type:" + shopType ;
720723 }
724+ String line2 ;
721725 switch (shopRemaining ) {
722726 //Unlimited
723727 case -1 :
724- lines [ 1 ] = plugin .text ().of (tradingStringKey , plugin .text ().of ("signs.unlimited" ).forLocale ()).forLocale ();
728+ line2 = plugin .text ().of (tradingStringKey , plugin .text ().of ("signs.unlimited" ).forLocale (locale )).forLocale (locale );
725729 break ;
726730 //No remaining
727731 case 0 :
728- lines [ 1 ] = plugin .text ().of (noRemainingStringKey ).forLocale ();
732+ line2 = plugin .text ().of (noRemainingStringKey ).forLocale (locale );
729733 break ;
730734 //Has remaining
731735 default :
732- lines [ 1 ] = plugin .text ().of (tradingStringKey , Integer .toString (shopRemaining )).forLocale ();
736+ line2 = plugin .text ().of (tradingStringKey , Integer .toString (shopRemaining )).forLocale (locale );
733737 }
738+ lines .add (new ComponentPackge (TextComponent .fromLegacyText (shopSignPrefix +line2 +" " )));
734739
735740 //line 3
736- lines [2 ] = plugin .text ().of ("signs.item" , Util .getItemStackName (this .getItem ())).forLocale ();
741+ if (this .getItem ().hasItemMeta () && this .getItem ().getItemMeta ().hasDisplayName ()){
742+ TextComponent left = new TextComponent (plugin .text ().of ("signs.item-left" ).forLocale ());
743+ TranslatableComponent mediumItem = new TranslatableComponent ("item." +getItem ().getType ().getKey ().getNamespace ()+"." +getItem ().getType ().getKey ().getKey ());
744+ TextComponent right = new TextComponent (plugin .text ().of ("signs.item-right" ).forLocale ());
745+ lines .add (new ComponentPackge (new ComponentBuilder ()
746+ .append (left )
747+ .append (mediumItem )
748+ .append (right )
749+ .create ()));
750+ }else {
751+ lines .add (new ComponentPackge (new ComponentBuilder ().append ( TextComponent .fromLegacyText (plugin .text ().of ("signs.item-left" ).forLocale ()))
752+ .append (TextComponent .fromLegacyText (Util .getItemStackName (getItem ())))
753+ .append (TextComponent .fromLegacyText (plugin .text ().of ("signs.item-right" ).forLocale ())).create ()));
754+ }
737755
738756 //line 4
757+ String line4 ;
739758 if (this .isStackingShop ()) {
740- lines [ 3 ] = plugin .text ().of ("signs.stack-price" ,
759+ line4 = plugin .text ().of ("signs.stack-price" ,
741760 Util .format (this .getPrice (), this ), Integer .toString (item .getAmount ()),
742761 Util .getItemStackName (item )).forLocale ();
743762 } else {
744- lines [ 3 ] = plugin .text ().of ("signs.price" , Util .format (this .getPrice (), this )).forLocale ();
763+ line4 = plugin .text ().of ("signs.price" , Util .format (this .getPrice (), this )).forLocale ();
745764 }
746-
747- //New pattern for recognizing shop sign
748- lines [1 ] = shopSignPrefix + lines [1 ] + " " ;
749-
765+ lines .add (new ComponentPackge (TextComponent .fromLegacyText (line4 )));
750766 return lines ;
751767 }
752768
@@ -756,15 +772,12 @@ public String[] getSignText() {
756772 * @param lines The array of lines to change. Index is line number.
757773 */
758774 @ Override
759- public void setSignText (@ NotNull String [] lines ) {
775+ public void setSignText (@ NotNull List < ComponentPackge > lines ) {
760776 Util .ensureThread (false );
761777 List <Sign > signs = this .getSigns ();
762778 for (Sign sign : signs ) {
763- if (Arrays .equals (sign .getLines (), lines )) {
764- continue ;
765- }
766- for (int i = 0 ; i < lines .length ; i ++) {
767- sign .setLine (i , lines [i ]);
779+ for (int i = 0 ; i < lines .size (); i ++) {
780+ sign .setLine (i , new TextComponent (lines .get (i ).getComponents ()).toLegacyText ());
768781 }
769782 if (plugin .getGameVersion ().isSignTextDyeSupport ()) {
770783 DyeColor dyeColor = Util .getDyeColor ();
@@ -790,7 +803,7 @@ public void setSignText() {
790803 if (!Util .isLoaded (this .location )) {
791804 return ;
792805 }
793- this .setSignText (getSignText ());
806+ this .setSignText (getSignText ("en_us" ));
794807 }
795808
796809 /**
@@ -1535,6 +1548,7 @@ public void openPreview(@NotNull Player player) {
15351548 inventoryPreview = new InventoryPreview (plugin , getItem ().clone ());
15361549 }
15371550 inventoryPreview .show (player );
1551+
15381552 }
15391553
15401554 @ Override
0 commit comments