Skip to content

Commit

Permalink
Allow setting a default plot price of -1 (#7313)
Browse files Browse the repository at this point in the history
* Allow setting a default plot price of -1

* -1 -1 -1

* Undo changed default plot type price
  • Loading branch information
Warriorrrr authored May 6, 2024
1 parent 18d3c52 commit 01d864b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ public void parsePlotForSale(Player player, String[] split, Resident resident, T
if (town == null) //Shouldn't be able to happen but check anyways.
throw new TownyException(Translatable.of("msg_err_empty_area_selection"));

double plotPrice = town.getPlotTypePrice(townBlock.getType());
double plotPrice = Math.max(town.getPlotTypePrice(townBlock.getType()), 0);

if (split.length == 0) {
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2086,9 +2086,8 @@ public static void townSetPlotPrice(CommandSender sender, String[] split, boolea
checkPermOrThrow(sender, PermissionNodes.TOWNY_COMMAND_TOWN_SET_PLOTPRICE.getNode());
if (split.length == 0)
throw new TownyException("Eg: /town set plotprice 50");

double amount = MathUtil.getDoubleOrThrow(split[0]);
if (amount < 0)
throw new TownyException(Translatable.of("msg_err_negative_money"));

town.setPlotPrice(amount);
town.save();
Expand All @@ -2101,9 +2100,8 @@ public static void townSetShopPrice(CommandSender sender, String[] split, boolea
checkPermOrThrow(sender, PermissionNodes.TOWNY_COMMAND_TOWN_SET_SHOPPRICE.getNode());
if (split.length == 0)
throw new TownyException("Eg: /town set shopprice 50");

double amount = MathUtil.getDoubleOrThrow(split[0]);
if (amount < 0)
throw new TownyException(Translatable.of("msg_err_negative_money"));

town.setCommercialPlotPrice(amount);
town.save();
Expand All @@ -2116,9 +2114,8 @@ public static void townSetEmbassyPrice(CommandSender sender, String[] split, boo
checkPermOrThrow(sender, PermissionNodes.TOWNY_COMMAND_TOWN_SET_EMBASSYPRICE.getNode());
if (split.length == 0)
throw new TownyException("Eg: /town set embassyprice 50");

double amount = MathUtil.getDoubleOrThrow(split[0]);
if (amount < 0)
throw new TownyException(Translatable.of("msg_err_negative_money"));

town.setEmbassyPlotPrice(amount);
town.save();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,9 @@ public final double getForSalePrice() {
}

public void setPlotPrice(double plotPrice) {
if (plotPrice < 0)
plotPrice = -1;

this.plotPrice = Math.min(plotPrice, TownySettings.getMaxPlotPrice());
}

Expand All @@ -1114,6 +1117,9 @@ public double getPlotTypePrice(TownBlockType type) {
}

public void setCommercialPlotPrice(double commercialPlotPrice) {
if (commercialPlotPrice < 0)
commercialPlotPrice = -1;

this.commercialPlotPrice = Math.min(commercialPlotPrice, TownySettings.getMaxPlotPrice());
}

Expand All @@ -1123,6 +1129,9 @@ public double getCommercialPlotPrice() {
}

public void setEmbassyPlotPrice(double embassyPlotPrice) {
if (embassyPlotPrice < 0)
embassyPlotPrice = -1;

this.embassyPlotPrice = Math.min(embassyPlotPrice, TownySettings.getMaxPlotPrice());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,16 @@ public boolean isOwner(@NotNull TownBlockOwner owner) {

public void setPlotPrice(double price) {
if (this.town != null) {
if (isForSale() && price == -1.0)
if (isForSale() && price < 0)
// Plot is no longer for sale.
this.town.getTownBlockTypeCache().removeTownBlockOfTypeForSale(this);
else if (!isForSale() && price > -1.0)
else if (!isForSale() && price >= 0)
// Plot is being put up for sale.
this.town.getTownBlockTypeCache().addTownBlockOfTypeForSale(this);
}

if (price < 0)
price = -1;

this.plotPrice = price;
}
Expand All @@ -242,7 +245,7 @@ public double getPlotPrice() {

public boolean isForSale() {

return getPlotPrice() != -1.0;
return getPlotPrice() >= 0.0;
}

public boolean isTaxed() {
Expand Down

0 comments on commit 01d864b

Please sign in to comment.