Skip to content

Commit

Permalink
修复在Essentials管控经济的前提下扣款无效的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
0XPYEX0 committed Mar 23, 2022
1 parent e4f1cf0 commit 26279d3
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import me.xpyex.plugin.flywithfood.common.implementations.FWFUser;
import me.xpyex.plugin.flywithfood.common.implementations.flyenergy.EnergyManager;
import me.xpyex.plugin.flywithfood.common.implementations.flyenergy.energys.MoneyEnergy;
import org.bukkit.Bukkit;
import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

Expand All @@ -16,11 +16,17 @@ public class BukkitMoney implements MoneyEnergy {

@Override
public void cost(@NotNull FWFUser user, @NotNull Number value) {
if (value.doubleValue() == 0) { //+-0没有变化
return;
}
if (FlyWithFood.ECON != null) {
Player target = (Player) user.getPlayer();
Bukkit.getScheduler().runTask(FlyWithFood.INSTANCE, () ->
FlyWithFood.ECON.depositPlayer(target, -value.doubleValue()) //才发现这玩意叫存款,,我还以为是设置金额
); //看看同步执行能不能修好那个奇怪的Bug
EconomyResponse result = value.doubleValue() > 0 ?
FlyWithFood.ECON.withdrawPlayer(target, value.doubleValue()) : //Ess不允许存入负数的钱款
FlyWithFood.ECON.depositPlayer(target, -value.doubleValue()); //存款
if (!result.transactionSuccess()) {
FlyWithFood.LOGGER.severe("处理玩家 " + target.getName() + " 的游戏币时出现错误: " + result.errorMessage);
}
}
}

Expand Down

0 comments on commit 26279d3

Please sign in to comment.