use of com.palmergames.util.KeyValueFile in project Towny by ElgarL.
the class TownyFlatFileSource method loadNation.
@Override
public boolean loadNation(Nation nation) {
String line = "";
String[] tokens;
String path = getNationFilename(nation);
File fileResident = new File(path);
if (fileResident.exists() && fileResident.isFile()) {
try {
KeyValueFile kvFile = new KeyValueFile(path);
line = kvFile.get("towns");
if (line != null) {
tokens = line.split(",");
for (String token : tokens) {
if (!token.isEmpty()) {
TownyMessaging.sendDebugMsg("Nation Fetching Town: " + token);
Town town = getTown(token);
if (town != null)
nation.addTown(town);
}
}
}
line = kvFile.get("capital");
if (line != null)
nation.setCapital(getTown(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)
// nation.addAssistant(assistant);
// }
// }
// }
line = kvFile.get("tag");
if (line != null)
try {
nation.setTag(line);
} catch (TownyException e) {
nation.setTag("");
}
line = kvFile.get("allies");
if (line != null) {
tokens = line.split(",");
for (String token : tokens) {
if (!token.isEmpty()) {
Nation friend = getNation(token);
if (friend != null)
//("ally", friend);
nation.addAlly(friend);
}
}
}
line = kvFile.get("enemies");
if (line != null) {
tokens = line.split(",");
for (String token : tokens) {
if (!token.isEmpty()) {
Nation enemy = getNation(token);
if (enemy != null)
//("enemy", enemy);
nation.addEnemy(enemy);
}
}
}
line = kvFile.get("taxes");
if (line != null)
try {
nation.setTaxes(Double.parseDouble(line));
} catch (Exception e) {
nation.setTaxes(0.0);
}
line = kvFile.get("neutral");
if (line != null)
try {
nation.setNeutral(Boolean.parseBoolean(line));
} catch (Exception e) {
}
} catch (Exception e) {
TownyMessaging.sendErrorMsg("Loading Error: Exception while reading nation file " + nation.getName());
return false;
}
return true;
} else
return false;
}
use of com.palmergames.util.KeyValueFile in project Towny by ElgarL.
the class TownyHModFlatFileSource method loadTown.
@Override
public boolean loadTown(Town town) {
System.out.println("[Towny] [hMod Conversion] Town: " + town.getName());
String line;
String[] tokens;
String path = rootFolder + dataFolder + "/towns/" + town.getName() + ".txt";
File fileResident = new File(path);
if (fileResident.exists() && fileResident.isFile()) {
try {
KeyValueFile kvFile = new KeyValueFile(path);
line = kvFile.get("residents");
if (line != null) {
tokens = line.split(",");
for (String token : tokens) {
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) {
// Resident assistant = getResident(token);
// if (assistant != null)
// town.addAssistant(assistant);
// }
// }
town.setTownBoard(kvFile.get("townBoard"));
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(Integer.parseInt(line));
} catch (Exception e) {
town.setPlotPrice(0);
}
line = kvFile.get("taxes");
if (line != null)
try {
town.setTaxes(Integer.parseInt(line));
} catch (Exception e) {
town.setTaxes(0);
}
line = kvFile.get("plotTax");
if (line != null)
try {
town.setPlotTax(Integer.parseInt(line));
} catch (Exception e) {
town.setPlotTax(0);
}
line = kvFile.get("pvp");
if (line != null)
try {
town.setPVP(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("taxpercent");
if (line != null)
try {
town.setTaxPercentage(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) {
}
} catch (Exception e) {
System.out.println("[Towny] Loading Error: Exception while reading town file " + town.getName());
e.printStackTrace();
return false;
}
return true;
} else
return false;
}
use of com.palmergames.util.KeyValueFile in project Towny by ElgarL.
the class TownyFlatFileSource method loadTownBlocks.
@Override
public boolean loadTownBlocks() {
String line = "";
String path;
for (TownBlock townBlock : getAllTownBlocks()) {
path = getTownBlockFilename(townBlock);
//boolean set = false;
File fileTownBlock = new File(path);
if (fileTownBlock.exists() && fileTownBlock.isFile()) {
try {
KeyValueFile kvFile = new KeyValueFile(path);
line = kvFile.get("name");
if (line != null)
try {
townBlock.setName(line.trim());
} catch (Exception e) {
}
line = kvFile.getString("price");
if (line != null)
try {
townBlock.setPlotPrice(Double.parseDouble(line.trim()));
} catch (Exception e) {
}
line = kvFile.getString("town");
if (line != null)
try {
Town town = getTown(line.trim());
townBlock.setTown(town);
} catch (Exception e) {
}
line = kvFile.getString("resident");
if (line != null && !line.isEmpty())
try {
Resident res = getResident(line.trim());
townBlock.setResident(res);
} catch (Exception e) {
}
line = kvFile.getString("type");
if (line != null)
try {
townBlock.setType(Integer.parseInt(line));
} catch (Exception e) {
}
line = kvFile.getString("outpost");
if (line != null)
try {
townBlock.setOutpost(Boolean.parseBoolean(line));
} catch (Exception e) {
}
line = kvFile.get("permissions");
if ((line != null) && !line.isEmpty())
try {
townBlock.setPermissions(line.trim());
//set = true;
} catch (Exception e) {
}
line = kvFile.get("changed");
if (line != null)
try {
townBlock.setChanged(Boolean.parseBoolean(line.trim()));
} catch (Exception e) {
}
line = kvFile.get("locked");
if (line != null)
try {
townBlock.setLocked(Boolean.parseBoolean(line.trim()));
} catch (Exception e) {
}
} catch (Exception e) {
TownyMessaging.sendErrorMsg("Loading Error: Exception while reading TownBlock file " + path);
return false;
}
// if (!set) {
// // no permissions found so set in relation to it's owners perms.
// try {
// if (townBlock.hasResident()) {
// townBlock.setPermissions(townBlock.getResident().getPermissions().toString());
// } else {
// townBlock.setPermissions(townBlock.getTown().getPermissions().toString());
// }
// } catch (NotRegisteredException e) {
// // Will never reach here
// }
// }
}
}
return true;
}
Aggregations