From 3647d5b2bfced1cdf5c692e39cdabeeb1ddbd62f Mon Sep 17 00:00:00 2001 From: Blank038 Date: Thu, 14 Dec 2023 21:11:47 +0800 Subject: [PATCH] feat: Add option to format the item price --- .../com/blank038/servermarket/api/entity/MarketData.java | 3 ++- .../servermarket/internal/gui/impl/MarketGui.java | 3 +-- src/main/resources/market/example.yml | 8 +++++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/blank038/servermarket/api/entity/MarketData.java b/src/main/java/com/blank038/servermarket/api/entity/MarketData.java index 222807d..bc4b3ae 100644 --- a/src/main/java/com/blank038/servermarket/api/entity/MarketData.java +++ b/src/main/java/com/blank038/servermarket/api/entity/MarketData.java @@ -50,7 +50,7 @@ public class MarketData { @Setter private boolean showSaleInfo, saleBroadcast; @Setter - private String dateFormat; + private String dateFormat, priceFormat; public MarketData(File file) { FileConfiguration options = YamlConfiguration.loadConfiguration(file); @@ -79,6 +79,7 @@ public MarketData(File file) { this.showSaleInfo = options.getBoolean("show-sale-info"); this.saleBroadcast = options.getBoolean("sale-broadcast"); this.dateFormat = options.getString("simple-date-format"); + this.priceFormat = options.getString("price-format", "%.1f"); switch ((this.ecoType = options.getString("vault-type").toLowerCase())) { case "vault": this.paytype = PayType.VAULT; diff --git a/src/main/java/com/blank038/servermarket/internal/gui/impl/MarketGui.java b/src/main/java/com/blank038/servermarket/internal/gui/impl/MarketGui.java index 841cd0c..8e27a31 100644 --- a/src/main/java/com/blank038/servermarket/internal/gui/impl/MarketGui.java +++ b/src/main/java/com/blank038/servermarket/internal/gui/impl/MarketGui.java @@ -1,7 +1,6 @@ package com.blank038.servermarket.internal.gui.impl; import com.aystudio.core.bukkit.util.common.CommonUtil; -import com.aystudio.core.bukkit.util.inventory.ExecuteInterface; import com.aystudio.core.bukkit.util.inventory.GuiModel; import com.blank038.servermarket.internal.plugin.ServerMarket; import com.blank038.servermarket.internal.data.DataContainer; @@ -260,7 +259,7 @@ private ItemStack getShowItem(MarketData marketData, SaleCache saleItem, FileCon for (String i : data.getStringList("sale-info")) { lore.add(TextUtil.formatHexColor(i) .replace("%seller%", saleItem.getOwnerName()) - .replace("%price%", String.valueOf(saleItem.getPrice())) + .replace("%price%", String.format(marketData.getPriceFormat(), saleItem.getPrice())) .replace("%time%", sdf.format(date)) .replace("%name%", displayName)); } diff --git a/src/main/resources/market/example.yml b/src/main/resources/market/example.yml index a33f660..6c81813 100644 --- a/src/main/resources/market/example.yml +++ b/src/main/resources/market/example.yml @@ -53,6 +53,8 @@ limit-count: vip: 10 # 日期格式 simple-date-format: "yyyy/MM/dd HH:mm:ss" +# 价格格式 +price-format: "%,.0f" # 商品超时时间, 单位: 秒 effective_time: 259200 # 物品上架黑名单 @@ -67,7 +69,7 @@ types: - "道具" ###################### # -# 全球市场界面配置文件 +# 全球市场界面配置文件 # ###################### # 界面标题 @@ -76,8 +78,8 @@ title: "&8全球市场面板" size: 54 # 显示商品的槽位 # 支持格式: -# > 数字(小)-数字(大) 例子: 0-44 -# > 数字 例子: 0 +# - 数字(小)-数字(大) 例子: 0-44 +# - 数字 例子: 0 sale-item-slots: "0-44" sale-name: "%name%" # 物品信息