Skip to content
This repository was archived by the owner on Mar 8, 2022. It is now read-only.

Commit 2739785

Browse files
committed
require confirm seller to pay for others, add pay/cancel command prompt
1 parent ac3400f commit 2739785

File tree

3 files changed

+49
-11
lines changed

3 files changed

+49
-11
lines changed

src/main/java/cat/nyaa/HamsterEcoHelper/transaction/TransactionCommands.java

+26-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
import cat.nyaa.nyaacore.Message;
1111
import cat.nyaa.nyaacore.utils.LocaleUtils;
1212
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.*;
1714
import org.bukkit.Material;
1815
import org.bukkit.OfflinePlayer;
1916
import org.bukkit.command.CommandSender;
@@ -73,6 +70,19 @@ public void sellTo(CommandSender sender, Arguments args) {
7370
Invoice invoice = plugin.transactionManager.sellTo(seller, buyer, item, price, tax);
7471
seller.getInventory().setItemInMainHand(new ItemStack(Material.AIR));
7572
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);
7686
invoiceMessage(componentMap, "user.transaction.drafted_seller", invoice.getId(), invoice.getTotalPrice(), invoice.getTax())
7787
.send(seller);
7888
invoiceMessage(componentMap, "user.transaction.drafted_buyer", invoice.getId(), invoice.getTotalPrice(), invoice.getTax())
@@ -109,6 +119,18 @@ public void pay(CommandSender sender, Arguments args) {
109119
if (invoice == null) return;
110120
}
111121
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+
}
112134
double totalPrice = invoice.getTotalPrice();
113135
double tax = invoice.getTax();
114136
if (plugin.eco.enoughMoney(drawee, totalPrice + tax)) {

src/main/resources/lang/en_US.yml

+11-3
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,12 @@ user:
252252
message_too_long: ad text max length is %d
253253
no_adid: "No such AdsID"
254254
transaction:
255-
drafted_seller: Invoice [%d] drafted. You offer {itemName} *{amount} to {buyer} with total price $%.2f (tax $%.2f).
256-
drafted_buyer: Invoice [%d] drafted. {seller} offer {itemName} *{amount} to you with total price $%.2f (tax $%.2f).
255+
drafted_seller: |-
256+
Invoice [%d] drafted. You offer {itemName} *{amount} to {buyer} with total price $%.2f (tax $%.2f).
257+
You can cancel the invoice by {cancelCommand}.
258+
drafted_buyer: |-
259+
Invoice [%d] drafted. {seller} offer {itemName} *{amount} to you with total price $%.2f (tax $%.2f).
260+
You can pay the invoice by {payCommand} or cancel the invoice by {cancelCommand}.
257261
max_open_sellside_limit: Maximum open sellside invoices limit %d exceeded.
258262
not_found: Invoice not found
259263
no_active_buy: You have no active buyside invoice.
@@ -286,7 +290,11 @@ user:
286290
completed_invoice: |-
287291
Invoice [%d] drafted at {createdTime} completed at {updatedTime}.
288292
{seller} sold {itemName} *{amount} to {buyer} with total price $%.2f (tax $%.2f) paid by {drawee}.
289-
293+
command_hover_text: Click to insert command to chatbox
294+
pay_command: /heh transaction pay %d
295+
cancel_command: /heh transaction cancel %d
296+
pay_others: You are paying for others invoice, please add seller's name after invoice ID
297+
wrong_seller: Wrong seller.
290298
manual:
291299
no_description: No description
292300
no_usage: No usage

src/main/resources/lang/zh_CN.yml

+12-4
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,12 @@ user:
238238
message_too_long: 广告内容最长为 %d 个字符
239239
no_adid: 找不到指定的 AdsID
240240
transaction:
241-
drafted_seller: 账单 [%d] 已起草。你计划以总价 %.2f(税 %.2f)向 {buyer} 出售 {itemName} *{amount}。
242-
drafted_buyer: 账单 [%d] 已起草。{seller} 计划以总价 %.2f(税 %.2f)向你出售 {itemName} *{amount}。
241+
drafted_seller: |-
242+
账单 [%d] 已起草。你计划以总价 %.2f(税 %.2f)向 {buyer} 出售 {itemName} *{amount}。
243+
可使用 {cancelCommand} 取消该账单。
244+
drafted_buyer: |-
245+
账单 [%d] 已起草。{seller} 计划以总价 %.2f(税 %.2f)向你出售 {itemName} *{amount}。
246+
可使用 {payCommand} 支付该账单,{cancelCommand} 取消该账单。
243247
max_open_sellside_limit: 达到最大卖方开放账单 %d 限制。
244248
not_found: 未找到账单
245249
no_active_buy: 你没有活跃的买方账单。
@@ -272,7 +276,11 @@ user:
272276
completed_invoice: |-
273277
账单 [%d] 于 {createdTime} 起草并在 {updatedTime} 完成。
274278
{seller} 以总价 %.2f(税 %.2f)向 {buyer} 出售了 {itemName} *{amount},由 {drawee} 支付。
275-
279+
command_hover_text: 点击输入命令
280+
pay_command: /heh transaction pay %d
281+
cancel_command: /heh transaction cancel %d
282+
pay_others: 您正在为其他人支付订单,请在订单号后输入卖家 ID 以确认。
283+
wrong_seller: 卖家 ID 不正确。
276284
manual:
277285
no_description: 无描述
278286
no_usage: 无用法说明
@@ -402,7 +410,7 @@ manual:
402410
usage: 用法: /heh transaction sellto [player] [totalPrice]
403411
pay:
404412
description: 支付账单
405-
usage: 用法: /heh transaction pay [id]
413+
usage: 用法: /heh transaction pay [id] [seller]
406414
cancel:
407415
description: 取消账单
408416
usage: 用法: /heh transaction cancel [id]

0 commit comments

Comments
 (0)