Skip to content

Commit

Permalink
feat: Add option to set item's display name.
Browse files Browse the repository at this point in the history
  • Loading branch information
blank038 committed Oct 21, 2023
1 parent 692ad5f commit e910f96
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/main/java/com/blank038/servermarket/gui/impl/MarketGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void openGui(Player player) {
break;
}
// 开始设置物品
Optional<SaleCache> saleItemOptional = ServerMarket.getStorageHandler().getSaleItem(sourceMarketKey, keys[i]);
Optional<SaleCache> saleItemOptional = ServerMarket.getStorageHandler().getSaleItem(sourceMarketKey, keys[i]);
if (!saleItemOptional.isPresent()) {
--index;
continue;
Expand Down Expand Up @@ -220,8 +220,13 @@ private String getCurrentTypeDisplayName() {
*/
private ItemStack getShowItem(MarketData marketData, SaleCache saleItem, FileConfiguration data) {
ItemStack itemStack = saleItem.getSaleItem().clone();
ItemMeta itemMeta = itemStack.getItemMeta();
if (data.contains("sale-name")) {
String displayName = itemMeta.hasDisplayName() ? itemMeta.getDisplayName() : itemStack.getType().name(),
finalName = data.getString("sale-name").replace("%name%", displayName);
itemMeta.setDisplayName(TextUtil.formatHexColor(finalName));
}
if (marketData.isShowSaleInfo()) {
ItemMeta itemMeta = itemStack.getItemMeta();
List<String> lore = itemMeta.hasLore() ? itemMeta.getLore() : Lists.newArrayList();
// 设置物品格式
Date date = new Date(saleItem.getPostTime());
Expand All @@ -232,8 +237,9 @@ private ItemStack getShowItem(MarketData marketData, SaleCache saleItem, FileCon
.replace("%price%", String.valueOf(saleItem.getPrice())).replace("%time%", sdf.format(date)));
}
itemMeta.setLore(lore);
itemStack.setItemMeta(itemMeta);
}
itemStack.setItemMeta(itemMeta);
// Add uuid to the sale nbt.
NBTItem nbtItem = new NBTItem(itemStack);
nbtItem.setString("SaleUUID", saleItem.getSaleUUID());
return nbtItem.getItem();
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/market/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ size: 54
# > 数字(小)-数字(大) 例子: 0-44
# > 数字 例子: 0
sale-item-slots: "0-44"
sale-name: "%name%"
# 物品信息
sale-info:
- " "
Expand Down

0 comments on commit e910f96

Please sign in to comment.