Skip to content

Commit

Permalink
feat: allow bypass of econ costs (#4126)
Browse files Browse the repository at this point in the history
  • Loading branch information
dordsor21 authored Aug 2, 2023
1 parent 49e1338 commit 0d63c2b
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Core/src/main/java/com/plotsquared/core/command/Auto.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public boolean onCommand(final PlotPlayer<?> player, String[] args) {
return true;
}
}
if (this.econHandler != null && plotarea.useEconomy()) {
if (this.econHandler != null && plotarea.useEconomy() && !player.hasPermission(Permission.PERMISSION_ADMIN_BYPASS_ECON)) {
PlotExpression costExp = plotarea.getPrices().get("claim");
PlotExpression mergeCostExp = plotarea.getPrices().get("merge");
int size = sizeX * sizeZ;
Expand Down
2 changes: 1 addition & 1 deletion Core/src/main/java/com/plotsquared/core/command/Claim.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public boolean onCommand(final PlotPlayer<?> player, String[] args) {
}
}
}
if (this.econHandler.isEnabled(area) && !force) {
if (this.econHandler.isEnabled(area) && !force && !player.hasPermission(Permission.PERMISSION_ADMIN_BYPASS_ECON)) {
PlotExpression costExr = area.getPrices().get("claim");
double cost = costExr.evaluate(currentPlots);
if (cost > 0d) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public void run(final Command cmd, final Runnable success, final Runnable failur
if (cmd.hasConfirmation(player)) {
CmdConfirm.addPending(player, cmd.getUsage(), () -> {
PlotArea area = player.getApplicablePlotArea();
if (area != null && econHandler.isEnabled(area)) {
if (area != null && econHandler.isEnabled(area) && !player.hasPermission(Permission.PERMISSION_ADMIN_BYPASS_ECON)) {
PlotExpression priceEval =
area.getPrices().get(cmd.getFullId());
double price = priceEval != null ? priceEval.evaluate(0d) : 0d;
Expand All @@ -201,7 +201,7 @@ public void run(final Command cmd, final Runnable success, final Runnable failur
return;
}
PlotArea area = player.getApplicablePlotArea();
if (area != null && econHandler.isEnabled(area)) {
if (area != null && econHandler.isEnabled(area) && !player.hasPermission(Permission.PERMISSION_ADMIN_BYPASS_ECON)) {
PlotExpression priceEval = area.getPrices().get(cmd.getFullId());
double price = priceEval != null ? priceEval.evaluate(0d) : 0d;
if (price != 0d && econHandler.getMoney(player) < price) {
Expand Down
12 changes: 6 additions & 6 deletions Core/src/main/java/com/plotsquared/core/command/Merge.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public boolean onCommand(final PlotPlayer<?> player, String[] args) {
return true;
}
if (plot.getPlotModificationManager().autoMerge(Direction.ALL, maxSize, uuid, player, terrain)) {
if (this.econHandler.isEnabled(plotArea) && price > 0d) {
if (this.econHandler.isEnabled(plotArea) && !player.hasPermission(Permission.PERMISSION_ADMIN_BYPASS_ECON) && price > 0d) {
this.econHandler.withdrawMoney(player, price);
player.sendMessage(
TranslatableCaption.of("economy.removed_balance"),
Expand All @@ -196,8 +196,8 @@ public boolean onCommand(final PlotPlayer<?> player, String[] args) {
player.sendMessage(TranslatableCaption.of("merge.no_available_automerge"));
return false;
}
if (!force && this.econHandler.isEnabled(plotArea) && price > 0d
&& this.econHandler.getMoney(player) < price) {
if (!force && this.econHandler.isEnabled(plotArea) && !player.hasPermission(Permission.PERMISSION_ADMIN_BYPASS_ECON) && price > 0d && this.econHandler.getMoney(
player) < price) {
player.sendMessage(
TranslatableCaption.of("economy.cannot_afford_merge"),
TagResolver.resolver("money", Tag.inserting(Component.text(this.econHandler.format(price))))
Expand All @@ -218,7 +218,7 @@ public boolean onCommand(final PlotPlayer<?> player, String[] args) {
return true;
}
if (plot.getPlotModificationManager().autoMerge(direction, maxSize - size, uuid, player, terrain)) {
if (this.econHandler.isEnabled(plotArea) && price > 0d) {
if (this.econHandler.isEnabled(plotArea) && !player.hasPermission(Permission.PERMISSION_ADMIN_BYPASS_ECON) && price > 0d) {
this.econHandler.withdrawMoney(player, price);
player.sendMessage(
TranslatableCaption.of("economy.removed_balance"),
Expand Down Expand Up @@ -259,7 +259,7 @@ public boolean onCommand(final PlotPlayer<?> player, String[] args) {
accepter.sendMessage(TranslatableCaption.of("merge.merge_not_valid"));
return;
}
if (this.econHandler.isEnabled(plotArea) && price > 0d) {
if (this.econHandler.isEnabled(plotArea) && !player.hasPermission(Permission.PERMISSION_ADMIN_BYPASS_ECON) && price > 0d) {
if (!force && this.econHandler.getMoney(player) < price) {
player.sendMessage(
TranslatableCaption.of("economy.cannot_afford_merge"),
Expand Down Expand Up @@ -303,7 +303,7 @@ public boolean onCommand(final PlotPlayer<?> player, String[] args) {
player,
terrain
)) {
if (this.econHandler.isEnabled(plotArea) && price > 0d) {
if (this.econHandler.isEnabled(plotArea) && !player.hasPermission(Permission.PERMISSION_ADMIN_BYPASS_ECON) && price > 0d) {
if (!force && this.econHandler.getMoney(player) < price) {
player.sendMessage(
TranslatableCaption.of("economy.cannot_afford_merge"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public boolean onClick(final int index) {
return false;
}

if (componentPreset.cost() > 0.0D) {
if (componentPreset.cost() > 0.0D && !player.hasPermission(Permission.PERMISSION_ADMIN_BYPASS_ECON)) {
if (!econHandler.isEnabled(plot.getArea())) {
getPlayer().sendMessage(
TranslatableCaption.of("preset.economy_disabled"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ public enum Permission implements ComponentLike {
PERMISSION_RATE("plots.rate"),
PERMISSION_ADMIN_FLIGHT("plots.admin.flight"),
PERMISSION_ADMIN_COMPONENTS_OTHER("plots.admin.component.other"),
PERMISSION_ADMIN_BYPASS_BORDER("plots.admin.border.bypass");
PERMISSION_ADMIN_BYPASS_BORDER("plots.admin.border.bypass"),
PERMISSION_ADMIN_BYPASS_ECON("plots.admin.econ.bypass");
//</editor-fold>

private final String text;
Expand Down

0 comments on commit 0d63c2b

Please sign in to comment.