String[] tokens;
String path = getTownFilename(town);
File fileTown = new File(path);
if (fileTown.exists() && fileTown.isFile()) {
try {
KeyValueFile kvFile = new KeyValueFile(path);
line = kvFile.get("residents");
if (line != null) {
tokens = line.split(",");
for (String token : tokens) {
if (!token.isEmpty()){
Resident resident = getResident(token);
if (resident != null)
town.addResident(resident);
}
}
}
line = kvFile.get("mayor");
if (line != null)
town.setMayor(getResident(line));
line = kvFile.get("assistants");
if (line != null) {
tokens = line.split(",");
for (String token : tokens) {
if (!token.isEmpty()){
Resident assistant = getResident(token);
if ((assistant != null) && (town.hasResident(assistant)))
town.addAssistant(assistant);
}
}
}
town.setTownBoard(kvFile.get("townBoard"));
line = kvFile.get("tag");
if (line != null)
try {
town.setTag(line);
} catch(TownyException e) {
town.setTag("");
}
line = kvFile.get("protectionStatus");
if (line != null)
town.setPermissions(line);
line = kvFile.get("bonusBlocks");
if (line != null)
try {
town.setBonusBlocks(Integer.parseInt(line));
} catch (Exception e) {
town.setBonusBlocks(0);
}
line = kvFile.get("purchasedBlocks");
if (line != null)
try {
town.setPurchasedBlocks(Integer.parseInt(line));
} catch (Exception e) {
town.setPurchasedBlocks(0);
}
line = kvFile.get("plotPrice");
if (line != null)
try {
town.setPlotPrice(Double.parseDouble(line));
} catch (Exception e) {
town.setPlotPrice(0);
}
line = kvFile.get("hasUpkeep");
if (line != null)
try {
town.setHasUpkeep(Boolean.parseBoolean(line));
} catch (NumberFormatException nfe) {
} catch (Exception e) {
}
line = kvFile.get("taxpercent");
if (line != null)
try {
town.setTaxPercentage(Boolean.parseBoolean(line));
} catch (NumberFormatException nfe) {
} catch (Exception e) {
}
line = kvFile.get("taxes");
if (line != null)
try {
town.setTaxes(Double.parseDouble(line));
} catch (Exception e) {
town.setTaxes(0);
}
line = kvFile.get("plotTax");
if (line != null)
try {
town.setPlotTax(Double.parseDouble(line));
} catch (Exception e) {
town.setPlotTax(0);
}
line = kvFile.get("commercialPlotPrice");
if (line != null)
try {
town.setCommercialPlotPrice(Double.parseDouble(line));
} catch (Exception e) {
town.setCommercialPlotPrice(0);
}
line = kvFile.get("commercialPlotTax");
if (line != null)
try {
town.setCommercialPlotTax(Double.parseDouble(line));
} catch (Exception e) {
town.setCommercialPlotTax(0);
}
line = kvFile.get("embassyPlotPrice");
if (line != null)
try {
town.setEmbassyPlotPrice(Double.parseDouble(line));
} catch (Exception e) {
town.setEmbassyPlotPrice(0);
}
line = kvFile.get("embassyPlotTax");
if (line != null)
try {
town.setEmbassyPlotTax(Double.parseDouble(line));
} catch (Exception e) {
town.setEmbassyPlotTax(0);
}
/*
line = kvFile.get("pvp");
if (line != null)
try {
town.setPVP(Boolean.parseBoolean(line));
} catch (NumberFormatException nfe) {
} catch (Exception e) {
}
line = kvFile.get("mobs");
if (line != null)
try {
town.setHasMobs(Boolean.parseBoolean(line));
} catch (NumberFormatException nfe) {
} catch (Exception e) {
}
*/
line = kvFile.get("open");
if (line != null)
try {
town.setOpen(Boolean.parseBoolean(line));
} catch (NumberFormatException nfe) {
} catch (Exception e) {
}
line = kvFile.get("public");
if (line != null)
try {
town.setPublic(Boolean.parseBoolean(line));
} catch (NumberFormatException nfe) {
} catch (Exception e) {
}
/*
line = kvFile.get("explosion");
if (line != null)
try {
town.setBANG(Boolean.parseBoolean(line));
} catch (NumberFormatException nfe) {
} catch (Exception e) {
}
line = kvFile.get("fire");
if (line != null)
try {
town.setFire(Boolean.parseBoolean(line));
} catch (NumberFormatException nfe) {
} catch (Exception e) {
}
*/
line = kvFile.get("townBlocks");
if (line != null)
utilLoadTownBlocks(line, town, null);
line = kvFile.get("homeBlock");
if (line != null) {
tokens = line.split(",");
if (tokens.length == 3)
try {
TownyWorld world = getWorld(tokens[0]);
try {
int x = Integer.parseInt(tokens[1]);
int z = Integer.parseInt(tokens[2]);
TownBlock homeBlock = world.getTownBlock(x, z);
town.setHomeBlock(homeBlock);
} catch (NumberFormatException e) {
System.out.println("[Towny] [Warning] " + town.getName() + " homeBlock tried to load invalid location.");
} catch (NotRegisteredException e) {
System.out.println("[Towny] [Warning] " + town.getName() + " homeBlock tried to load invalid TownBlock.");
} catch (TownyException e) {
System.out.println("[Towny] [Warning] " + town.getName() + " does not have a home block.");
}
} catch (NotRegisteredException e) {
System.out.println("[Towny] [Warning] " + town.getName() + " homeBlock tried to load invalid world.");
}
}
line = kvFile.get("spawn");
if (line != null) {
tokens = line.split(",");
if (tokens.length >= 4)
try {
World world = plugin.getServerWorld(tokens[0]);