diff --git a/bukkit/src/main/java/com/blank038/servermarket/internal/command/virtual/VirtualMarketCommand.java b/bukkit/src/main/java/com/blank038/servermarket/internal/command/virtual/VirtualMarketCommand.java index a056624..98c7b85 100644 --- a/bukkit/src/main/java/com/blank038/servermarket/internal/command/virtual/VirtualMarketCommand.java +++ b/bukkit/src/main/java/com/blank038/servermarket/internal/command/virtual/VirtualMarketCommand.java @@ -20,6 +20,8 @@ import java.util.Map; import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import java.util.logging.Level; /** * @author Blank038 @@ -117,27 +119,39 @@ private void performSellCommand(Player player, String[] args) { } // send taxes ServerMarketApi.sendTaxes(this.marketData.getPaymentType(), this.marketData.getEconomyType(), tax); - // 设置玩家手中物品为空 player.getInventory().setItemInMainHand(null); - // 上架物品 + // initial SaleCache SaleCache saleItem = new SaleCache(UUID.randomUUID().toString(), this.marketData.getMarketKey(), player.getUniqueId().toString(), player.getName(), cloneItem, PayType.VAULT, this.marketData.getEconomyType(), price, System.currentTimeMillis()); - // add sale to storage handler - ServerMarket.getStorageHandler().addSale(this.marketData.getMarketKey(), saleItem); - // call PlayerSaleEvent.Sell - PlayerSaleEvent.Sell event = new PlayerSaleEvent.Sell(player, this.marketData, saleItem); - Bukkit.getPluginManager().callEvent(event); + CompletableFuture future = CompletableFuture.supplyAsync(() -> { + // add sale to storage handler + return ServerMarket.getStorageHandler().addSale(this.marketData.getMarketKey(), saleItem); + }); + future.thenAccept((result) -> { + if (result) { + // call PlayerSaleEvent.Sell + PlayerSaleEvent.Sell event = new PlayerSaleEvent.Sell(player, this.marketData, saleItem); + Bukkit.getPluginManager().callEvent(event); - player.sendMessage(I18n.getStrAndHeader("sell")); - // 判断是否公告 - if (this.marketData.isSaleBroadcast()) { - String displayName = cloneItem.hasItemMeta() && cloneItem.getItemMeta().hasDisplayName() ? - cloneItem.getItemMeta().getDisplayName() : cloneItem.getType().name(); - Bukkit.getServer().broadcastMessage(I18n.getStrAndHeader("broadcast") - .replace("%item%", displayName) - .replace("%market_name%", this.marketData.getDisplayName()) - .replace("%amount%", String.valueOf(cloneItem.getAmount())) - .replace("%player%", player.getName())); - } + player.sendMessage(I18n.getStrAndHeader("sell")); + // 判断是否公告 + if (this.marketData.isSaleBroadcast()) { + String displayName = cloneItem.hasItemMeta() && cloneItem.getItemMeta().hasDisplayName() ? + cloneItem.getItemMeta().getDisplayName() : cloneItem.getType().name(); + Bukkit.getServer().broadcastMessage(I18n.getStrAndHeader("broadcast") + .replace("%item%", displayName) + .replace("%market_name%", this.marketData.getDisplayName()) + .replace("%amount%", String.valueOf(cloneItem.getAmount())) + .replace("%player%", player.getName())); + } + } else { + player.sendMessage(I18n.getStrAndHeader("sale-denied")); + } + }); + future.exceptionally((e) -> { + ServerMarket.getInstance().getLogger().log(Level.WARNING, e, () -> "Please contact the author at https://github.com/blank038/ServerMarket/issues"); + player.sendMessage(I18n.getStrAndHeader("sale-failed")); + return false; + }); } } diff --git a/bukkit/src/main/resources/language/en_US.yml b/bukkit/src/main/resources/language/en_US.yml index 8a7c2d9..b3863bc 100644 --- a/bukkit/src/main/resources/language/en_US.yml +++ b/bukkit/src/main/resources/language/en_US.yml @@ -33,11 +33,13 @@ min-price: "The price must be greater than %min%." max-price: "The price cannot exceed %max%." hand-air: "Please hold an item in your hand." deny-item: "This item is not allowed to be listed." +sale-denied: "Item listing was denied. Please contact the server owner." +sale-failed: "An error occurred while listing the item for sale. Please contact the admin." sell: "Item successfully listed." broadcast: "%player% listed item &e%item% &fx&e%amount% &f(%market_name%&f)." shift-unsale: "Hold Shift and click to delist the item." inventory-full: "Your inventory is full. Unable to retrieve the item." -unsale: "Successfully delisted item." +unsale: "Successfully delisted item. Please go to the storage box to retrieve it." is-owner: "You cannot purchase your own items." shift-buy: "Hold Shift and click to purchase the item." buy-item: "Successfully purchased the item. Please go to the storage box to retrieve it." diff --git a/bukkit/src/main/resources/language/zh_CN.yml b/bukkit/src/main/resources/language/zh_CN.yml index 60c9a4c..008c478 100644 --- a/bukkit/src/main/resources/language/zh_CN.yml +++ b/bukkit/src/main/resources/language/zh_CN.yml @@ -33,6 +33,8 @@ min-price: "价格必须大于%min%." max-price: "价格不能超过%max%." hand-air: "请手持一个物品." deny-item: "该物品不允许上架." +sale-denied: "商品上架被拒绝, 请联系服主." +sale-failed: "上架商品出现错误, 请联系管理员." sell: "成功上架该物品." broadcast: "玩家 %player% 上架了物品 &e%item% &fx &e%amount% &f(%market_name%&f)." shift-unsale: "按住 Shift 点击即可下架物品."