use of com.palmergames.bukkit.towny.event.NationRemoveTownEvent in project Towny by TownyAdvanced.
the class TownyDatabaseHandler method removeNation.
@Override
public void removeNation(Nation nation) {
PreDeleteNationEvent preEvent = new PreDeleteNationEvent(nation);
BukkitTools.getPluginManager().callEvent(preEvent);
if (preEvent.isCancelled())
return;
Resident king = null;
if (nation.hasKing())
king = nation.getKing();
// Remove the Nation's spawn particle.
if (nation.hasSpawn()) {
try {
universe.removeSpawnPoint(nation.getSpawn());
} catch (TownyException ignored) {
}
}
// search and remove from all ally/enemy lists
List<Nation> toSaveNation = new ArrayList<>();
for (Nation toCheck : new ArrayList<>(universe.getNations())) 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) {
e.printStackTrace();
}
}
for (Nation toCheck : toSaveNation) saveNation(toCheck);
// Search and remove any ally invites sent to this nation.
for (Nation toCheck : new ArrayList<>(universe.getNations())) for (Invite invite : new ArrayList<>(toCheck.getSentAllyInvites())) if (invite.getReceiver().getName().equalsIgnoreCase(nation.getName())) {
toCheck.deleteSentAllyInvite(invite);
InviteHandler.removeInvite(invite);
}
// Search and remove any sent ally invites sent by this nation.
for (Invite invite : new ArrayList<>(nation.getSentAllyInvites())) {
nation.deleteSentAllyInvite(invite);
InviteHandler.removeInvite(invite);
}
// Transfer any money to the warchest.
if (TownyEconomyHandler.isActive())
nation.getAccount().removeAccount();
// Delete nation and save towns
deleteNation(nation);
List<Town> toSave = new ArrayList<>(nation.getTowns());
nation.clear();
try {
universe.unregisterNation(nation);
} catch (NotRegisteredException e) {
// Just print out the exception. Very unlikely to happen.
e.printStackTrace();
}
for (Town town : toSave) {
for (Resident res : town.getResidents()) {
if (res.hasTitle() || res.hasSurname()) {
res.setTitle("");
res.setSurname("");
}
res.updatePermsForNationRemoval();
res.save();
}
try {
town.setNation(null);
} catch (AlreadyRegisteredException ignored) {
// Cannot reach AlreadyRegisteredException
}
town.save();
BukkitTools.getPluginManager().callEvent(new NationRemoveTownEvent(town, nation));
}
plugin.resetCache();
UUID kingUUID = null;
if (king != null)
kingUUID = king.getUUID();
BukkitTools.getPluginManager().callEvent(new DeleteNationEvent(nation, kingUUID));
}
use of com.palmergames.bukkit.towny.event.NationRemoveTownEvent in project Towny by ElgarL.
the class Nation method remove.
private void remove(Town town) {
// removeAssistantsIn(town);
try {
town.setNation(null);
} catch (AlreadyRegisteredException e) {
}
towns.remove(town);
BukkitTools.getPluginManager().callEvent(new NationRemoveTownEvent(town, this));
}
Aggregations