Search in sources :

Example 1 with AlreadyRegisteredException

use of com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException in project Towny by ElgarL.

the class TownyWorldListener method newWorld.

private void newWorld(String worldName) {
    // String worldName = event.getWorld().getName();
    try {
        TownyUniverse.getDataSource().newWorld(worldName);
        TownyWorld world = TownyUniverse.getDataSource().getWorld(worldName);
        if (world == null)
            TownyMessaging.sendErrorMsg("Could not create data for " + worldName);
        else {
            if (!TownyUniverse.getDataSource().loadWorld(world)) {
                // First time world has been noticed
                TownyUniverse.getDataSource().saveWorld(world);
            }
        }
    } catch (AlreadyRegisteredException e) {
    // Allready loaded
    } catch (NotRegisteredException e) {
        TownyMessaging.sendErrorMsg("Could not create data for " + worldName);
        e.printStackTrace();
    }
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld)

Example 2 with AlreadyRegisteredException

use of com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException in project Towny by ElgarL.

the class Resident method setTown.

public void setTown(Town town) throws AlreadyRegisteredException {
    if (town == null) {
        this.town = null;
        setTitle("");
        setSurname("");
        updatePerms();
        return;
    }
    if (this.town == town)
        return;
    if (hasTown())
        throw new AlreadyRegisteredException();
    this.town = town;
    setTitle("");
    setSurname("");
    updatePerms();
}
Also used : AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException)

Example 3 with AlreadyRegisteredException

use of com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException in project Towny by ElgarL.

the class Resident method addTownRank.

public boolean addTownRank(String rank) throws AlreadyRegisteredException {
    if (this.hasTown() && TownyPerms.getTownRanks().contains(rank)) {
        if (townRanks.contains(rank))
            throw new AlreadyRegisteredException();
        townRanks.add(rank);
        TownyPerms.assignPermissions(this, null);
        return true;
    }
    return false;
}
Also used : AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException)

Example 4 with AlreadyRegisteredException

use of com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException in project Towny by ElgarL.

the class TownyFlatFileSource method loadWorldList.

@Override
public boolean loadWorldList() {
    if (plugin != null) {
        TownyMessaging.sendDebugMsg("Loading Server World List");
        for (World world : plugin.getServer().getWorlds()) try {
            newWorld(world.getName());
        } catch (AlreadyRegisteredException e) {
        // e.printStackTrace();
        } catch (NotRegisteredException e) {
        // e.printStackTrace();
        }
    }
    // Can no longer reply on Bukkit to report ALL available worlds.
    TownyMessaging.sendDebugMsg("Loading World List");
    String line;
    BufferedReader fin = null;
    try {
        fin = new BufferedReader(new FileReader(rootFolder + dataFolder + FileMgmt.fileSeparator() + "worlds.txt"));
        while ((line = fin.readLine()) != null) if (!line.equals(""))
            newWorld(line);
        return true;
    } catch (AlreadyRegisteredException e) {
        // Ignore this as the world may have been passed to us by bukkit
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    } finally {
        if (fin != null) {
            try {
                fin.close();
            } catch (IOException ignore) {
            }
        }
    }
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException) World(org.bukkit.World) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) 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)

Example 5 with AlreadyRegisteredException

use of com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException in project Towny by ElgarL.

the class TownyFlatFileSource method utilLoadTownBlocks.

/**
 * Load townblocks according to the given line Townblock: x,y,forSale Eg:
 * townBlocks=world:10,11;10,12,true;|nether:1,1|
 *
 * @param line
 * @param town
 * @param resident
 */
@Deprecated
public void utilLoadTownBlocks(String line, Town town, Resident resident) {
    String[] worlds = line.split("\\|");
    for (String w : worlds) {
        String[] split = w.split(":");
        if (split.length != 2) {
            TownyMessaging.sendErrorMsg("[Warning] " + town.getName() + " BlockList does not have a World or data.");
            continue;
        }
        try {
            TownyWorld world = getWorld(split[0]);
            for (String s : split[1].split(";")) {
                String blockTypeData = null;
                int indexOfType = s.indexOf("[");
                if (indexOfType != -1) {
                    // is found
                    int endIndexOfType = s.indexOf("]");
                    if (endIndexOfType != -1) {
                        blockTypeData = s.substring(indexOfType + 1, endIndexOfType);
                    }
                    s = s.substring(endIndexOfType + 1);
                }
                String[] tokens = s.split(",");
                if (tokens.length < 2)
                    continue;
                try {
                    int x = Integer.parseInt(tokens[0]);
                    int z = Integer.parseInt(tokens[1]);
                    try {
                        world.newTownBlock(x, z);
                    } catch (AlreadyRegisteredException e) {
                    }
                    TownBlock townblock = world.getTownBlock(x, z);
                    if (town != null)
                        townblock.setTown(town);
                    if (resident != null && townblock.hasTown())
                        townblock.setResident(resident);
                    if (blockTypeData != null) {
                        utilLoadTownBlockTypeData(townblock, blockTypeData);
                    }
                    // if present set the plot price
                    if (tokens.length >= 3) {
                        if (tokens[2] == "true")
                            townblock.setPlotPrice(town.getPlotPrice());
                        else
                            townblock.setPlotPrice(Double.parseDouble(tokens[2]));
                    }
                } catch (NumberFormatException e) {
                } catch (NotRegisteredException e) {
                }
            }
        } catch (NotRegisteredException e) {
            continue;
        }
    }
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) TownBlock(com.palmergames.bukkit.towny.object.TownBlock)

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