Search in sources :

Example 1 with TownPreUnclaimEvent

use of com.palmergames.bukkit.towny.event.town.TownPreUnclaimEvent in project Towny by TownyAdvanced.

the class TownyDatabaseHandler method removeTownBlock.

@Override
public void removeTownBlock(TownBlock townBlock) {
    Town town = townBlock.getTownOrNull();
    if (town == null)
        // Log as error because TownBlocks *must* have a town.
        logger.error(String.format("The TownBlock at (%s, %d, %d) is not registered to a town.", townBlock.getWorld().getName(), townBlock.getX(), townBlock.getZ()));
    TownPreUnclaimEvent event = new TownPreUnclaimEvent(town, townBlock);
    BukkitTools.getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        // Log as Warn because the event has been processed
        logger.warn(event.getCancelMessage());
        return;
    }
    if (townBlock.isJail() && townBlock.getJail() != null)
        removeJail(townBlock.getJail());
    universe.removeTownBlock(townBlock);
    deleteTownBlock(townBlock);
    if (townBlock.getWorld().isUsingPlotManagementDelete())
        TownyRegenAPI.addDeleteTownBlockIdQueue(townBlock.getWorldCoord());
    // Move the plot to be restored
    if (townBlock.getWorld().isUsingPlotManagementRevert())
        TownyRegenAPI.addToRegenQueueList(townBlock.getWorldCoord(), true);
    // Raise an event to signal the unclaim
    BukkitTools.getPluginManager().callEvent(new TownUnclaimEvent(town, townBlock.getWorldCoord()));
}
Also used : Town(com.palmergames.bukkit.towny.object.Town) TownPreUnclaimEvent(com.palmergames.bukkit.towny.event.town.TownPreUnclaimEvent) TownUnclaimEvent(com.palmergames.bukkit.towny.event.town.TownUnclaimEvent)

Aggregations

TownPreUnclaimEvent (com.palmergames.bukkit.towny.event.town.TownPreUnclaimEvent)1 TownUnclaimEvent (com.palmergames.bukkit.towny.event.town.TownUnclaimEvent)1 Town (com.palmergames.bukkit.towny.object.Town)1