2222import com .lishid .openinv .OpenInv ;
2323import io .papermc .lib .PaperLib ;
2424import lombok .EqualsAndHashCode ;
25+ import net .kyori .adventure .text .Component ;
26+ import net .kyori .adventure .text .serializer .legacy .LegacyComponentSerializer ;
2527import org .bukkit .*;
2628import org .bukkit .block .Block ;
2729import org .bukkit .block .BlockFace ;
4244import org .jetbrains .annotations .Nullable ;
4345import org .maxgamer .quickshop .QuickShop ;
4446import org .maxgamer .quickshop .event .*;
47+ import org .maxgamer .quickshop .externalhelper .paperadventurelib .PaperAdventureLib ;
48+ import org .maxgamer .quickshop .externalhelper .paperadventurelib .SignAdventure ;
4549import org .maxgamer .quickshop .util .PriceLimiter ;
4650import org .maxgamer .quickshop .util .Util ;
4751
@@ -605,15 +609,78 @@ public boolean inventoryAvailable() {
605609 return true ;
606610 }
607611
608- @ Override
609- public String [] getSignText () {
612+ // @Override
613+ // public Component[] getSignText() {
614+ // Util.ensureThread(false);
615+ // Component[] lines = new Component[4];
616+ //
617+ // //Line 1
618+ // OfflinePlayer player = plugin.getServer().getOfflinePlayer(this.getOwner());
619+ // String statusStringKey = inventoryAvailable() ? "signs.status-available" : "signs.status-unavailable";
620+ // lines[0] = Component.text(plugin.text().of("signs.header", this.ownerName(false), plugin.text().of(statusStringKey).forLocale()).forLocale());
621+ //
622+ // //Line 2
623+ // String tradingStringKey;
624+ // String noRemainingStringKey;
625+ // int shopRemaining;
626+ //
627+ // switch (shopType) {
628+ // case BUYING:
629+ // shopRemaining = getRemainingSpace();
630+ // tradingStringKey = isStackingShop() ? "signs.stack-buying" : "signs.buying";
631+ // noRemainingStringKey = "signs.out-of-space";
632+ // break;
633+ // case SELLING:
634+ // shopRemaining = getRemainingStock();
635+ // tradingStringKey = isStackingShop() ? "signs.stack-selling" : "signs.selling";
636+ // noRemainingStringKey = "signs.out-of-stock";
637+ // break;
638+ // default:
639+ // shopRemaining = 0;
640+ // tradingStringKey = "MissingKey for shop type:" + shopType;
641+ // noRemainingStringKey = "MissingKey for shop type:" + shopType;
642+ // }
643+ // switch (shopRemaining) {
644+ // //Unlimited
645+ // case -1:
646+ // lines[1] = Component.text(plugin.text().of(tradingStringKey, plugin.text().of("signs.unlimited").forLocale()).forLocale());
647+ // break;
648+ // //No remaining
649+ // case 0:
650+ // lines[1] =Component.text(plugin.text().of(noRemainingStringKey).forLocale());
651+ // break;
652+ // //Has remaining
653+ // default:
654+ // lines[1] = Component.text(plugin.text().of(tradingStringKey, Integer.toString(shopRemaining)).forLocale());
655+ // }
656+ //
657+ // //line 3
658+ // lines[2] = Component.text(plugin.text().of("signs.item", Util.getItemStackName(this.getItem())).forLocale());
659+ //
660+ // //line 4
661+ // if (this.isStackingShop()) {
662+ // lines[3] = Component.text(plugin.text().of("signs.stack-price",
663+ // Util.format(this.getPrice(), this), Integer.toString(item.getAmount()),
664+ // Util.getItemStackName(item)).forLocale());
665+ // } else {
666+ // lines[3] = Component.text( plugin.text().of("signs.price", Util.format(this.getPrice(), this)).forLocale());
667+ // }
668+ //
669+ // //New pattern for recognizing shop sign
670+ // lines[1] = Component.text(shopSignPrefix + lines[1] + " ");
671+ //
672+ // return lines;
673+ // }
674+
675+ @ Override
676+ public Component [] getSignText () {
610677 Util .ensureThread (false );
611- String [] lines = new String [4 ];
678+ Component [] lines = new Component [4 ];
612679
613680 //Line 1
614681 OfflinePlayer player = plugin .getServer ().getOfflinePlayer (this .getOwner ());
615682 String statusStringKey = inventoryAvailable () ? "signs.status-available" : "signs.status-unavailable" ;
616- lines [0 ] = plugin .text ().of ("signs.header" , this .ownerName (false ), plugin .text ().of (statusStringKey ).forLocale ()).forLocale ();
683+ lines [0 ] = Component . text ( plugin .text ().of ("signs.header" , this .ownerName (false ), plugin .text ().of (statusStringKey ).forLocale ()).forLocale () );
617684
618685 //Line 2
619686 String tradingStringKey ;
@@ -639,50 +706,55 @@ public String[] getSignText() {
639706 switch (shopRemaining ) {
640707 //Unlimited
641708 case -1 :
642- lines [1 ] = plugin .text ().of (tradingStringKey , plugin .text ().of ("signs.unlimited" ).forLocale ()).forLocale ();
709+ lines [1 ] = Component . text ( plugin .text ().of (tradingStringKey , plugin .text ().of ("signs.unlimited" ).forLocale ()).forLocale () );
643710 break ;
644711 //No remaining
645712 case 0 :
646- lines [1 ] =plugin .text ().of (noRemainingStringKey ).forLocale ();
713+ lines [1 ] =Component . text ( plugin .text ().of (noRemainingStringKey ).forLocale () );
647714 break ;
648715 //Has remaining
649716 default :
650- lines [1 ] = plugin .text ().of (tradingStringKey , Integer .toString (shopRemaining )).forLocale ();
717+ lines [1 ] = Component . text ( plugin .text ().of (tradingStringKey , Integer .toString (shopRemaining )).forLocale () );
651718 }
652719
653720 //line 3
654- lines [2 ] = plugin .text ().of ("signs.item" , Util .getItemStackName (this .getItem ())).forLocale ();
721+ lines [2 ] = Component . text ( plugin .text ().of ("signs.item" , Util .getItemStackName (this .getItem ())).forLocale () );
655722
656723 //line 4
657724 if (this .isStackingShop ()) {
658- lines [3 ] = plugin .text ().of ("signs.stack-price" ,
725+ lines [3 ] = Component . text ( plugin .text ().of ("signs.stack-price" ,
659726 Util .format (this .getPrice (), this ), Integer .toString (item .getAmount ()),
660- Util .getItemStackName (item )).forLocale ();
727+ Util .getItemStackName (item )).forLocale ()) ;
661728 } else {
662- lines [3 ] = plugin .text ().of ("signs.price" , Util .format (this .getPrice (), this )).forLocale ();
729+ lines [3 ] = Component . text ( plugin .text ().of ("signs.price" , Util .format (this .getPrice (), this )).forLocale () );
663730 }
664731
665732 //New pattern for recognizing shop sign
666- lines [1 ] = shopSignPrefix + lines [1 ] + " " ;
733+ lines [1 ] = Component . text ( shopSignPrefix + lines [1 ] + " " ) ;
667734
668735 return lines ;
669736 }
670737
738+
671739 /**
672740 * Changes all lines of text on a sign near the shop
673741 *
674742 * @param lines The array of lines to change. Index is line number.
675743 */
676744 @ Override
677- public void setSignText (@ NotNull String [] lines ) {
745+ public void setSignText (@ NotNull Component [] lines ) {
678746 Util .ensureThread (false );
679747 List <Sign > signs = this .getSigns ();
680748 for (Sign sign : signs ) {
681749 if (Arrays .equals (sign .getLines (), lines )) {
682750 continue ;
683751 }
684752 for (int i = 0 ; i < lines .length ; i ++) {
685- sign .setLine (i , lines [i ]);
753+ if (PaperAdventureLib .isSupported ()){
754+ SignAdventure .set (sign ,i ,lines [i ]);
755+ }else {
756+ sign .setLine (i , LegacyComponentSerializer .legacySection ().serialize (lines [i ]));
757+ }
686758 }
687759 if (plugin .getGameVersion ().isSignTextDyeSupport ()) {
688760 DyeColor dyeColor = Util .getDyeColor ();
0 commit comments