Skip to content

Commit

Permalink
Allow setting a default plot price of -1
Browse files Browse the repository at this point in the history
  • Loading branch information
Warriorrrr committed Mar 16, 2024
1 parent 359113f commit fae5a7a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,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 @@ -2063,9 +2063,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 @@ -2078,9 +2077,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 @@ -2093,9 +2091,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 @@ -1078,7 +1078,7 @@ public final double getForSalePrice() {
}

public void setPlotPrice(double plotPrice) {
this.plotPrice = Math.min(plotPrice, TownySettings.getMaxPlotPrice());
this.plotPrice = Math.min(Math.max(plotPrice, -1), TownySettings.getMaxPlotPrice());
}

public double getPlotPrice() {
Expand All @@ -1092,11 +1092,11 @@ public double getPlotTypePrice(TownBlockType type) {
default -> getPlotPrice();
};

return Math.max(plotPrice, 0);
return Math.max(plotPrice, -1);
}

public void setCommercialPlotPrice(double commercialPlotPrice) {
this.commercialPlotPrice = Math.min(commercialPlotPrice, TownySettings.getMaxPlotPrice());
this.commercialPlotPrice = Math.min(Math.max(commercialPlotPrice, -1), TownySettings.getMaxPlotPrice());
}

public double getCommercialPlotPrice() {
Expand All @@ -1105,7 +1105,7 @@ public double getCommercialPlotPrice() {
}

public void setEmbassyPlotPrice(double embassyPlotPrice) {
this.embassyPlotPrice = Math.min(embassyPlotPrice, TownySettings.getMaxPlotPrice());
this.embassyPlotPrice = Math.min(Math.max(embassyPlotPrice, -1), TownySettings.getMaxPlotPrice());
}

public double getEmbassyPlotPrice() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,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 @@ -237,7 +240,7 @@ public double getPlotPrice() {

public boolean isForSale() {

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

public boolean isTaxed() {
Expand Down

0 comments on commit fae5a7a

Please sign in to comment.