Search in sources :

Example 1 with WarSpoils

use of com.palmergames.bukkit.towny.war.eventwar.WarSpoils in project Towny by ElgarL.

the class TownyDatabaseHandler method removeNation.

@Override
public void removeNation(Nation nation) {
    // search and remove from all ally/enemy lists
    List<Nation> toSaveNation = new ArrayList<Nation>();
    for (Nation toCheck : new ArrayList<Nation>(universe.getNationsMap().values())) if (toCheck.hasAlly(nation) || toCheck.hasEnemy(nation)) {
        try {
            if (toCheck.hasAlly(nation))
                toCheck.removeAlly(nation);
            else
                toCheck.removeEnemy(nation);
            toSaveNation.add(toCheck);
        } catch (NotRegisteredException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    for (Nation toCheck : toSaveNation) saveNation(toCheck);
    // Transfer any money to the warchest.
    if (TownyEconomyHandler.isActive())
        try {
            nation.payTo(nation.getHoldingBalance(), new WarSpoils(), "Remove Nation");
            nation.removeAccount();
        } catch (Exception e) {
        }
    // Delete nation and save towns
    deleteNation(nation);
    List<Town> toSave = new ArrayList<Town>(nation.getTowns());
    nation.clear();
    universe.getNationsMap().remove(nation.getName().toLowerCase());
    for (Town town : toSave) {
        /*
			 * Remove all resident titles before saving the town itself.
			 */
        List<Resident> titleRemove = new ArrayList<Resident>(town.getResidents());
        for (Resident res : titleRemove) {
            if (res.hasTitle() || res.hasSurname()) {
                res.setTitle("");
                res.setSurname("");
                saveResident(res);
            }
        }
        saveTown(town);
    }
    plugin.resetCache();
    saveNationList();
    BukkitTools.getPluginManager().callEvent(new DeleteNationEvent(nation.getName()));
    universe.setChangedNotify(REMOVE_NATION);
}
Also used : DeleteNationEvent(com.palmergames.bukkit.towny.event.DeleteNationEvent) ArrayList(java.util.ArrayList) WarSpoils(com.palmergames.bukkit.towny.war.eventwar.WarSpoils) InvalidNameException(javax.naming.InvalidNameException)

Example 2 with WarSpoils

use of com.palmergames.bukkit.towny.war.eventwar.WarSpoils 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)

Aggregations

WarSpoils (com.palmergames.bukkit.towny.war.eventwar.WarSpoils)2 ArrayList (java.util.ArrayList)2 InvalidNameException (javax.naming.InvalidNameException)2 DeleteNationEvent (com.palmergames.bukkit.towny.event.DeleteNationEvent)1 DeleteTownEvent (com.palmergames.bukkit.towny.event.DeleteTownEvent)1