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);
}
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);
}
Aggregations