Search in sources :

Example 1 with PlotNotForSaleEvent

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();
}
Also used : PlotNotForSaleEvent(com.palmergames.bukkit.towny.event.plot.PlotNotForSaleEvent) PlotSetForSaleEvent(com.palmergames.bukkit.towny.event.plot.PlotSetForSaleEvent) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Aggregations

PlotNotForSaleEvent (com.palmergames.bukkit.towny.event.plot.PlotNotForSaleEvent)1 PlotSetForSaleEvent (com.palmergames.bukkit.towny.event.plot.PlotSetForSaleEvent)1 TownyException (com.palmergames.bukkit.towny.exceptions.TownyException)1 TownBlock (com.palmergames.bukkit.towny.object.TownBlock)1