use of com.palmergames.bukkit.towny.object.Nation in project Towny by ElgarL.
the class NationCommand method listNations.
/**
* Send a list of all nations in the universe to player Command: /nation
* list
*
* @param player
*/
public void listNations(Player player) {
player.sendMessage(ChatTools.formatTitle(TownySettings.getLangString("nation_plu")));
ArrayList<String> formatedList = new ArrayList<String>();
for (Nation nation : TownyUniverse.getDataSource().getNations()) formatedList.add(Colors.LightBlue + nation.getName() + Colors.Blue + " [" + nation.getNumTowns() + "]" + Colors.White);
for (String line : ChatTools.list(formatedList)) player.sendMessage(line);
}
use of com.palmergames.bukkit.towny.object.Nation in project Towny by ElgarL.
the class NationCommand method nationKick.
public void nationKick(Player player, String[] names) {
if (names.length < 1) {
TownyMessaging.sendErrorMsg(player, "Eg: /nation kick [names]");
return;
}
Resident resident;
Nation nation;
try {
resident = TownyUniverse.getDataSource().getResident(player.getName());
nation = resident.getTown().getNation();
} catch (TownyException x) {
TownyMessaging.sendErrorMsg(player, x.getMessage());
return;
}
nationKick(player, resident, nation, TownyUniverse.getDataSource().getTowns(names));
}
use of com.palmergames.bukkit.towny.object.Nation in project Towny by ElgarL.
the class NationCommand method nationToggle.
public void nationToggle(Player player, String[] split) throws TownyException {
if (split.length == 0) {
player.sendMessage(ChatTools.formatTitle("/nation toggle"));
player.sendMessage(ChatTools.formatCommand("", "/nation toggle", "neutral", ""));
} else {
Resident resident;
Nation nation;
try {
resident = TownyUniverse.getDataSource().getResident(player.getName());
nation = resident.getTown().getNation();
} catch (TownyException x) {
TownyMessaging.sendErrorMsg(player, x.getMessage());
return;
}
if (split[0].equalsIgnoreCase("neutral")) {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_TOGGLE_NEUTRAL.getNode()))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
try {
if (!TownySettings.isDeclaringNeutral())
throw new TownyException(TownySettings.getLangString("msg_neutral_disabled"));
boolean choice = !nation.isNeutral();
Double cost = TownySettings.getNationNeutralityCost();
if (choice && TownySettings.isUsingEconomy() && !nation.pay(cost, "Nation Neutrality Cost"))
throw new TownyException(TownySettings.getLangString("msg_nation_cant_neutral"));
nation.setNeutral(choice);
// for neutral
if (TownySettings.isUsingEconomy() && cost > 0)
TownyMessaging.sendMsg(player, String.format(TownySettings.getLangString("msg_you_paid"), TownyEconomyHandler.getFormattedBalance(cost)));
else
TownyMessaging.sendMsg(player, TownySettings.getLangString("msg_nation_set_neutral"));
TownyMessaging.sendNationMessage(nation, TownySettings.getLangString("msg_nation_neutral") + (nation.isNeutral() ? Colors.Green : Colors.Red + " not") + " neutral.");
} catch (EconomyException e) {
TownyMessaging.sendErrorMsg(player, e.getMessage());
} catch (TownyException e) {
try {
nation.setNeutral(false);
} catch (TownyException e1) {
e1.printStackTrace();
}
TownyMessaging.sendErrorMsg(player, e.getMessage());
} catch (Exception e) {
TownyMessaging.sendErrorMsg(player, e.getMessage());
}
} else {
TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_err_invalid_property"), "nation"));
return;
}
plugin.getTownyUniverse();
TownyUniverse.getDataSource().saveNation(nation);
}
}
use of com.palmergames.bukkit.towny.object.Nation 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.object.Nation in project Towny by ElgarL.
the class NationCommand method newNation.
public Nation newNation(TownyUniverse universe, String name, Town town) throws AlreadyRegisteredException, NotRegisteredException {
TownyUniverse.getDataSource().newNation(name);
Nation nation = TownyUniverse.getDataSource().getNation(name);
nation.addTown(town);
nation.setCapital(town);
if (TownySettings.isUsingEconomy()) {
//TODO
try {
nation.setBalance(0, "Deleting Nation");
} catch (EconomyException e) {
e.printStackTrace();
}
}
TownyUniverse.getDataSource().saveTown(town);
TownyUniverse.getDataSource().saveNation(nation);
TownyUniverse.getDataSource().saveNationList();
return nation;
}
Aggregations