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