Skip to content

Commit

Permalink
- Add town price to the PreNewTownEvent.
Browse files Browse the repository at this point in the history
  • Loading branch information
LlmDl committed Feb 27, 2024
1 parent e910ede commit 1da2e80
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Towny/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<artifactId>towny</artifactId>
<packaging>jar</packaging>
<version>0.100.1.17</version>
<version>0.100.1.18</version>

<licenses>
<license>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2506,14 +2506,18 @@ public static void newTown(Player player, String name, Resident resident, boolea

// If the town doesn't cost money to create, just make the Town.
if (noCharge || !TownyEconomyHandler.isActive()) {
BukkitTools.ifCancelledThenThrow(new PreNewTownEvent(player, name, spawnLocation));
BukkitTools.ifCancelledThenThrow(new PreNewTownEvent(player, name, spawnLocation, 0));
newTown(world, name, resident, key, spawnLocation, player);
TownyMessaging.sendGlobalMessage(Translatable.of("msg_new_town", player.getName(), StringMgmt.remUnderscore(name)));
return;
}

// Fire a cancellable event that allows allows plugins to alter the price of a town.
PreNewTownEvent pnte = new PreNewTownEvent(player, name, spawnLocation, TownySettings.getNewTownPrice());
BukkitTools.ifCancelledThenThrow(pnte);

// Test if the resident can afford the town.
double cost = TownySettings.getNewTownPrice();
double cost = pnte.getPrice();
if (!resident.getAccount().canPayFromHoldings(cost))
throw new TownyException(Translatable.of("msg_no_funds_new_town2", (resident.getName().equals(player.getName()) ? Translatable.of("msg_you") : resident.getName()), cost));

Expand All @@ -2529,7 +2533,6 @@ public static void newTown(Player player, String name, Resident resident, boolea
plugin.getLogger().log(Level.WARNING, "An exception occurred while creating a new town", e);
}
})
.setCancellableEvent(new PreNewTownEvent(player, name, spawnLocation))
.setTitle(Translatable.of("msg_confirm_purchase", prettyMoney(cost)))
.setCost(new ConfirmationTransaction(() -> cost, resident, "New Town Cost",
Translatable.of("msg_no_funds_new_town2", (resident.getName().equals(player.getName()) ? Translatable.of("msg_you") : resident.getName()), prettyMoney(cost))))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ public class PreNewTownEvent extends CancellableTownyEvent {
private final String townName;
private final Location spawnLocation;
private final WorldCoord worldCoord;
private double price;

public PreNewTownEvent(Player player, String townName, Location spawnLocation) {
public PreNewTownEvent(Player player, String townName, Location spawnLocation, double price) {
this.player = player;
this.townName = townName;
this.spawnLocation = spawnLocation;
this.worldCoord = WorldCoord.parseWorldCoord(spawnLocation);
this.setPrice(price);
}

public Player getPlayer() {
Expand All @@ -37,6 +39,14 @@ public WorldCoord getTownWorldCoord() {
return this.worldCoord;
}

public double getPrice() {
return price;
}

public void setPrice(double price) {
this.price = price;
}

public static HandlerList getHandlerList() {
return HANDLER_LIST;
}
Expand Down
5 changes: 4 additions & 1 deletion Towny/src/main/resources/ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9569,4 +9569,7 @@ v0.92.0.11:
- Child node of towny.command.resident.*
- No changes required to the townyperms.yml.
- New automatic townyperms.yml edit: towny.command.resident.outlawlist will be added to the townyperms.yml nomad section.
- Close a loophole using out-of-jail teleports.
- Close a loophole using out-of-jail teleports.
0.100.1.18:
- Add town price to the PreNewTownEvent.
- Unblocks https://github.com/TownyAdvanced/TownyProvinces/issues/52.

0 comments on commit 1da2e80

Please # to comment.