Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting a default plot price of -1 #7313

Merged
merged 3 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
LlmDl marked this conversation as resolved.
Show resolved Hide resolved
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
Loading