Skip to content

Commit

Permalink
修复了在某些情况下没有经济插件也能创建领地的可能
Browse files Browse the repository at this point in the history
  • Loading branch information
ColdeZhang committed Jul 18, 2024
1 parent 1297f0c commit fe75a3c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>cn.lunadeer</groupId>
<artifactId>Dominion</artifactId>
<version>1.38.1-beta</version>
<version>1.38.2-beta</version>
<packaging>jar</packaging>

<name>Dominion</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,11 @@ public static void create(AbstractOperator operator, String name,
}
}
// 检查经济
if (!skipEco)
handleEconomy(operator, Dominion.config.getEconomyOnlyXZ() ? dominion.getSquare() : dominion.getVolume(), true, FAIL, SUCCESS);
if (!skipEco) {
if (handleEconomyFailed(operator, Dominion.config.getEconomyOnlyXZ() ? dominion.getSquare() : dominion.getVolume(), true, FAIL, SUCCESS)) {
return;
}
}
dominion = DominionDTO.insert(dominion);
if (dominion == null) {
operator.setResponse(FAIL.addMessage("创建领地失败,数据库错误,请联系管理员"));
Expand Down Expand Up @@ -231,8 +234,8 @@ public static void expand(AbstractOperator operator, Integer size, String domini
}
AbstractOperator.Result SUCCESS = new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "成功扩展领地 %s %d格", dominion_name, size);
// 检查经济
handleEconomy(operator, Dominion.config.getEconomyOnlyXZ() ? sqr(newCords) - dominion.getSquare() : vol(newCords) - dominion.getVolume()
, true, FAIL, SUCCESS);
if (handleEconomyFailed(operator, Dominion.config.getEconomyOnlyXZ() ? sqr(newCords) - dominion.getSquare() : vol(newCords) - dominion.getVolume()
, true, FAIL, SUCCESS)) return;
// 显示粒子效果
dominion = dominion.setXYZ(newCords);
handleParticle(operator, dominion);
Expand Down Expand Up @@ -283,8 +286,8 @@ public static void contract(AbstractOperator operator, Integer size, String domi
}
AbstractOperator.Result SUCCESS = new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "成功缩小领地 %s %d格", dominion_name, size);
// 退还经济
handleEconomy(operator, Dominion.config.getEconomyOnlyXZ() ? dominion.getSquare() - sqr(newCords) : dominion.getVolume() - vol(newCords)
, false, FAIL, SUCCESS);
if (handleEconomyFailed(operator, Dominion.config.getEconomyOnlyXZ() ? dominion.getSquare() - sqr(newCords) : dominion.getVolume() - vol(newCords)
, false, FAIL, SUCCESS)) return;
// 显示粒子效果
dominion = dominion.setXYZ(newCords);
handleParticle(operator, dominion);
Expand Down Expand Up @@ -343,7 +346,7 @@ public static void delete(AbstractOperator operator, String dominion_name, boole
count += sub_dominion.getVolume();
}
}
handleEconomy(operator, count, false, FAIL, SUCCESS);
if (handleEconomyFailed(operator, count, false, FAIL, SUCCESS)) return;
operator.setResponse(SUCCESS);
}

Expand Down Expand Up @@ -756,17 +759,17 @@ private static DominionDTO getExistDomAndIsOwner(AbstractOperator operator, Stri
* @param FAIL 失败消息
* @param SUCCESS 成功消息
*/
private static void handleEconomy(AbstractOperator operator, Integer count, boolean paid, AbstractOperator.Result FAIL, AbstractOperator.Result SUCCESS) {
private static boolean handleEconomyFailed(AbstractOperator operator, Integer count, boolean paid, AbstractOperator.Result FAIL, AbstractOperator.Result SUCCESS) {
if (Dominion.config.getEconomyEnable()) {
if (!VaultConnect.instance.economyAvailable()) {
operator.setResponse(FAIL.addMessage("没有可用的经济插件系统,请联系服主。"));
return;
return true;
}
float priceOrRefund = count * Dominion.config.getEconomyPrice();
if (paid) {
if (VaultConnect.instance.getBalance(operator.getPlayer()) < priceOrRefund) {
operator.setResponse(FAIL.addMessage("你的余额不足,需要 %.2f %s", priceOrRefund, VaultConnect.instance.currencyNamePlural()));
return;
return true;
}
SUCCESS.addMessage("已扣除 %.2f %s", priceOrRefund, VaultConnect.instance.currencyNamePlural());
VaultConnect.instance.withdrawPlayer(operator.getPlayer(), priceOrRefund);
Expand All @@ -776,6 +779,7 @@ private static void handleEconomy(AbstractOperator operator, Integer count, bool
SUCCESS.addMessage("已退还 %.2f %s", refund, VaultConnect.instance.currencyNamePlural());
}
}
return false;
}

/**
Expand Down

0 comments on commit fe75a3c

Please sign in to comment.