use of com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException in project Towny by ElgarL.
the class PlotClaim method residentClaim.
private boolean residentClaim(WorldCoord worldCoord) throws TownyException, EconomyException {
//if (resident.hasTown())
try {
TownBlock townBlock = worldCoord.getTownBlock();
Town town = townBlock.getTown();
if ((resident.hasTown() && (resident.getTown() != town) && (!townBlock.getType().equals(TownBlockType.EMBASSY))) || ((!resident.hasTown()) && (!townBlock.getType().equals(TownBlockType.EMBASSY))))
throw new TownyException(TownySettings.getLangString("msg_err_not_part_town"));
try {
Resident owner = townBlock.getResident();
if (townBlock.getPlotPrice() != -1) {
if (TownySettings.isUsingEconomy() && !resident.payTo(townBlock.getPlotPrice(), owner, "Plot - Buy From Seller"))
throw new TownyException(TownySettings.getLangString("msg_no_money_purchase_plot"));
int maxPlots = TownySettings.getMaxResidentPlots(resident);
if (maxPlots >= 0 && resident.getTownBlocks().size() + 1 > maxPlots)
throw new TownyException(String.format(TownySettings.getLangString("msg_max_plot_own"), maxPlots));
TownyMessaging.sendTownMessage(town, TownySettings.getBuyResidentPlotMsg(resident.getName(), owner.getName(), townBlock.getPlotPrice()));
townBlock.setPlotPrice(-1);
townBlock.setResident(resident);
// Set the plot permissions to mirror the new owners.
townBlock.setType(townBlock.getType());
TownyUniverse.getDataSource().saveResident(owner);
TownyUniverse.getDataSource().saveTownBlock(townBlock);
// Update any caches for this WorldCoord
plugin.updateCache(worldCoord);
return true;
} else if (player.hasPermission(PermissionNodes.TOWNY_COMMAND_PLOT_ASMAYOR.getNode())) {
if (TownySettings.isUsingEconomy() && !town.payTo(0.0, owner, "Plot - Buy Back"))
throw new TownyException(TownySettings.getLangString("msg_town_no_money_purchase_plot"));
TownyMessaging.sendTownMessage(town, TownySettings.getBuyResidentPlotMsg(town.getName(), owner.getName(), 0.0));
townBlock.setResident(null);
townBlock.setPlotPrice(-1);
// Set the plot permissions to mirror the towns.
townBlock.setType(townBlock.getType());
TownyUniverse.getDataSource().saveResident(owner);
// Update the townBlock data file so it's no longer using custom settings.
TownyUniverse.getDataSource().saveTownBlock(townBlock);
return true;
} else {
//Should never reach here.
throw new AlreadyRegisteredException(String.format(TownySettings.getLangString("msg_already_claimed"), owner.getName()));
}
} catch (NotRegisteredException e) {
if (townBlock.getPlotPrice() == -1)
throw new TownyException(TownySettings.getLangString("msg_err_plot_nfs"));
double bankcap = TownySettings.getTownBankCap();
if (bankcap > 0) {
if (townBlock.getPlotPrice() + town.getHoldingBalance() > bankcap)
throw new TownyException(String.format(TownySettings.getLangString("msg_err_deposit_capped"), bankcap));
}
if (TownySettings.isUsingEconomy() && !resident.payTo(townBlock.getPlotPrice(), town, "Plot - Buy From Town"))
throw new TownyException(TownySettings.getLangString("msg_no_money_purchase_plot"));
townBlock.setPlotPrice(-1);
townBlock.setResident(resident);
// Set the plot permissions to mirror the new owners.
townBlock.setType(townBlock.getType());
TownyUniverse.getDataSource().saveTownBlock(townBlock);
return true;
}
} catch (NotRegisteredException e) {
throw new TownyException(TownySettings.getLangString("msg_err_not_part_town"));
}
//else
// throw new TownyException(TownySettings.getLangString("msg_err_not_in_town_claim"));
}
use of com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException in project Towny by ElgarL.
the class Resident method addNationRank.
public boolean addNationRank(String rank) throws AlreadyRegisteredException {
if (this.hasNation() && TownyPerms.getNationRanks().contains(rank)) {
if (nationRanks.contains(rank))
throw new AlreadyRegisteredException();
nationRanks.add(rank);
TownyPerms.assignPermissions(this, null);
return true;
}
return false;
}
use of com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException in project Towny by ElgarL.
the class TownySQLSource method loadNationList.
@Override
public boolean loadNationList() {
TownyMessaging.sendDebugMsg("Loading Nation List");
if (!getContext())
return false;
try {
Statement s = cntx.createStatement();
ResultSet rs = s.executeQuery("SELECT name FROM " + tb_prefix + "NATIONS");
while (rs.next()) {
try {
newNation(rs.getString("name"));
} catch (AlreadyRegisteredException e) {
}
}
s.close();
return true;
} catch (SQLException e) {
TownyMessaging.sendErrorMsg("SQL: nation list sql error : " + e.getMessage());
} catch (Exception e) {
TownyMessaging.sendErrorMsg("SQL: nation list unknown error : ");
e.printStackTrace();
}
return false;
}
use of com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException in project Towny by ElgarL.
the class TownyWorld method addTown.
public void addTown(Town town) throws AlreadyRegisteredException {
if (hasTown(town))
throw new AlreadyRegisteredException();
else {
towns.add(town);
town.setWorld(this);
}
}
use of com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException in project Towny by ElgarL.
the class TownyFlatFileSource method loadResidentList.
@Override
public boolean loadResidentList() {
TownyMessaging.sendDebugMsg("Loading Resident List");
String line;
BufferedReader fin = null;
try {
fin = new BufferedReader(new FileReader(rootFolder + dataFolder + FileMgmt.fileSeparator() + "residents.txt"));
while ((line = fin.readLine()) != null) if (!line.equals(""))
newResident(line);
return true;
} catch (AlreadyRegisteredException e) {
e.printStackTrace();
return false;
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
if (fin != null) {
try {
fin.close();
} catch (IOException ignore) {
}
}
}
}
Aggregations