Skip to content

Commit c45d185

Browse files
committed
Revert "Use paper adventure lib for"
This reverts commit 9ef1a63
1 parent e8b9f4b commit c45d185

File tree

3 files changed

+76
-101
lines changed

3 files changed

+76
-101
lines changed

src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java

Lines changed: 14 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
import com.lishid.openinv.OpenInv;
2323
import io.papermc.lib.PaperLib;
2424
import lombok.EqualsAndHashCode;
25-
import net.kyori.adventure.text.Component;
26-
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
2725
import org.bukkit.*;
2826
import org.bukkit.block.Block;
2927
import org.bukkit.block.BlockFace;
@@ -44,8 +42,6 @@
4442
import org.jetbrains.annotations.Nullable;
4543
import org.maxgamer.quickshop.QuickShop;
4644
import org.maxgamer.quickshop.event.*;
47-
import org.maxgamer.quickshop.externalhelper.paperadventurelib.PaperAdventureLib;
48-
import org.maxgamer.quickshop.externalhelper.paperadventurelib.SignAdventure;
4945
import org.maxgamer.quickshop.util.PriceLimiter;
5046
import org.maxgamer.quickshop.util.Util;
5147

@@ -609,78 +605,15 @@ public boolean inventoryAvailable() {
609605
return true;
610606
}
611607

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() {
608+
@Override
609+
public String[] getSignText() {
677610
Util.ensureThread(false);
678-
Component[] lines = new Component[4];
611+
String[] lines = new String[4];
679612

680613
//Line 1
681614
OfflinePlayer player = plugin.getServer().getOfflinePlayer(this.getOwner());
682615
String statusStringKey = inventoryAvailable() ? "signs.status-available" : "signs.status-unavailable";
683-
lines[0] = Component.text(plugin.text().of("signs.header", this.ownerName(false), plugin.text().of(statusStringKey).forLocale()).forLocale());
616+
lines[0] = plugin.text().of("signs.header", this.ownerName(false), plugin.text().of(statusStringKey).forLocale()).forLocale();
684617

685618
//Line 2
686619
String tradingStringKey;
@@ -706,55 +639,50 @@ public Component[] getSignText() {
706639
switch (shopRemaining) {
707640
//Unlimited
708641
case -1:
709-
lines[1] = Component.text(plugin.text().of(tradingStringKey, plugin.text().of("signs.unlimited").forLocale()).forLocale());
642+
lines[1] = plugin.text().of(tradingStringKey, plugin.text().of("signs.unlimited").forLocale()).forLocale();
710643
break;
711644
//No remaining
712645
case 0:
713-
lines[1] =Component.text(plugin.text().of(noRemainingStringKey).forLocale());
646+
lines[1] =plugin.text().of(noRemainingStringKey).forLocale();
714647
break;
715648
//Has remaining
716649
default:
717-
lines[1] = Component.text(plugin.text().of(tradingStringKey, Integer.toString(shopRemaining)).forLocale());
650+
lines[1] = plugin.text().of(tradingStringKey, Integer.toString(shopRemaining)).forLocale();
718651
}
719652

720653
//line 3
721-
lines[2] = Component.text(plugin.text().of("signs.item", Util.getItemStackName(this.getItem())).forLocale());
654+
lines[2] = plugin.text().of("signs.item", Util.getItemStackName(this.getItem())).forLocale();
722655

723656
//line 4
724657
if (this.isStackingShop()) {
725-
lines[3] = Component.text(plugin.text().of("signs.stack-price",
658+
lines[3] = plugin.text().of("signs.stack-price",
726659
Util.format(this.getPrice(), this), Integer.toString(item.getAmount()),
727-
Util.getItemStackName(item)).forLocale());
660+
Util.getItemStackName(item)).forLocale();
728661
} else {
729-
lines[3] = Component.text( plugin.text().of("signs.price", Util.format(this.getPrice(), this)).forLocale());
662+
lines[3] = plugin.text().of("signs.price", Util.format(this.getPrice(), this)).forLocale();
730663
}
731664

732665
//New pattern for recognizing shop sign
733-
lines[1] = Component.text(shopSignPrefix + lines[1] + " ");
666+
lines[1] = shopSignPrefix + lines[1] + " ";
734667

735668
return lines;
736669
}
737670

738-
739671
/**
740672
* Changes all lines of text on a sign near the shop
741673
*
742674
* @param lines The array of lines to change. Index is line number.
743675
*/
744676
@Override
745-
public void setSignText(@NotNull Component[] lines) {
677+
public void setSignText(@NotNull String[] lines) {
746678
Util.ensureThread(false);
747679
List<Sign> signs = this.getSigns();
748680
for (Sign sign : signs) {
749681
if (Arrays.equals(sign.getLines(), lines)) {
750682
continue;
751683
}
752684
for (int i = 0; i < lines.length; i++) {
753-
if(PaperAdventureLib.isSupported()){
754-
SignAdventure.set(sign,i,lines[i]);
755-
}else{
756-
sign.setLine(i, LegacyComponentSerializer.legacySection().serialize(lines[i]));
757-
}
685+
sign.setLine(i, lines[i]);
758686
}
759687
if (plugin.getGameVersion().isSignTextDyeSupport()) {
760688
DyeColor dyeColor = Util.getDyeColor();

src/main/java/org/maxgamer/quickshop/shop/Shop.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
package org.maxgamer.quickshop.shop;
2121

22-
import net.kyori.adventure.text.Component;
2322
import org.bukkit.Location;
2423
import org.bukkit.block.Block;
2524
import org.bukkit.block.Sign;
@@ -165,7 +164,6 @@ public interface Shop {
165164
*/
166165
void sell(@NotNull UUID seller, @NotNull Inventory sellerInventory, @NotNull Location loc2Drop, int paramInt);
167166

168-
169167
/**
170168
* Generate new sign texts on shop's sign.
171169
*/
@@ -182,17 +180,17 @@ public interface Shop {
182180
* Line 3: Price
183181
*/
184182
@NotNull
185-
default Component[] getSignText() {
183+
default String[] getSignText() {
186184
//backward support
187185
throw new UnsupportedOperationException();
188186
}
189187

190188
/**
191189
* Set texts on shop's sign
192190
*
193-
* @param contents The texts you want set
191+
* @param paramArrayOfString The texts you want set
194192
*/
195-
void setSignText(@NotNull Component[] contents);
193+
void setSignText(@NotNull String[] paramArrayOfString);
196194

197195
/**
198196
* Update shop data to database

src/main/java/org/maxgamer/quickshop/util/MsgUtil.java

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626
import lombok.Builder;
2727
import lombok.Data;
2828
import lombok.Getter;
29+
import net.kyori.adventure.key.Key;
30+
import net.kyori.adventure.nbt.api.BinaryTagHolder;
2931
import net.kyori.adventure.text.Component;
32+
import net.kyori.adventure.text.event.HoverEvent;
3033
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
3134
import org.apache.commons.lang.StringUtils;
3235
import org.bukkit.Bukkit;
@@ -57,6 +60,7 @@
5760
import java.io.File;
5861
import java.io.IOException;
5962
import java.io.InputStreamReader;
63+
import java.lang.reflect.InvocationTargetException;
6064
import java.sql.ResultSet;
6165
import java.sql.SQLException;
6266
import java.text.DecimalFormat;
@@ -115,12 +119,26 @@ public static boolean flush(@NotNull OfflinePlayer p) {
115119
if (data == null) {
116120
MsgUtil.sendDirectMessage(p.getPlayer(), msg.getMessage());
117121
} else {
118-
plugin.adventure().sender(player).sendMessage(
119-
Component.text(msg.getMessage())
120-
.hoverEvent(Util.generateItemHoverEvent(data)));
122+
plugin.adventure().sender(player).sendMessage(
123+
Component.text(msg.getMessage())
124+
.hoverEvent(HoverEvent.showItem(
125+
HoverEvent.ShowItem.of(
126+
Key.key(data.getType().getKey().getNamespace(),data.getType().getKey().getKey()),
127+
data.getAmount(),
128+
BinaryTagHolder.of(ReflectFactory.convertBukkitItemStackToJson(data))))));
129+
130+
//plugin.getQuickChat().sendItemHologramChat(player, msg.getMessage(), data);
121131
}
122132
} catch (InvalidConfigurationException e) {
123133
MsgUtil.sendDirectMessage(p.getPlayer(), msg.getMessage());
134+
} catch (InvocationTargetException e) {
135+
e.printStackTrace();
136+
} catch (IllegalAccessException e) {
137+
e.printStackTrace();
138+
} catch (NoSuchMethodException e) {
139+
e.printStackTrace();
140+
} catch (InstantiationException e) {
141+
e.printStackTrace();
124142
}
125143
}
126144
}
@@ -499,7 +517,11 @@ public static void send(@NotNull UUID player, @NotNull TransactionMessage transa
499517
ItemStack data = Util.deserialize(transactionMessage.getHoverItem());
500518
plugin.adventure().sender(p.getPlayer()).sendMessage(
501519
Component.text(transactionMessage.getMessage())
502-
.hoverEvent(Util.generateItemHoverEvent(data)));
520+
.hoverEvent(HoverEvent.showItem(
521+
HoverEvent.ShowItem.of(
522+
Key.key(data.getType().getKey().getNamespace(),data.getType().getKey().getKey()),
523+
data.getAmount(),
524+
BinaryTagHolder.of(ReflectFactory.convertBukkitItemStackToJson(data))))));
503525
// plugin.getQuickChat().sendItemHologramChat(p.getPlayer(), transactionMessage.getMessage(), Objects.requireNonNull(Util.deserialize(transactionMessage.getHoverItem())));
504526
} catch (Exception any) {
505527
Util.debugLog("Unknown error, send by plain text.");
@@ -535,11 +557,24 @@ public static void send(@NotNull Shop shop, @NotNull UUID player, @NotNull Trans
535557
if (p.getPlayer() != null) {
536558
if (transactionMessage.getHoverItem() != null) {
537559
try {
560+
try {
538561
ItemStack data = Util.deserialize(transactionMessage.getHoverItem());
539562
plugin.adventure().sender(p.getPlayer()).sendMessage(
540563
Component.text(transactionMessage.getMessage())
541-
.hoverEvent(Util.generateItemHoverEvent(data)));
542-
564+
.hoverEvent(HoverEvent.showItem(
565+
HoverEvent.ShowItem.of(
566+
Key.key(data.getType().getKey().getNamespace(),data.getType().getKey().getKey()),
567+
data.getAmount(),
568+
BinaryTagHolder.of(ReflectFactory.convertBukkitItemStackToJson(data))))));
569+
} catch (InvocationTargetException e) {
570+
e.printStackTrace();
571+
} catch (IllegalAccessException e) {
572+
e.printStackTrace();
573+
} catch (NoSuchMethodException e) {
574+
e.printStackTrace();
575+
} catch (InstantiationException e) {
576+
e.printStackTrace();
577+
}
543578
// plugin.getQuickChat().sendItemHologramChat(p.getPlayer(), transactionMessage.getMessage(), Objects.requireNonNull(Util.deserialize(transactionMessage.getHoverItem())));
544579
} catch (Exception any) {
545580
Util.debugLog("Unknown error, send by plain text.");
@@ -908,10 +943,24 @@ public static void sendShopInfo(@NotNull Player p, @NotNull Shop shop) {
908943
chatSheetPrinter.printLine(plugin.text().of(p,"menu.shop-information").forLocale());
909944
chatSheetPrinter.printLine(plugin.text().of(p,"menu.owner", shop.ownerName()).forLocale());
910945
// Enabled
911-
String msg = ChatColor.DARK_PURPLE + plugin.text().of(p,"tableformat.left_begin").forLocale() + plugin.text().of(p,"menu.item", Util.getItemStackName(items)) + " ";
912-
plugin.adventure().sender(p).sendMessage(
913-
Component.text(msg)
914-
.hoverEvent(Util.generateItemHoverEvent(items)));
946+
947+
try {
948+
plugin.adventure().sender(p).sendMessage(
949+
Component.text(ChatColor.DARK_PURPLE + plugin.text().of(p,"tableformat.left_begin").forLocale() + plugin.text().of(p,"menu.item", Util.getItemStackName(items)) + " ")
950+
.hoverEvent(HoverEvent.showItem(
951+
HoverEvent.ShowItem.of(
952+
Key.key(items.getType().getKey().getNamespace(),items.getType().getKey().getKey()),
953+
items.getAmount(),
954+
BinaryTagHolder.of(ReflectFactory.convertBukkitItemStackToJson(items))))));
955+
} catch (InvocationTargetException e) {
956+
e.printStackTrace();
957+
} catch (IllegalAccessException e) {
958+
e.printStackTrace();
959+
} catch (NoSuchMethodException e) {
960+
e.printStackTrace();
961+
} catch (InstantiationException e) {
962+
e.printStackTrace();
963+
}
915964
//plugin.getQuickChat().sendItemHologramChat(player, msg.getMessage(), data);
916965

917966
//plugin.getQuickChat().send(p, plugin.getQuickChat().getItemHologramChat(shop, items, p);

0 commit comments

Comments
 (0)