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();
}
}
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();
}
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;
}
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) {
}
}
}
}
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;
}
}
}
Aggregations