diff --git a/src/main/java/cat/nyaa/HamsterEcoHelper/transaction/TransactionCommands.java b/src/main/java/cat/nyaa/HamsterEcoHelper/transaction/TransactionCommands.java index a6306f6..4eeed27 100644 --- a/src/main/java/cat/nyaa/HamsterEcoHelper/transaction/TransactionCommands.java +++ b/src/main/java/cat/nyaa/HamsterEcoHelper/transaction/TransactionCommands.java @@ -10,10 +10,7 @@ import cat.nyaa.nyaacore.Message; import cat.nyaa.nyaacore.utils.LocaleUtils; import com.google.common.collect.Iterables; -import net.md_5.bungee.api.chat.BaseComponent; -import net.md_5.bungee.api.chat.ComponentBuilder; -import net.md_5.bungee.api.chat.HoverEvent; -import net.md_5.bungee.api.chat.TextComponent; +import net.md_5.bungee.api.chat.*; import org.bukkit.Material; import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; @@ -73,6 +70,19 @@ public void sellTo(CommandSender sender, Arguments args) { Invoice invoice = plugin.transactionManager.sellTo(seller, buyer, item, price, tax); seller.getInventory().setItemInMainHand(new ItemStack(Material.AIR)); Map componentMap = invoiceComponent(invoice); + String hoverText = I18n.format("user.transaction.command_hover_text", invoice.getId()); + HoverEvent hover = new HoverEvent(HoverEvent.Action.SHOW_TEXT, + new BaseComponent[]{new TextComponent(hoverText)}); + String payCmd = I18n.format("user.transaction.pay_command", invoice.getId()); + BaseComponent payCommand = new TextComponent(payCmd); + payCommand.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, payCmd)); + payCommand.setHoverEvent(hover); + String cancelCmd = I18n.format("user.transaction.cancel_command", invoice.getId()); + BaseComponent cancelCommand = new TextComponent(cancelCmd); + cancelCommand.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, cancelCmd)); + cancelCommand.setHoverEvent(hover); + componentMap.put("{payCommand}", payCommand); + componentMap.put("{cancelCommand}", cancelCommand); invoiceMessage(componentMap, "user.transaction.drafted_seller", invoice.getId(), invoice.getTotalPrice(), invoice.getTax()) .send(seller); invoiceMessage(componentMap, "user.transaction.drafted_buyer", invoice.getId(), invoice.getTotalPrice(), invoice.getTax()) @@ -109,6 +119,18 @@ public void pay(CommandSender sender, Arguments args) { if (invoice == null) return; } if (notDraft(sender, drawee, invoice)) return; + if (!drawee.getUniqueId().equals(invoice.getBuyerId())) { + if (args.top() == null) { + msg(sender, "user.transaction.pay_others"); + return; + } else { + OfflinePlayer expectedSeller = args.nextOfflinePlayer(); + if (!expectedSeller.getUniqueId().equals(invoice.getSellerId())) { + msg(sender, "user.transaction.wrong_seller"); + return; + } + } + } double totalPrice = invoice.getTotalPrice(); double tax = invoice.getTax(); if (plugin.eco.enoughMoney(drawee, totalPrice + tax)) { diff --git a/src/main/resources/lang/en_US.yml b/src/main/resources/lang/en_US.yml index 31cd779..5226220 100644 --- a/src/main/resources/lang/en_US.yml +++ b/src/main/resources/lang/en_US.yml @@ -252,8 +252,12 @@ user: message_too_long: ad text max length is %d no_adid: "No such AdsID" transaction: - drafted_seller: Invoice [%d] drafted. You offer {itemName} *{amount} to {buyer} with total price $%.2f (tax $%.2f). - drafted_buyer: Invoice [%d] drafted. {seller} offer {itemName} *{amount} to you with total price $%.2f (tax $%.2f). + drafted_seller: |- + Invoice [%d] drafted. You offer {itemName} *{amount} to {buyer} with total price $%.2f (tax $%.2f). + You can cancel the invoice by {cancelCommand}. + drafted_buyer: |- + Invoice [%d] drafted. {seller} offer {itemName} *{amount} to you with total price $%.2f (tax $%.2f). + You can pay the invoice by {payCommand} or cancel the invoice by {cancelCommand}. max_open_sellside_limit: Maximum open sellside invoices limit %d exceeded. not_found: Invoice not found no_active_buy: You have no active buyside invoice. @@ -286,7 +290,11 @@ user: completed_invoice: |- Invoice [%d] drafted at {createdTime} completed at {updatedTime}. {seller} sold {itemName} *{amount} to {buyer} with total price $%.2f (tax $%.2f) paid by {drawee}. - + command_hover_text: Click to insert command to chatbox + pay_command: /heh transaction pay %d + cancel_command: /heh transaction cancel %d + pay_others: You are paying for others invoice, please add seller's name after invoice ID + wrong_seller: Wrong seller. manual: no_description: No description no_usage: No usage diff --git a/src/main/resources/lang/zh_CN.yml b/src/main/resources/lang/zh_CN.yml index 292edda..e01143e 100644 --- a/src/main/resources/lang/zh_CN.yml +++ b/src/main/resources/lang/zh_CN.yml @@ -238,8 +238,12 @@ user: message_too_long: 广告内容最长为 %d 个字符 no_adid: 找不到指定的 AdsID transaction: - drafted_seller: 账单 [%d] 已起草。你计划以总价 %.2f(税 %.2f)向 {buyer} 出售 {itemName} *{amount}。 - drafted_buyer: 账单 [%d] 已起草。{seller} 计划以总价 %.2f(税 %.2f)向你出售 {itemName} *{amount}。 + drafted_seller: |- + 账单 [%d] 已起草。你计划以总价 %.2f(税 %.2f)向 {buyer} 出售 {itemName} *{amount}。 + 可使用 {cancelCommand} 取消该账单。 + drafted_buyer: |- + 账单 [%d] 已起草。{seller} 计划以总价 %.2f(税 %.2f)向你出售 {itemName} *{amount}。 + 可使用 {payCommand} 支付该账单,{cancelCommand} 取消该账单。 max_open_sellside_limit: 达到最大卖方开放账单 %d 限制。 not_found: 未找到账单 no_active_buy: 你没有活跃的买方账单。 @@ -272,7 +276,11 @@ user: completed_invoice: |- 账单 [%d] 于 {createdTime} 起草并在 {updatedTime} 完成。 {seller} 以总价 %.2f(税 %.2f)向 {buyer} 出售了 {itemName} *{amount},由 {drawee} 支付。 - + command_hover_text: 点击输入命令 + pay_command: /heh transaction pay %d + cancel_command: /heh transaction cancel %d + pay_others: 您正在为其他人支付订单,请在订单号后输入卖家 ID 以确认。 + wrong_seller: 卖家 ID 不正确。 manual: no_description: 无描述 no_usage: 无用法说明 @@ -402,7 +410,7 @@ manual: usage: 用法: /heh transaction sellto [player] [totalPrice] pay: description: 支付账单 - usage: 用法: /heh transaction pay [id] + usage: 用法: /heh transaction pay [id] [seller] cancel: description: 取消账单 usage: 用法: /heh transaction cancel [id]