use of com.palmergames.bukkit.towny.exceptions.TownyException in project Towny by ElgarL.
the class NationCommand method nationDeposit.
private void nationDeposit(Player player, int amount) {
Resident resident;
Nation nation;
try {
resident = TownyUniverse.getDataSource().getResident(player.getName());
nation = resident.getTown().getNation();
double bankcap = TownySettings.getNationBankCap();
if (bankcap > 0) {
if (amount + nation.getHoldingBalance() > bankcap)
throw new TownyException(String.format(TownySettings.getLangString("msg_err_deposit_capped"), bankcap));
}
if (amount < 0)
throw new TownyException(TownySettings.getLangString("msg_err_negative_money"));
if (!resident.payTo(amount, nation, "Nation Deposit"))
throw new TownyException(TownySettings.getLangString("msg_insuf_funds"));
TownyMessaging.sendNationMessage(nation, String.format(TownySettings.getLangString("msg_xx_deposited_xx"), resident.getName(), amount, "nation"));
} catch (TownyException x) {
TownyMessaging.sendErrorMsg(player, x.getMessage());
} catch (EconomyException x) {
TownyMessaging.sendErrorMsg(player, x.getMessage());
}
}
use of com.palmergames.bukkit.towny.exceptions.TownyException in project Towny by ElgarL.
the class NationCommand method parseNationCommand.
public void parseNationCommand(Player player, String[] split) {
String nationCom = "/nation";
try {
if (split.length == 0)
try {
Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
Town town = resident.getTown();
Nation nation = town.getNation();
TownyMessaging.sendMessage(player, TownyFormatter.getStatus(nation));
} catch (NotRegisteredException x) {
TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_dont_belong_nation"));
}
else if (split[0].equalsIgnoreCase("?"))
for (String line : nation_help) player.sendMessage(line);
else if (split[0].equalsIgnoreCase("list")) {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_LIST.getNode()))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
listNations(player);
} else if (split[0].equalsIgnoreCase("new")) {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_NEW.getNode()))
throw new TownyException(TownySettings.getNotPermToNewNationLine());
// newNation(Player,String,Town)
if (split.length == 1)
TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_specify_nation_name"));
else if (split.length == 2) {
Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
if (!resident.isMayor() && !resident.getTown().hasAssistant(resident))
throw new TownyException(TownySettings.getLangString("msg_peasant_right"));
newNation(player, split[1], resident.getTown().getName());
} else {
// TODO: Check if player is an admin
newNation(player, split[1], split[2]);
}
} else if (split[0].equalsIgnoreCase("leave")) {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_LEAVE.getNode()))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
nationLeave(player);
} else if (split[0].equalsIgnoreCase("withdraw")) {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_WITHDRAW.getNode()))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
if (split.length == 2)
try {
nationWithdraw(player, Integer.parseInt(split[1].trim()));
} catch (NumberFormatException e) {
TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_error_must_be_int"));
}
else
TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_must_specify_amnt"), nationCom));
} else if (split[0].equalsIgnoreCase("deposit")) {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_DEPOSIT.getNode()))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
if (split.length == 2)
try {
nationDeposit(player, Integer.parseInt(split[1].trim()));
} catch (NumberFormatException e) {
TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_error_must_be_int"));
}
else
TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_must_specify_amnt"), nationCom + " deposit"));
} else {
String[] newSplit = StringMgmt.remFirstArg(split);
if (split[0].equalsIgnoreCase("rank")) {
/*
* Rank perm tests are performed in the nationrank method.
*/
nationRank(player, newSplit);
} else if (split[0].equalsIgnoreCase("king")) {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_KING.getNode()))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
nationKing(player, newSplit);
} else if (split[0].equalsIgnoreCase("add")) {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_ADD.getNode()))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
nationAdd(player, newSplit);
} else if (split[0].equalsIgnoreCase("kick")) {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_KICK.getNode()))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
nationKick(player, newSplit);
} else if (split[0].equalsIgnoreCase("set")) {
/*
* perm test performed in method.
*/
nationSet(player, newSplit);
} else if (split[0].equalsIgnoreCase("toggle")) {
/*
* perm test performed in method.
*/
nationToggle(player, newSplit);
} else if (split[0].equalsIgnoreCase("ally")) {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_ALLY.getNode()))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
nationAlly(player, newSplit);
} else if (split[0].equalsIgnoreCase("enemy")) {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_ENEMY.getNode()))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
nationEnemy(player, newSplit);
} else if (split[0].equalsIgnoreCase("delete")) {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_DELETE.getNode()))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
nationDelete(player, newSplit);
} else if (split[0].equalsIgnoreCase("online")) {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_ONLINE.getNode()))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
try {
Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
Town town = resident.getTown();
Nation nation = town.getNation();
TownyMessaging.sendMessage(player, TownyFormatter.getFormattedOnlineResidents(TownySettings.getLangString("msg_nation_online"), nation, player));
} catch (NotRegisteredException x) {
TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_dont_belong_nation"));
}
} else
try {
Nation nation = TownyUniverse.getDataSource().getNation(split[0]);
TownyMessaging.sendMessage(player, TownyFormatter.getStatus(nation));
} catch (NotRegisteredException x) {
TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_err_not_registered_1"), split[0]));
}
}
} catch (Exception x) {
TownyMessaging.sendErrorMsg(player, x.getMessage());
}
}
use of com.palmergames.bukkit.towny.exceptions.TownyException in project Towny by ElgarL.
the class NationCommand method nationWithdraw.
private void nationWithdraw(Player player, int amount) {
Resident resident;
Nation nation;
try {
if (!TownySettings.geNationBankAllowWithdrawls())
throw new TownyException(TownySettings.getLangString("msg_err_withdraw_disabled"));
if (amount < 0)
// TODO
throw new TownyException(TownySettings.getLangString("msg_err_negative_money"));
resident = TownyUniverse.getDataSource().getResident(player.getName());
nation = resident.getTown().getNation();
nation.withdrawFromBank(resident, amount);
TownyMessaging.sendNationMessage(nation, String.format(TownySettings.getLangString("msg_xx_withdrew_xx"), resident.getName(), amount, "nation"));
} catch (TownyException x) {
TownyMessaging.sendErrorMsg(player, x.getMessage());
} catch (EconomyException x) {
TownyMessaging.sendErrorMsg(player, x.getMessage());
}
}
use of com.palmergames.bukkit.towny.exceptions.TownyException in project Towny by ElgarL.
the class NationCommand method nationAlly.
public void nationAlly(Player player, String[] split) {
if (split.length < 2) {
TownyMessaging.sendErrorMsg(player, "Eg: /nation ally [add/remove] [name]");
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;
}
ArrayList<Nation> list = new ArrayList<Nation>();
Nation ally;
// test add or remove
String test = split[0];
String[] newSplit = StringMgmt.remFirstArg(split);
if ((test.equalsIgnoreCase("remove") || test.equalsIgnoreCase("add")) && newSplit.length > 0) {
for (String name : newSplit) {
try {
ally = TownyUniverse.getDataSource().getNation(name);
if (nation.equals(ally))
TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_own_nation_disallow"));
else
list.add(ally);
} catch (NotRegisteredException e) {
// Do nothing here as the name doesn't match a Nation
}
}
if (!list.isEmpty())
nationAlly(player, nation, list, test.equalsIgnoreCase("add"));
} else {
TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_err_invalid_property"), "[add/remove]"));
}
}
use of com.palmergames.bukkit.towny.exceptions.TownyException in project Towny by ElgarL.
the class ResidentCommand method residentToggle.
/**
* Toggle modes for this player.
*
* @param player
* @param newSplit
* @throws TownyException
*/
private void residentToggle(Player player, String[] newSplit) throws TownyException {
Resident resident;
try {
resident = TownyUniverse.getDataSource().getResident(player.getName());
} catch (NotRegisteredException e) {
// unknown resident
throw new TownyException(String.format(TownySettings.getLangString("msg_err_not_registered"), player.getName()));
}
if (newSplit.length == 0) {
player.sendMessage(ChatTools.formatTitle("/res toggle"));
player.sendMessage(ChatTools.formatCommand("", "/res toggle", "pvp", ""));
player.sendMessage(ChatTools.formatCommand("", "/res toggle", "fire", ""));
player.sendMessage(ChatTools.formatCommand("", "/res toggle", "mobs", ""));
player.sendMessage(ChatTools.formatCommand("", "/res toggle", "plotborder", ""));
player.sendMessage(ChatTools.formatCommand("", "/res toggle", "spy", ""));
TownyMessaging.sendMsg(resident, ("Modes set: " + StringMgmt.join(resident.getModes(), ",")));
return;
}
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_RESIDENT_TOGGLE.getNode(newSplit[0].toLowerCase())))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
TownyPermission perm = resident.getPermissions();
// Special case chat spy
if (newSplit[0].equalsIgnoreCase("spy")) {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_CHAT_SPY.getNode(newSplit[0].toLowerCase())))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
resident.toggleMode(newSplit, true);
return;
} else if (newSplit[0].equalsIgnoreCase("pvp")) {
perm.pvp = !perm.pvp;
} else if (newSplit[0].equalsIgnoreCase("fire")) {
perm.fire = !perm.fire;
} else if (newSplit[0].equalsIgnoreCase("explosion")) {
perm.explosion = !perm.explosion;
} else if (newSplit[0].equalsIgnoreCase("mobs")) {
perm.mobs = !perm.mobs;
} else {
resident.toggleMode(newSplit, true);
return;
}
notifyPerms(player, perm);
TownyUniverse.getDataSource().saveResident(resident);
}
Aggregations