Skip to content

Commit

Permalink
fix: Error reading permission value
Browse files Browse the repository at this point in the history
  • Loading branch information
blank038 committed Dec 12, 2023
1 parent 339b8df commit b02d582
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
32 changes: 12 additions & 20 deletions src/main/java/com/blank038/servermarket/api/entity/MarketData.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.blank038.servermarket.internal.i18n.I18n;
import com.blank038.servermarket.internal.util.TextUtil;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
Expand Down Expand Up @@ -46,7 +47,9 @@ public class MarketData {
private final PayType paytype;
private final ConfigurationSection taxSection, shoutTaxSection, limitCountSection;
private MarketStatus marketStatus;
@Setter
private boolean showSaleInfo, saleBroadcast;
@Setter
private String dateFormat;

public MarketData(File file) {
Expand Down Expand Up @@ -121,37 +124,26 @@ public PayType getPayType() {
/**
* 获取玩家在权限节点上的值
*
* @param player 目标玩家
* @param section target section
* @param player target player
* @param compareBig is bigger than
* @return 最终值
*/
public double getPermsValueForPlayer(ConfigurationSection section, Player player) {
public double getPermsValueForPlayer(ConfigurationSection section, Player player, boolean compareBig) {
String header = section.getString("header");
double tax = section.getDouble("node.default");
for (String key : section.getConfigurationSection("node").getKeys(false)) {
double tempTax = section.getDouble("node." + key);
if (player.hasPermission(header + "." + key) && tempTax < tax) {
if (!player.hasPermission(header + "." + key)) {
continue;
}
if ((!compareBig && tempTax < tax) || (compareBig && tempTax > tax)) {
tax = tempTax;
}
}
return tax;
}

public void setShowSaleInfo(boolean show) {
this.showSaleInfo = show;
}

public boolean isSaleBroadcastStatus() {
return saleBroadcast;
}

public void setSaleBroadcastStatus(boolean status) {
this.saleBroadcast = status;
}

public void setDateFormat(String format) {
this.dateFormat = format;
}

public void tryBuySale(Player buyer, String uuid, boolean shift, int page, FilterHandler filter) {
// 判断商品是否存在
if (!ServerMarket.getStorageHandler().hasSale(this.sourceId, uuid)) {
Expand Down Expand Up @@ -190,7 +182,7 @@ public void tryBuySale(Player buyer, String uuid, boolean shift, int page, Filte
BaseEconomy.getEconomyBridge(this.paytype).take(buyer, this.ecoType, saleItem.getPrice());
Player seller = Bukkit.getPlayer(UUID.fromString(saleItem.getOwnerUUID()));
if (seller != null && seller.isOnline()) {
double last = saleItem.getPrice() - saleItem.getPrice() * this.getPermsValueForPlayer(this.getTaxSection(), seller);
double last = saleItem.getPrice() - saleItem.getPrice() * this.getPermsValueForPlayer(this.getTaxSection(), seller, false);
DecimalFormat df = new DecimalFormat("#0.00");
BaseEconomy.getEconomyBridge(this.paytype).give(seller, this.ecoType, last);
seller.sendMessage(I18n.getStrAndHeader("sale-sell")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ private void performSellCommand(Player player, String[] args) {
}
// 判断玩家上架物品是否上限
int currentCount = ServerMarket.getStorageHandler().getSaleCountByPlayer(player.getUniqueId(), this.marketData.getMarketKey());
if (currentCount >= this.marketData.getPermsValueForPlayer(this.marketData.getLimitCountSection(), player)) {
if (currentCount >= this.marketData.getPermsValueForPlayer(this.marketData.getLimitCountSection(), player, true)) {
player.sendMessage(I18n.getStrAndHeader("maximum-sale"));
return;
}
// 判断余额是否足够交上架税
double tax = this.marketData.getPermsValueForPlayer(this.marketData.getShoutTaxSection(), player);
double tax = this.marketData.getPermsValueForPlayer(this.marketData.getShoutTaxSection(), player, false);
if (BaseEconomy.getEconomyBridge(this.marketData.getPayType()).balance(player, this.marketData.getEcoType()) < tax) {
player.sendMessage(I18n.getStrAndHeader("shout-tax")
.replace("%economy%", this.marketData.getEconomyName()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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;
Expand Down Expand Up @@ -31,10 +32,13 @@
* @author Blank038
*/
public class MarketGui extends AbstractGui {
private static final ExecuteInterface CLICK_FUNC = (e) -> {

};
private final String sourceMarketKey;
private FilterHandler filter;
private int currentPage;
private String currentType = "all";
private String currentType = "all", currentSort = "none";

public MarketGui(String sourceMarketKey, int currentPage, FilterHandler filter) {
this.sourceMarketKey = sourceMarketKey;
Expand Down Expand Up @@ -195,7 +199,9 @@ private void initializeDisplayItem(GuiModel model, FileConfiguration data) {
itemMeta.setDisplayName(TextUtil.formatHexColor(section.getString("name")));
// 开始遍历设置Lore
List<String> list = new ArrayList<>(section.getStringList("lore"));
list.replaceAll((s) -> TextUtil.formatHexColor(s).replace("%saleType%", this.getCurrentTypeDisplayName()));
list.replaceAll((s) -> TextUtil.formatHexColor(s)
.replace("%saleType%", this.getCurrentTypeDisplayName())
.replace("%sortType%", this.getCurrentSortDisplayName()));
itemMeta.setLore(list);
itemStack.setItemMeta(itemMeta);
// 开始判断是否有交互操作
Expand All @@ -215,6 +221,10 @@ private String getCurrentTypeDisplayName() {
return DataContainer.SALE_TYPE_DISPLAY_NAME.getOrDefault(this.currentType, this.currentType);
}

private String getCurrentSortDisplayName() {
return DataContainer.SALE_TYPE_DISPLAY_NAME.getOrDefault(this.currentSort, this.currentSort);
}

/**
* 获得市场展示物品
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private synchronized void checkResult(Player player) {
// 获取市场数据
MarketData marketData = DataContainer.MARKET_DATA.getOrDefault(v.getSourceMarket(), null);
// 获取可获得货币
double price = v.getAmount(), last = marketData == null ? price : (price - price * marketData.getPermsValueForPlayer(marketData.getTaxSection(), player));
double price = v.getAmount(), last = marketData == null ? price : (price - price * marketData.getPermsValueForPlayer(marketData.getTaxSection(), player, false));
// 判断货币桥是否存在
if (BaseEconomy.PAY_TYPES.containsKey(v.getPayType())) {
DecimalFormat df = new DecimalFormat("#0.00");
Expand Down

0 comments on commit b02d582

Please sign in to comment.