Skip to content

Commit

Permalink
build(1.2.2-SNAPSHOT): 增加关键字独立价格范围, 修复物品无元数据分类异常
Browse files Browse the repository at this point in the history
  • Loading branch information
blank038 committed Nov 8, 2022
1 parent 9f9b837 commit 0c6e009
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group 'com.blank038.servermarket'
version '1.2.1-SNAPSHOT'
version '1.2.2-SNAPSHOT'
archivesBaseName = "ServerMarket"

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.blank038.servermarket.api.event.MarketLoadEvent;
import com.blank038.servermarket.bridge.BaseBridge;
import com.blank038.servermarket.filter.FilterBuilder;
import com.blank038.servermarket.filter.impl.KeyFilterImpl;
import com.blank038.servermarket.gui.MarketGui;
import com.blank038.servermarket.i18n.I18n;
import com.blank038.servermarket.data.sale.SaleItem;
Expand Down Expand Up @@ -35,7 +36,8 @@ public class MarketData {
/**
* 商品列表
*/
private final HashMap<String, SaleItem> saleMap = new HashMap<>();
private final Map<String, SaleItem> saleMap = new HashMap<>();
private final Map<String, String> extraMap = new HashMap<>();
private final String sourceId, marketKey, permission, shortCommand, ecoType, displayName, economyName;
private final List<String> loreBlackList, typeBlackList, saleTypes;
private final int min, max, effectiveTime;
Expand All @@ -56,6 +58,11 @@ public MarketData(File file) {
this.economyName = ChatColor.translateAlternateColorCodes('&', data.getString("economy-name"));
this.min = data.getInt("price.min");
this.max = data.getInt("price.max");
if (data.contains("extra-price")) {
for (String key : data.getConfigurationSection("extra-price").getKeys(false)) {
this.extraMap.put(key, data.getString("extra-price." + key));
}
}
this.effectiveTime = data.getInt("effective_time");
this.typeBlackList = data.getStringList("black-list.type");
this.loreBlackList = data.getStringList("black-list.lore");
Expand Down Expand Up @@ -99,7 +106,7 @@ public File getSourceFile() {
return this.sourceFile;
}

public HashMap<String, SaleItem> getSales() {
public Map<String, SaleItem> getSales() {
return saleMap;
}

Expand Down Expand Up @@ -305,7 +312,7 @@ public void buySaleItem(Player buyer, String uuid, boolean shift, int page, Filt
*
* @param player 命令执行者
* @param message 命令
* @return 执行结果
* @return 执行结果, 为 true 时取消事件
*/
public boolean performSellCommand(Player player, String message) {
String[] split = message.split(" ");
Expand All @@ -330,16 +337,16 @@ public boolean performSellCommand(Player player, String message) {
player.sendMessage(I18n.getString("hand-air", true));
return true;
}
boolean has = false;
boolean denied = false;
if (itemStack.hasItemMeta() && itemStack.getItemMeta().hasLore()) {
for (String l : itemStack.getItemMeta().getLore()) {
if (loreBlackList.contains(l.replace("§", "&"))) {
has = true;
denied = true;
break;
}
}
}
if (typeBlackList.contains(itemStack.getType().name()) || has) {
if (typeBlackList.contains(itemStack.getType().name()) || denied) {
player.sendMessage(I18n.getString("deny-item", true));
return true;
}
Expand All @@ -358,6 +365,19 @@ public boolean performSellCommand(Player player, String message) {
player.sendMessage(I18n.getString("max-price", true).replace("%max%", String.valueOf(this.max)));
return true;
}
String extraPrice = this.extraMap.entrySet().stream()
.filter((s) -> new FilterBuilder().addKeyFilter(new KeyFilterImpl(s.getKey())).check(itemStack))
.findFirst()
.map(Map.Entry::getValue)
.orElse(null);
if (extraPrice != null && price < Integer.parseInt(extraPrice.split("-")[0])) {
player.sendMessage(I18n.getString("min-price", true).replace("%min%", extraPrice.split("-")[0]));
return true;
}
if (extraPrice != null && price > Integer.parseInt(extraPrice.split("-")[1])) {
player.sendMessage(I18n.getString("max-price", true).replace("%max%", extraPrice.split("-")[1]));
return true;
}
double tax = this.getTax(this.getShoutTaxSection(), player);
if (ServerMarket.getInstance().getEconomyBridge(this.paytype).balance(player, this.ecoType) < tax) {
player.sendMessage(I18n.getString("shout-tax", true).replace("%economy%", this.economyName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.blank038.servermarket.data.sale.SaleItem;
import com.blank038.servermarket.filter.impl.TypeFilterImpl;
import com.blank038.servermarket.filter.interfaces.ISaleFilter;
import org.bukkit.inventory.ItemStack;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -34,4 +35,8 @@ public boolean check(SaleItem saleItem) {
}
return this.saleFilters.stream().anyMatch((saleFilter) -> saleFilter.check(saleItem));
}

public boolean check(ItemStack itemStack) {
return this.saleFilters.stream().anyMatch((saleFilter) -> saleFilter.check(itemStack));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,21 @@ public KeyFilterImpl(List<String> keys) {

@Override
public boolean check(SaleItem saleItem) {
ItemStack itemStack = saleItem.getSafeItem();
if (itemStack == null || !itemStack.hasItemMeta()) {
return this.check(saleItem.getSafeItem());
}

@Override
public boolean check(ItemStack itemStack) {
if (itemStack == null) {
return false;
}
return Arrays.stream(keys).anyMatch((s) -> {
if (itemStack.getType().name().toLowerCase().contains(s.toLowerCase())) {
return true;
}
if (!itemStack.hasItemMeta()) {
return false;
}
if (itemStack.getItemMeta().hasDisplayName() && itemStack.getItemMeta().getDisplayName().toLowerCase().contains(s.toLowerCase())) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.blank038.servermarket.data.sale.SaleItem;
import com.blank038.servermarket.filter.interfaces.ISaleFilter;
import org.bukkit.inventory.ItemStack;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -30,4 +31,9 @@ public boolean check(SaleItem saleItem) {
}
return this.types.stream().anyMatch((s) -> saleItem.getSaleTypes().contains(s));
}

@Override
public boolean check(ItemStack itemStack) {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.blank038.servermarket.filter.interfaces;

import com.blank038.servermarket.data.sale.SaleItem;
import org.bukkit.inventory.ItemStack;

public interface ISaleFilter {

boolean check(SaleItem saleItem);

boolean check(ItemStack itemStack);
}
1 change: 0 additions & 1 deletion src/main/java/com/blank038/servermarket/gui/MarketGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
* @author Blank038
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/market/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ economy-name: "金币"
price:
min: 1
max: 2000000
# 特定物品价格设定(判断: 物品类型、物品昵称、物品描述)
extra-price:
DIAMOND: 1000-10000
"道具": 20000-30000
# 上架物品是否公告
sale-broadcast: true
# 是否开启商品额外信息
Expand Down

0 comments on commit 0c6e009

Please sign in to comment.