use of com.palmergames.bukkit.towny.exceptions.EmptyNationException in project Towny by ElgarL.
the class NationCommand method nationKick.
public void nationKick(Player player, Resident resident, Nation nation, List<Town> kicking) {
ArrayList<Town> remove = new ArrayList<Town>();
for (Town town : kicking) if (town.isCapital())
remove.add(town);
else
try {
nation.removeTown(town);
TownyUniverse.getDataSource().saveTown(town);
} catch (NotRegisteredException e) {
remove.add(town);
} catch (EmptyNationException e) {
// You can't kick yourself and only the mayor can kick
// assistants
// so there will always be at least one resident.
}
for (Town town : remove) kicking.remove(town);
if (kicking.size() > 0) {
String msg = "";
for (Town town : kicking) {
msg += town.getName() + ", ";
TownyMessaging.sendTownMessage(town, String.format(TownySettings.getLangString("msg_nation_kicked_by"), player.getName()));
}
msg = msg.substring(0, msg.length() - 2);
msg = String.format(TownySettings.getLangString("msg_nation_kicked"), player.getName(), msg);
TownyMessaging.sendNationMessage(nation, ChatTools.color(msg));
TownyUniverse.getDataSource().saveNation(nation);
plugin.resetCache();
} else
TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_invalid_name"));
}
use of com.palmergames.bukkit.towny.exceptions.EmptyNationException in project Towny by ElgarL.
the class NationCommand method nationLeave.
public void nationLeave(Player player) {
Town town = null;
Nation nation = null;
try {
Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
town = resident.getTown();
nation = town.getNation();
nation.removeTown(town);
/*
* 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("");
TownyUniverse.getDataSource().saveResident(res);
}
}
TownyUniverse.getDataSource().saveNation(nation);
TownyUniverse.getDataSource().saveNationList();
TownyMessaging.sendNationMessage(nation, ChatTools.color(String.format(TownySettings.getLangString("msg_nation_town_left"), town.getName())));
TownyMessaging.sendTownMessage(town, ChatTools.color(String.format(TownySettings.getLangString("msg_town_left_nation"), nation.getName())));
} catch (TownyException x) {
TownyMessaging.sendErrorMsg(player, x.getMessage());
return;
} catch (EmptyNationException en) {
TownyUniverse.getDataSource().removeNation(en.getNation());
TownyUniverse.getDataSource().saveNationList();
TownyMessaging.sendGlobalMessage(ChatTools.color(String.format(TownySettings.getLangString("msg_del_nation"), en.getNation().getName())));
} finally {
TownyUniverse.getDataSource().saveTown(town);
}
}
use of com.palmergames.bukkit.towny.exceptions.EmptyNationException in project Towny by ElgarL.
the class DailyTimerTask method collectNationTaxes.
/**
* Collect taxes due to the nation from it's member towns.
*
* @param nation
* @throws EconomyException
*/
protected void collectNationTaxes(Nation nation) throws EconomyException {
if (nation.getTaxes() > 0) {
List<Town> towns = new ArrayList<Town>(nation.getTowns());
ListIterator<Town> townItr = towns.listIterator();
Town town = null;
while (townItr.hasNext()) {
town = townItr.next();
/*
* Only collect nation tax from this town if it really still
* exists.
* We are running in an Async thread so MUST verify all objects.
*/
if (TownyUniverse.getDataSource().hasTown(town.getName())) {
if (town.isCapital() || !town.hasUpkeep())
continue;
if (!town.payTo(nation.getTaxes(), nation, "Nation Tax")) {
try {
TownyMessaging.sendNationMessage(nation, TownySettings.getCouldntPayTaxesMsg(town, "nation"));
nation.removeTown(town);
} catch (EmptyNationException e) {
// Always has 1 town (capital) so ignore
} catch (NotRegisteredException e) {
}
TownyUniverse.getDataSource().saveTown(town);
TownyUniverse.getDataSource().saveNation(nation);
}
} else
TownyMessaging.sendTownMessage(town, TownySettings.getPayedTownTaxMsg() + nation.getTaxes());
}
}
}
Aggregations