Search in sources :

Example 1 with DeleteTownEvent

use of com.palmergames.bukkit.towny.event.DeleteTownEvent in project Towny by ElgarL.

the class TownyDatabaseHandler method removeTown.

@Override
public void removeTown(Town town) {
    removeTownBlocks(town);
    List<Resident> toSave = new ArrayList<Resident>(town.getResidents());
    TownyWorld townyWorld = town.getWorld();
    try {
        if (town.hasNation()) {
            Nation nation = town.getNation();
            nation.removeTown(town);
            saveNation(nation);
        }
        // Clear all town blocks so the sign removal triggers.
        removeTownBlocks(town);
        town.clear();
    } catch (EmptyNationException e) {
        removeNation(e.getNation());
        TownyMessaging.sendGlobalMessage(String.format(TownySettings.getLangString("msg_del_nation"), e.getNation()));
    } catch (NotRegisteredException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    for (Resident resident : toSave) {
        removeResident(resident);
        saveResident(resident);
    }
    if (TownyEconomyHandler.isActive())
        try {
            town.payTo(town.getHoldingBalance(), new WarSpoils(), "Remove Town");
            town.removeAccount();
        } catch (Exception e) {
        }
    universe.getTownsMap().remove(town.getName().toLowerCase());
    plugin.resetCache();
    deleteTown(town);
    saveTownList();
    try {
        townyWorld.removeTown(town);
    } catch (NotRegisteredException e) {
    // Must already be removed
    }
    saveWorld(townyWorld);
    BukkitTools.getPluginManager().callEvent(new DeleteTownEvent(town.getName()));
    universe.setChangedNotify(REMOVE_TOWN);
}
Also used : ArrayList(java.util.ArrayList) DeleteTownEvent(com.palmergames.bukkit.towny.event.DeleteTownEvent) WarSpoils(com.palmergames.bukkit.towny.war.eventwar.WarSpoils) InvalidNameException(javax.naming.InvalidNameException)

Example 2 with DeleteTownEvent

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

the class TownyDatabaseHandler method removeTown.

@Override
public void removeTown(Town town, boolean delayFullRemoval) {
    if (delayFullRemoval) {
        /*
			 * When Town ruining is active, send the Town into a ruined state, prior to real removal.
			 */
        TownRuinUtil.putTownIntoRuinedState(town);
        return;
    }
    PreDeleteTownEvent preEvent = new PreDeleteTownEvent(town);
    BukkitTools.getPluginManager().callEvent(preEvent);
    if (preEvent.isCancelled())
        return;
    Resident mayor = town.getMayor();
    TownyWorld townyWorld = town.getHomeblockWorld();
    // Remove the Town's spawn particle.
    if (town.hasSpawn()) {
        try {
            universe.removeSpawnPoint(town.getSpawn());
        } catch (TownyException ignored) {
        }
    }
    removeTownBlocks(town);
    List<Resident> toSave = new ArrayList<>(town.getResidents());
    if (town.hasNation()) {
        town.removeNation();
    }
    for (Resident resident : toSave) {
        resident.clearModes();
        resident.removeTown();
    }
    // Look for residents inside of this town's jail(s) and free them, more than
    // likely the above removeTownBlocks(town) will have already set them free.
    new ArrayList<>(universe.getJailedResidentMap()).stream().filter(resident -> resident.hasJailTown(town.getName())).forEach(resident -> JailUtil.unJailResident(resident, UnJailReason.JAIL_DELETED));
    if (TownyEconomyHandler.isActive())
        town.getAccount().removeAccount();
    if (townyWorld != null) {
        try {
            townyWorld.removeTown(town);
        } catch (NotRegisteredException e) {
        // Must already be removed
        }
        saveWorld(townyWorld);
    }
    try {
        universe.unregisterTown(town);
    } catch (NotRegisteredException e) {
        TownyMessaging.sendErrorMsg(e.getMessage());
    }
    plugin.resetCache();
    deleteTown(town);
    BukkitTools.getPluginManager().callEvent(new DeleteTownEvent(town, mayor));
    TownyMessaging.sendGlobalMessage(Translatable.of("msg_del_town2", town.getName()));
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Resident(com.palmergames.bukkit.towny.object.Resident) TownBlockType(com.palmergames.bukkit.towny.object.TownBlockType) Translatable(com.palmergames.bukkit.towny.object.Translatable) PreDeleteTownEvent(com.palmergames.bukkit.towny.event.PreDeleteTownEvent) Random(java.util.Random) JailUtil(com.palmergames.bukkit.towny.utils.JailUtil) RenameNationEvent(com.palmergames.bukkit.towny.event.RenameNationEvent) TownPreUnclaimEvent(com.palmergames.bukkit.towny.event.town.TownPreUnclaimEvent) DataFieldIO(com.palmergames.bukkit.towny.object.metadata.DataFieldIO) Invite(com.palmergames.bukkit.towny.invites.Invite) DeleteFileTask(com.palmergames.bukkit.towny.tasks.DeleteFileTask) UnJailReason(com.palmergames.bukkit.towny.object.jail.UnJailReason) Location(org.bukkit.Location) RenameTownEvent(com.palmergames.bukkit.towny.event.RenameTownEvent) ZipFile(java.util.zip.ZipFile) InvalidNameException(com.palmergames.bukkit.towny.exceptions.InvalidNameException) TownyRegenAPI(com.palmergames.bukkit.towny.regen.TownyRegenAPI) NameValidation(com.palmergames.bukkit.util.NameValidation) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) Collection(java.util.Collection) BukkitTools(com.palmergames.bukkit.util.BukkitTools) UUID(java.util.UUID) TownyObject(com.palmergames.bukkit.towny.object.TownyObject) EOFException(java.io.EOFException) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) StandardCharsets(java.nio.charset.StandardCharsets) DeleteNationEvent(com.palmergames.bukkit.towny.event.DeleteNationEvent) RenameResidentEvent(com.palmergames.bukkit.towny.event.RenameResidentEvent) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Logger(org.apache.logging.log4j.Logger) NationRemoveTownEvent(com.palmergames.bukkit.towny.event.NationRemoveTownEvent) BukkitTask(org.bukkit.scheduler.BukkitTask) Queue(java.util.Queue) Towny(com.palmergames.bukkit.towny.Towny) TownyMessaging(com.palmergames.bukkit.towny.TownyMessaging) FileMgmt(com.palmergames.util.FileMgmt) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) TownUnclaimEvent(com.palmergames.bukkit.towny.event.town.TownUnclaimEvent) Translation(com.palmergames.bukkit.towny.object.Translation) DataInputStream(java.io.DataInputStream) DeletePlayerEvent(com.palmergames.bukkit.towny.event.DeletePlayerEvent) WorldCoord(com.palmergames.bukkit.towny.object.WorldCoord) DeleteTownEvent(com.palmergames.bukkit.towny.event.DeleteTownEvent) PreDeleteNationEvent(com.palmergames.bukkit.towny.event.PreDeleteNationEvent) SimpleDateFormat(java.text.SimpleDateFormat) TownyUniverse(com.palmergames.bukkit.towny.TownyUniverse) ArrayList(java.util.ArrayList) PlotGroup(com.palmergames.bukkit.towny.object.PlotGroup) PlotBlockData(com.palmergames.bukkit.towny.regen.PlotBlockData) Town(com.palmergames.bukkit.towny.object.Town) InviteHandler(com.palmergames.bukkit.towny.invites.InviteHandler) Nation(com.palmergames.bukkit.towny.object.Nation) TownRuinUtil(com.palmergames.bukkit.towny.utils.TownRuinUtil) TownyFlatFileSource.elements(com.palmergames.bukkit.towny.db.TownyFlatFileSource.elements) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) TownyEconomyHandler(com.palmergames.bukkit.towny.TownyEconomyHandler) InputStreamReader(java.io.InputStreamReader) TownyAPI(com.palmergames.bukkit.towny.TownyAPI) File(java.io.File) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) BufferedReader(java.io.BufferedReader) TownySettings(com.palmergames.bukkit.towny.TownySettings) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException) LogManager(org.apache.logging.log4j.LogManager) Jail(com.palmergames.bukkit.towny.object.jail.Jail) InputStream(java.io.InputStream) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) PreDeleteTownEvent(com.palmergames.bukkit.towny.event.PreDeleteTownEvent) ArrayList(java.util.ArrayList) PreDeleteTownEvent(com.palmergames.bukkit.towny.event.PreDeleteTownEvent) DeleteTownEvent(com.palmergames.bukkit.towny.event.DeleteTownEvent) Resident(com.palmergames.bukkit.towny.object.Resident) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Aggregations

DeleteTownEvent (com.palmergames.bukkit.towny.event.DeleteTownEvent)2 ArrayList (java.util.ArrayList)2 Towny (com.palmergames.bukkit.towny.Towny)1 TownyAPI (com.palmergames.bukkit.towny.TownyAPI)1 TownyEconomyHandler (com.palmergames.bukkit.towny.TownyEconomyHandler)1 TownyMessaging (com.palmergames.bukkit.towny.TownyMessaging)1 TownySettings (com.palmergames.bukkit.towny.TownySettings)1 TownyUniverse (com.palmergames.bukkit.towny.TownyUniverse)1 TownyFlatFileSource.elements (com.palmergames.bukkit.towny.db.TownyFlatFileSource.elements)1 DeleteNationEvent (com.palmergames.bukkit.towny.event.DeleteNationEvent)1 DeletePlayerEvent (com.palmergames.bukkit.towny.event.DeletePlayerEvent)1 NationRemoveTownEvent (com.palmergames.bukkit.towny.event.NationRemoveTownEvent)1 PreDeleteNationEvent (com.palmergames.bukkit.towny.event.PreDeleteNationEvent)1 PreDeleteTownEvent (com.palmergames.bukkit.towny.event.PreDeleteTownEvent)1 RenameNationEvent (com.palmergames.bukkit.towny.event.RenameNationEvent)1 RenameResidentEvent (com.palmergames.bukkit.towny.event.RenameResidentEvent)1 RenameTownEvent (com.palmergames.bukkit.towny.event.RenameTownEvent)1 TownPreUnclaimEvent (com.palmergames.bukkit.towny.event.town.TownPreUnclaimEvent)1 TownUnclaimEvent (com.palmergames.bukkit.towny.event.town.TownUnclaimEvent)1 AlreadyRegisteredException (com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException)1