|
10 | 10 | import cat.nyaa.nyaacore.Message;
|
11 | 11 | import cat.nyaa.nyaacore.utils.LocaleUtils;
|
12 | 12 | import com.google.common.collect.Iterables;
|
13 |
| -import net.md_5.bungee.api.chat.BaseComponent; |
14 |
| -import net.md_5.bungee.api.chat.ComponentBuilder; |
15 |
| -import net.md_5.bungee.api.chat.HoverEvent; |
16 |
| -import net.md_5.bungee.api.chat.TextComponent; |
| 13 | +import net.md_5.bungee.api.chat.*; |
17 | 14 | import org.bukkit.Material;
|
18 | 15 | import org.bukkit.OfflinePlayer;
|
19 | 16 | import org.bukkit.command.CommandSender;
|
@@ -73,6 +70,19 @@ public void sellTo(CommandSender sender, Arguments args) {
|
73 | 70 | Invoice invoice = plugin.transactionManager.sellTo(seller, buyer, item, price, tax);
|
74 | 71 | seller.getInventory().setItemInMainHand(new ItemStack(Material.AIR));
|
75 | 72 | Map<String, BaseComponent> componentMap = invoiceComponent(invoice);
|
| 73 | + String hoverText = I18n.format("user.transaction.command_hover_text", invoice.getId()); |
| 74 | + HoverEvent hover = new HoverEvent(HoverEvent.Action.SHOW_TEXT, |
| 75 | + new BaseComponent[]{new TextComponent(hoverText)}); |
| 76 | + String payCmd = I18n.format("user.transaction.pay_command", invoice.getId()); |
| 77 | + BaseComponent payCommand = new TextComponent(payCmd); |
| 78 | + payCommand.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, payCmd)); |
| 79 | + payCommand.setHoverEvent(hover); |
| 80 | + String cancelCmd = I18n.format("user.transaction.cancel_command", invoice.getId()); |
| 81 | + BaseComponent cancelCommand = new TextComponent(cancelCmd); |
| 82 | + cancelCommand.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, cancelCmd)); |
| 83 | + cancelCommand.setHoverEvent(hover); |
| 84 | + componentMap.put("{payCommand}", payCommand); |
| 85 | + componentMap.put("{cancelCommand}", cancelCommand); |
76 | 86 | invoiceMessage(componentMap, "user.transaction.drafted_seller", invoice.getId(), invoice.getTotalPrice(), invoice.getTax())
|
77 | 87 | .send(seller);
|
78 | 88 | invoiceMessage(componentMap, "user.transaction.drafted_buyer", invoice.getId(), invoice.getTotalPrice(), invoice.getTax())
|
@@ -109,6 +119,18 @@ public void pay(CommandSender sender, Arguments args) {
|
109 | 119 | if (invoice == null) return;
|
110 | 120 | }
|
111 | 121 | if (notDraft(sender, drawee, invoice)) return;
|
| 122 | + if (!drawee.getUniqueId().equals(invoice.getBuyerId())) { |
| 123 | + if (args.top() == null) { |
| 124 | + msg(sender, "user.transaction.pay_others"); |
| 125 | + return; |
| 126 | + } else { |
| 127 | + OfflinePlayer expectedSeller = args.nextOfflinePlayer(); |
| 128 | + if (!expectedSeller.getUniqueId().equals(invoice.getSellerId())) { |
| 129 | + msg(sender, "user.transaction.wrong_seller"); |
| 130 | + return; |
| 131 | + } |
| 132 | + } |
| 133 | + } |
112 | 134 | double totalPrice = invoice.getTotalPrice();
|
113 | 135 | double tax = invoice.getTax();
|
114 | 136 | if (plugin.eco.enoughMoney(drawee, totalPrice + tax)) {
|
|
0 commit comments