Search in sources :

Example 21 with AlreadyRegisteredException

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"));
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Town(com.palmergames.bukkit.towny.object.Town) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException) Resident(com.palmergames.bukkit.towny.object.Resident) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 22 with AlreadyRegisteredException

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;
}
Also used : AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException)

Example 23 with AlreadyRegisteredException

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;
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException) ResultSet(java.sql.ResultSet) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) SQLException(java.sql.SQLException) IOException(java.io.IOException) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 24 with AlreadyRegisteredException

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);
    }
}
Also used : AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException)

Example 25 with AlreadyRegisteredException

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) {
            }
        }
    }
}
Also used : AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) IOException(java.io.IOException) EOFException(java.io.EOFException) FileNotFoundException(java.io.FileNotFoundException) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException) InvalidNameException(javax.naming.InvalidNameException) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Aggregations

AlreadyRegisteredException (com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException)27 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)21 TownyException (com.palmergames.bukkit.towny.exceptions.TownyException)15 IOException (java.io.IOException)12 TownyWorld (com.palmergames.bukkit.towny.object.TownyWorld)8 InvalidNameException (javax.naming.InvalidNameException)7 Resident (com.palmergames.bukkit.towny.object.Resident)6 BufferedReader (java.io.BufferedReader)6 EOFException (java.io.EOFException)6 FileNotFoundException (java.io.FileNotFoundException)6 FileReader (java.io.FileReader)6 Town (com.palmergames.bukkit.towny.object.Town)5 PreparedStatement (java.sql.PreparedStatement)5 ResultSet (java.sql.ResultSet)5 SQLException (java.sql.SQLException)5 Statement (java.sql.Statement)5 ArrayList (java.util.ArrayList)5 TownBlock (com.palmergames.bukkit.towny.object.TownBlock)4 World (org.bukkit.World)3 Nation (com.palmergames.bukkit.towny.object.Nation)2