Skip to content

Commit

Permalink
Adds confirmation for setting plot types to outposts. (#3900)
Browse files Browse the repository at this point in the history
* Adds confirmation for setting plot types to outposts.

* Revert lang changes.

* Fix merge issues.

* fix the other lang files.

* Fix players being charged before they confirm/cancel the confirmation.

* Add forgotten check to see if economy is being used.

Co-authored-by: Llm Dl <[email protected]>
  • Loading branch information
Suneet Tipirneni (Siris) and LlmDl authored Apr 14, 2020
1 parent a54cd08 commit 6e97bb5
Showing 1 changed file with 34 additions and 10 deletions.
44 changes: 34 additions & 10 deletions src/com/palmergames/bukkit/towny/command/PlotCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -662,16 +662,40 @@ public boolean parsePlotCommand(Player player, String[] split) throws TownyExcep
boolean isAdmin = townyUniverse.getPermissionSource().isTownyAdmin(player);
Coord key = Coord.parseCoord(plugin.getCache(player).getLastLocation());

if (OutpostUtil.OutpostTests(town, resident, townyWorld, key, isAdmin, true)) {
if (TownySettings.isUsingEconomy() && !town.getAccount().pay(TownySettings.getOutpostCost(), String.format("Plot Set Outpost")))
throw new TownyException(TownySettings.getLangString("msg_err_cannot_afford_to_set_outpost"));

TownyMessaging.sendMessage(player, String.format(TownySettings.getLangString("msg_plot_set_cost"), TownyEconomyHandler.getFormattedBalance(TownySettings.getOutpostCost()), TownySettings.getLangString("outpost")));
townBlock.setOutpost(true);
town.addOutpostSpawn(player.getLocation());
townyUniverse.getDataSource().saveTown(town);
townyUniverse.getDataSource().saveTownBlock(townBlock);
}
if (OutpostUtil.OutpostTests(town, resident, townyWorld, key, isAdmin, true)) {
// Test if they can pay.
if (TownySettings.isUsingEconomy() && !town.getAccount().canPayFromHoldings(TownySettings.getOutpostCost()))
throw new TownyException(TownySettings.getLangString("msg_err_cannot_afford_to_set_outpost"));

// Create a confirmation for setting outpost.
Confirmation confirmation = new Confirmation(() -> {
townBlock.setOutpost(true);

try {
town.addOutpostSpawn(player.getLocation());
} catch (TownyException e) {
TownyMessaging.sendErrorMsg(e.getMessage());
return;
}

//Make them pay, ignoring exception because we already know they can pay.
if (TownySettings.isUsingEconomy() && TownySettings.getOutpostCost() > 0 )
try {
town.getAccount().pay(TownySettings.getOutpostCost(), "Plot Set Outpost");
} catch (EconomyException ignored) {
}
townyUniverse.getDataSource().saveTown(town);
townyUniverse.getDataSource().saveTownBlock(townBlock);
TownyMessaging.sendMessage(player, String.format(TownySettings.getLangString("msg_plot_set_cost"), TownyEconomyHandler.getFormattedBalance(TownySettings.getOutpostCost()), TownySettings.getLangString("outpost")));
});
// Set title.
String title = String.format(TownySettings.getLangString("msg_confirm_purchase"), TownyEconomyHandler.getFormattedBalance(TownySettings.getOutpostCost()));
confirmation.setTitle(title);

// Send the confirmation.
ConfirmationHandler.sendConfirmation(player, confirmation);

}
return true;
}
}
Expand Down

0 comments on commit 6e97bb5

Please sign in to comment.