use of com.palmergames.bukkit.towny.object.Town 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.object.Town in project Towny by ElgarL.
the class TownyFormatter method getStatus.
/**
*
* @param townBlock
* @return a string list containing the results.
*/
public static List<String> getStatus(TownBlock townBlock) {
List<String> out = new ArrayList<String>();
try {
TownBlockOwner owner;
Town town = townBlock.getTown();
TownyWorld world = townBlock.getWorld();
if (townBlock.hasResident()) {
owner = townBlock.getResident();
} else {
owner = townBlock.getTown();
}
out.add(ChatTools.formatTitle(TownyFormatter.getFormattedName(owner) + ((BukkitTools.isOnline(owner.getName())) ? Colors.LightGreen + " (Online)" : "")));
out.add(Colors.Green + " Perm: " + ((owner instanceof Resident) ? townBlock.getPermissions().getColourString() : townBlock.getPermissions().getColourString().replace("f", "r")));
out.add(Colors.Green + "PvP: " + ((town.isPVP() || world.isForcePVP() || townBlock.getPermissions().pvp) ? Colors.Red + "ON" : Colors.LightGreen + "OFF") + Colors.Green + " Explosions: " + ((world.isForceExpl() || townBlock.getPermissions().explosion) ? Colors.Red + "ON" : Colors.LightGreen + "OFF") + Colors.Green + " Firespread: " + ((town.isFire() || world.isForceFire() || townBlock.getPermissions().fire) ? Colors.Red + "ON" : Colors.LightGreen + "OFF") + Colors.Green + " Mob Spawns: " + ((town.hasMobs() || world.isForceTownMobs() || townBlock.getPermissions().mobs) ? Colors.Red + "ON" : Colors.LightGreen + "OFF"));
} catch (NotRegisteredException e) {
out.add("Error: " + e.getMessage());
}
return out;
}
use of com.palmergames.bukkit.towny.object.Town in project Towny by ElgarL.
the class NationCommand method newNation.
/**
* Create a new nation. Command: /nation new [nation] *[capital]
*
* @param player
*/
public void newNation(Player player, String name, String capitalName) {
TownyUniverse universe = plugin.getTownyUniverse();
try {
Town town = TownyUniverse.getDataSource().getTown(capitalName);
if (town.hasNation())
throw new TownyException(TownySettings.getLangString("msg_err_already_nation"));
// Check the name is valid and doesn't already exist.
String filteredName;
try {
filteredName = NameValidation.checkAndFilterName(name);
} catch (InvalidNameException e) {
filteredName = null;
}
if ((filteredName == null) || TownyUniverse.getDataSource().hasNation(filteredName))
throw new TownyException(String.format(TownySettings.getLangString("msg_err_invalid_name"), name));
if (TownySettings.isUsingEconomy() && !town.pay(TownySettings.getNewNationPrice(), "New Nation Cost"))
throw new TownyException(TownySettings.getLangString("msg_no_funds_new_nation"));
newNation(universe, name, town);
/*
* universe.newNation(name); Nation nation =
* universe.getNation(name); nation.addTown(town);
* nation.setCapital(town);
*
* universe.getDataSource().saveTown(town);
* universe.getDataSource().saveNation(nation);
* universe.getDataSource().saveNationList();
*/
TownyMessaging.sendGlobalMessage(TownySettings.getNewNationMsg(player.getName(), name));
} catch (TownyException x) {
TownyMessaging.sendErrorMsg(player, x.getMessage());
// TODO: delete town data that might have been done
} catch (EconomyException x) {
TownyMessaging.sendErrorMsg(player, x.getMessage());
}
}
use of com.palmergames.bukkit.towny.object.Town in project Towny by ElgarL.
the class NationCommand method nationAdd.
public static void nationAdd(Nation nation, List<Town> towns) throws AlreadyRegisteredException {
for (Town town : towns) {
if (!town.hasNation()) {
nation.addTown(town);
TownyUniverse.getDataSource().saveTown(town);
TownyMessaging.sendNationMessage(nation, String.format(TownySettings.getLangString("msg_join_nation"), town.getName()));
}
}
plugin.resetCache();
TownyUniverse.getDataSource().saveNation(nation);
}
use of com.palmergames.bukkit.towny.object.Town in project Towny by ElgarL.
the class NationCommand method nationSet.
public void nationSet(Player player, String[] split) throws TownyException, InvalidNameException {
if (split.length == 0) {
player.sendMessage(ChatTools.formatTitle("/nation set"));
player.sendMessage(ChatTools.formatCommand("", "/nation set", "king " + TownySettings.getLangString("res_2"), ""));
player.sendMessage(ChatTools.formatCommand("", "/nation set", "capital [town]", ""));
player.sendMessage(ChatTools.formatCommand("", "/nation set", "taxes [$]", ""));
player.sendMessage(ChatTools.formatCommand("", "/nation set", "name [name]", ""));
player.sendMessage(ChatTools.formatCommand("", "/nation set", "title/surname [resident] [text]", ""));
player.sendMessage(ChatTools.formatCommand("", "/nation set", "tag [upto 4 letters] or clear", ""));
} 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;
}
// TODO: Let admin's call a subfunction of this.
if (split[0].equalsIgnoreCase("king")) {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_SET_KING.getNode()))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
if (split.length < 2)
TownyMessaging.sendErrorMsg(player, "Eg: /nation set king Dumbo");
else
try {
Resident newKing = TownyUniverse.getDataSource().getResident(split[1]);
String oldKingsName = nation.getCapital().getMayor().getName();
nation.setKing(newKing);
plugin.deleteCache(oldKingsName);
plugin.deleteCache(newKing.getName());
TownyMessaging.sendNationMessage(nation, TownySettings.getNewKingMsg(newKing.getName(), nation.getName()));
} catch (TownyException e) {
TownyMessaging.sendErrorMsg(player, e.getMessage());
}
} else if (split[0].equalsIgnoreCase("capital")) {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_SET_CAPITOL.getNode()))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
if (split.length < 2)
TownyMessaging.sendErrorMsg(player, "Eg: /nation set capital {town name}");
else
try {
Town newCapital = TownyUniverse.getDataSource().getTown(split[1]);
nation.setCapital(newCapital);
plugin.resetCache();
TownyMessaging.sendNationMessage(nation, TownySettings.getNewKingMsg(newCapital.getMayor().getName(), nation.getName()));
} catch (TownyException e) {
TownyMessaging.sendErrorMsg(player, e.getMessage());
}
} else if (split[0].equalsIgnoreCase("taxes")) {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_SET_TAXES.getNode()))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
if (split.length < 2)
TownyMessaging.sendErrorMsg(player, "Eg: /nation set taxes 70");
else {
Integer amount = Integer.parseInt(split[1].trim());
if (amount < 0) {
TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_negative_money"));
return;
}
try {
nation.setTaxes(amount);
TownyMessaging.sendNationMessage(nation, String.format(TownySettings.getLangString("msg_town_set_nation_tax"), player.getName(), split[1]));
} catch (NumberFormatException e) {
TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_error_must_be_int"));
}
}
} else if (split[0].equalsIgnoreCase("name")) {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_SET_NAME.getNode()))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
if (split.length < 2)
TownyMessaging.sendErrorMsg(player, "Eg: /nation set name Plutoria");
else {
if (!NameValidation.isBlacklistName(split[1]))
nationRename(player, nation, split[1]);
else
TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_invalid_name"));
}
} else if (split[0].equalsIgnoreCase("tag")) {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_SET_TAG.getNode()))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
if (split.length < 2)
TownyMessaging.sendErrorMsg(player, "Eg: /nation set tag PLT");
else if (split[1].equalsIgnoreCase("clear")) {
try {
nation.setTag(" ");
TownyMessaging.sendNationMessage(nation, String.format(TownySettings.getLangString("msg_reset_nation_tag"), player.getName()));
} catch (TownyException e) {
TownyMessaging.sendErrorMsg(player, e.getMessage());
}
} else
nation.setTag(NameValidation.checkAndFilterName(split[1]));
TownyMessaging.sendNationMessage(nation, String.format(TownySettings.getLangString("msg_set_nation_tag"), player.getName(), nation.getTag()));
} else if (split[0].equalsIgnoreCase("title")) {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_SET_TITLE.getNode()))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
// Give the resident a title
if (split.length < 2)
TownyMessaging.sendErrorMsg(player, "Eg: /nation set title bilbo Jester ");
else
resident = TownyUniverse.getDataSource().getResident(split[1]);
if (resident.hasNation()) {
if (resident.getTown().getNation() != TownyUniverse.getDataSource().getResident(player.getName()).getTown().getNation()) {
TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_err_not_same_nation"), resident.getName()));
return;
}
} else {
TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_err_not_same_nation"), resident.getName()));
return;
}
split = StringMgmt.remArgs(split, 2);
if (StringMgmt.join(split).length() > TownySettings.getMaxTitleLength()) {
TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_input_too_long"));
return;
}
String title = StringMgmt.join(NameValidation.checkAndFilterArray(split));
resident.setTitle(title + " ");
TownyUniverse.getDataSource().saveResident(resident);
if (resident.hasTitle())
TownyMessaging.sendNationMessage(nation, String.format(TownySettings.getLangString("msg_set_title"), resident.getName(), resident.getTitle()));
else
TownyMessaging.sendNationMessage(nation, String.format(TownySettings.getLangString("msg_clear_title_surname"), "Title", resident.getName()));
} else if (split[0].equalsIgnoreCase("surname")) {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_SET_SURNAME.getNode()))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
// Give the resident a title
if (split.length < 2)
TownyMessaging.sendErrorMsg(player, "Eg: /nation set surname bilbo the dwarf ");
else
resident = TownyUniverse.getDataSource().getResident(split[1]);
if (resident.hasNation()) {
if (resident.getTown().getNation() != TownyUniverse.getDataSource().getResident(player.getName()).getTown().getNation()) {
TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_err_not_same_nation"), resident.getName()));
return;
}
} else {
TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_err_not_same_nation"), resident.getName()));
return;
}
split = StringMgmt.remArgs(split, 2);
if (StringMgmt.join(split).length() > TownySettings.getMaxTitleLength()) {
TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_input_too_long"));
return;
}
String surname = StringMgmt.join(NameValidation.checkAndFilterArray(split));
resident.setSurname(" " + surname);
TownyUniverse.getDataSource().saveResident(resident);
if (resident.hasSurname())
TownyMessaging.sendNationMessage(nation, String.format(TownySettings.getLangString("msg_set_surname"), resident.getName(), resident.getSurname()));
else
TownyMessaging.sendNationMessage(nation, String.format(TownySettings.getLangString("msg_clear_title_surname"), "Surname", resident.getName()));
} else {
TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_err_invalid_property"), split[0]));
return;
}
TownyUniverse.getDataSource().saveNation(nation);
TownyUniverse.getDataSource().saveNationList();
}
}
Aggregations