use of com.palmergames.bukkit.towny.event.plot.PlotNotForSaleEvent in project Towny by TownyAdvanced.
the class PlotCommand method setPlotForSale.
/**
* Set the plot for sale/not for sale if permitted
*
* @param resident - Resident Object.
* @param worldCoord - WorldCoord.
* @param forSale - Price.
* @throws TownyException - Exception.
*/
public void setPlotForSale(Resident resident, WorldCoord worldCoord, double forSale) throws TownyException {
TownBlock townBlock = worldCoord.getTownBlockOrNull();
if (townBlock == null || !townBlock.hasTown())
throw new TownyException(Translatable.of("msg_err_not_part_town"));
// Test we are allowed to work on this plot
// If this fails it will trigger a TownyException.
plotTestOwner(resident, townBlock);
townBlock.setPlotPrice(Math.min(TownySettings.getMaxPlotPrice(), forSale));
if (forSale != -1) {
TownyMessaging.sendPrefixedTownMessage(townBlock.getTownOrNull(), Translatable.of("MSG_PLOT_FOR_SALE", resident.getName(), worldCoord.toString()));
if (!resident.hasTown() || (resident.hasTown() && townBlock.getTownOrNull() != resident.getTownOrNull()))
TownyMessaging.sendMsg(resident, Translatable.of("MSG_PLOT_FOR_SALE", resident.getName(), worldCoord.toString()));
Bukkit.getPluginManager().callEvent(new PlotSetForSaleEvent(resident, forSale, townBlock));
} else {
TownyMessaging.sendMsg(resident, Translatable.of("msg_plot_set_to_nfs"));
Bukkit.getPluginManager().callEvent(new PlotNotForSaleEvent(resident, townBlock));
}
// Save this townblock so the for sale status is remembered.
townBlock.save();
}
Aggregations