Skip to content

Commit 88801ec

Browse files
committed
1 parent f7224f5 commit 88801ec

File tree

3 files changed

+46
-15
lines changed

3 files changed

+46
-15
lines changed

src/main/java/org/maxgamer/quickshop/chat/platform/minedown/BungeeQuickChat.java

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import lombok.AllArgsConstructor;
2323
import net.md_5.bungee.api.chat.*;
24+
import net.md_5.bungee.chat.ComponentSerializer;
2425
import org.apache.commons.lang.StringUtils;
2526
import org.bukkit.ChatColor;
2627
import org.bukkit.command.CommandSender;
@@ -83,16 +84,22 @@ public void sendItemHologramChat(@NotNull Player player, @NotNull String text, @
8384
ComponentBuilder builder = new ComponentBuilder();
8485
TextSplitter.SpilledString spilledString = TextSplitter.deBakeItem(text);
8586
if (spilledString == null) {
87+
Util.debugLog("Spilled string is null");
8688
builder.append(text);
8789
} else {
90+
Util.debugLog("Building component...");
8891
builder.append(spilledString.getLeft())
8992
.append(spilledString.getComponents())
9093
.append(spilledString.getRight());
94+
Util.debugLog("Left is " + spilledString.getLeft());
95+
Util.debugLog("Right is " + spilledString.getRight());
96+
Util.debugLog("Component is " + ComponentSerializer.toString(spilledString.getComponents()));
97+
Util.debugLog("Success...");
9198
}
92-
TextComponent centerItem = new TextComponent(builder.create());
93-
ComponentBuilder cBuilder = new ComponentBuilder(json);
94-
centerItem.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ITEM, cBuilder.create())); //FIXME: Update this when drop 1.15 supports
95-
player.spigot().sendMessage(centerItem);
99+
builder.event(new HoverEvent(HoverEvent.Action.SHOW_ITEM, new ComponentBuilder(json).create()));
100+
BaseComponent[] components = builder.create();
101+
Util.debugLog("Sending debug: " + ComponentSerializer.toString(components));
102+
player.spigot().sendMessage(components);
96103
} catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException | InstantiationException e) {
97104
plugin.getLogger().log(Level.WARNING, "Failed to process chat component", e);
98105
player.spigot().sendMessage(errorComponent);
@@ -103,33 +110,38 @@ public void sendItemHologramChat(@NotNull Player player, @NotNull String text, @
103110
public @NotNull QuickComponent getItemHologramChat(@NotNull Shop shop, @NotNull ItemStack itemStack, @NotNull Player player, @NotNull String message) {
104111
TextComponent errorComponent = new TextComponent(plugin.text().of(player, "menu.item-holochat-error").forLocale());
105112
try {
106-
107113
String json = ReflectFactory.convertBukkitItemStackToJson(itemStack);
108114
if (json == null) {
109115
return new QuickComponentImpl(errorComponent);
110116
}
111117
ComponentBuilder builder = new ComponentBuilder();
112118
TextSplitter.SpilledString spilledString = TextSplitter.deBakeItem(message);
113119
if (spilledString == null) {
120+
Util.debugLog("Spilled string is null");
114121
builder.append(message);
115122
} else {
123+
Util.debugLog("Building component...");
116124
builder.append(spilledString.getLeft())
117125
.append(spilledString.getComponents())
118126
.append(spilledString.getRight());
127+
Util.debugLog("Left is " + spilledString.getLeft());
128+
Util.debugLog("Right is " + spilledString.getRight());
129+
Util.debugLog("Component is " + ComponentSerializer.toString(spilledString.getComponents()));
130+
Util.debugLog("Success...");
119131
}
132+
120133
builder.append(" ")
121134
.append(plugin.text().of(player, "menu.preview").forLocale());
122-
TextComponent normalmessage = new TextComponent(builder.create());
123-
ComponentBuilder cBuilder = new ComponentBuilder(json);
135+
// builder.event(new HoverEvent(HoverEvent.Action.SHOW_ITEM, new ComponentBuilder(json).create()));
124136
if (QuickShop.getPermissionManager().hasPermission(player, "quickshop.preview")) {
125-
normalmessage.setClickEvent(new ClickEvent(
137+
builder.event(new ClickEvent(
126138
ClickEvent.Action.RUN_COMMAND,
127139
MsgUtil.fillArgs(
128140
"/qs silentpreview {0}",
129141
shop.getRuntimeRandomUniqueId().toString())));
130142
}
131-
normalmessage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ITEM, cBuilder.create())); //FIXME: Update this when drop 1.15 supports
132-
return new QuickComponentImpl(normalmessage);
143+
builder.event(new HoverEvent(HoverEvent.Action.SHOW_ITEM, new ComponentBuilder(json).create()));
144+
return new QuickComponentImpl(builder.create());
133145
} catch (Throwable t) {
134146
plugin.getLogger().log(Level.WARNING, "Failed to process chat component", t);
135147
return new QuickComponentImpl(errorComponent);

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -713,21 +713,32 @@ public void actionBuy(
713713
String.valueOf(amount),
714714
MsgUtil.convertItemStackToTranslateText(shop.getItem().getType())).forLocale();
715715

716+
MsgUtil.TransactionMessage transactionMessage = new MsgUtil.TransactionMessage(msg, Util.serialize(shop.getItem()), null);
717+
718+
if (plugin.getConfiguration().getBoolean("shop.sending-stock-message-to-staffs")) {
719+
for (UUID staff : shop.getModerator().getStaffs()) {
720+
MsgUtil.send(shop, staff, transactionMessage);
721+
}
722+
}
723+
MsgUtil.send(shop, shop.getOwner(), transactionMessage);
724+
716725
if (space == amount) {
717-
msg += "\n" + plugin.text().of(buyer, "shop-out-of-space",
726+
msg = plugin.text().of(buyer, "shop-out-of-space",
718727
Integer.toString(shop.getLocation().getBlockX()),
719728
Integer.toString(shop.getLocation().getBlockY()),
720729
Integer.toString(shop.getLocation().getBlockZ())).forLocale();
721730
}
722731

723-
MsgUtil.TransactionMessage transactionMessage = new MsgUtil.TransactionMessage(msg, Util.serialize(shop.getItem()), null);
732+
transactionMessage = new MsgUtil.TransactionMessage(msg, Util.serialize(shop.getItem()), null);
724733

725734
if (plugin.getConfiguration().getBoolean("shop.sending-stock-message-to-staffs")) {
726735
for (UUID staff : shop.getModerator().getStaffs()) {
727736
MsgUtil.send(shop, staff, transactionMessage);
728737
}
729738
}
730739
MsgUtil.send(shop, shop.getOwner(), transactionMessage);
740+
741+
731742
shop.buy(buyer, buyerInventory, player != null ? player.getLocation() : shop.getLocation(), amount);
732743
sendSellSuccess(buyer, shop, amount);
733744
ShopSuccessPurchaseEvent se = new ShopSuccessPurchaseEvent(shop, buyer, buyerInventory, amount, total, taxModifier);
@@ -1092,16 +1103,25 @@ public void actionSell(
10921103
MsgUtil.convertItemStackToTranslateText(shop.getItem().getType()),
10931104
Double.toString(total)).forLocale();
10941105
}
1106+
1107+
MsgUtil.TransactionMessage transactionMessage = new MsgUtil.TransactionMessage(msg, Util.serialize(shop.getItem()), null);
1108+
1109+
MsgUtil.send(shop, shop.getOwner(), transactionMessage);
1110+
if (plugin.getConfiguration().getBoolean("shop.sending-stock-message-to-staffs")) {
1111+
for (UUID staff : shop.getModerator().getStaffs()) {
1112+
MsgUtil.send(shop, staff, transactionMessage);
1113+
}
1114+
}
10951115
// Transfers the item from A to B
10961116
if (stock == amount) {
1097-
msg += "\n" + plugin.text().of(seller, "shop-out-of-stock",
1117+
msg = plugin.text().of(seller, "shop-out-of-stock",
10981118
Integer.toString(shop.getLocation().getBlockX()),
10991119
Integer.toString(shop.getLocation().getBlockY()),
11001120
Integer.toString(shop.getLocation().getBlockZ()),
11011121
MsgUtil.convertItemStackToTranslateText(shop.getItem().getType())).forLocale();
11021122
}
11031123

1104-
MsgUtil.TransactionMessage transactionMessage = new MsgUtil.TransactionMessage(msg, Util.serialize(shop.getItem()), null);
1124+
transactionMessage = new MsgUtil.TransactionMessage(msg, Util.serialize(shop.getItem()), null);
11051125

11061126
MsgUtil.send(shop, shop.getOwner(), transactionMessage);
11071127
if (plugin.getConfiguration().getBoolean("shop.sending-stock-message-to-staffs")) {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,6 @@ public static void send(@NotNull Shop shop, @NotNull UUID player, @NotNull Trans
399399
if (shop.isUnlimited() && plugin.getConfiguration().getBoolean("shop.ignore-unlimited-shop-messages")) {
400400
return; // Ignore unlimited shops messages.
401401
}
402-
Util.debugLog(transactionMessage.getMessage());
403402
OfflinePlayer p = Bukkit.getOfflinePlayer(player);
404403
if (!p.isOnline()) {
405404
List<TransactionMessage> msgs = OUTGOING_MESSAGES.getOrDefault(player, new LinkedList<>());

0 commit comments

Comments
 (0)