use of com.palmergames.bukkit.towny.object.Resident in project Towny by ElgarL.
the class TownyHModFlatFileSource method loadResident.
/*
* Load individual towny object
*/
@Override
public boolean loadResident(Resident resident) {
System.out.println("[Towny] [hMod Conversion] Resident: " + resident.getName());
String line;
String path = rootFolder + dataFolder + "/residents/" + resident.getName() + ".txt";
File fileResident = new File(path);
if (fileResident.exists() && fileResident.isFile()) {
try {
KeyValueFile kvFile = new KeyValueFile(path);
resident.setLastOnline(Long.parseLong(kvFile.get("lastLogin")));
line = kvFile.get("registered");
if (line != null)
resident.setRegistered(Long.parseLong(line));
else
resident.setRegistered(resident.getLastOnline());
line = kvFile.get("town");
if (line != null)
resident.setTown(getTown(line));
line = kvFile.get("friends");
if (line != null) {
String[] tokens = line.split(",");
for (String token : tokens) {
Resident friend = getResident(token);
if (friend != null)
resident.addFriend(friend);
}
}
} catch (Exception e) {
System.out.println("[Towny] Loading Error: Exception while reading resident file " + resident.getName());
e.printStackTrace();
return false;
}
return true;
} else
return false;
}
use of com.palmergames.bukkit.towny.object.Resident in project Towny by ElgarL.
the class TownySQLSource method loadTownBlocks.
@Override
public boolean loadTownBlocks() {
String line = "";
Boolean result = false;
// Load town blocks
if (!getContext())
return false;
ResultSet rs;
for (TownBlock townBlock : getAllTownBlocks()) {
try {
Statement s = cntx.createStatement();
rs = s.executeQuery("SELECT * FROM " + tb_prefix + "TOWNBLOCKS" + " WHERE world='" + townBlock.getWorld().getName() + "' AND x='" + townBlock.getX() + "' AND z='" + townBlock.getZ() + "'");
while (rs.next()) {
line = rs.getString("name");
if (line != null)
try {
townBlock.setName(line.trim());
} catch (Exception e) {
}
line = rs.getString("price");
if (line != null)
try {
townBlock.setPlotPrice(Float.parseFloat(line.trim()));
} catch (Exception e) {
}
line = rs.getString("town");
if (line != null)
try {
Town town = getTown(line.trim());
townBlock.setTown(town);
} catch (Exception e) {
}
line = rs.getString("resident");
if (line != null && !line.isEmpty())
try {
Resident res = getResident(line.trim());
townBlock.setResident(res);
} catch (Exception e) {
}
line = rs.getString("type");
if (line != null)
try {
townBlock.setType(Integer.parseInt(line));
} catch (Exception e) {
}
line = rs.getString("outpost");
if (line != null)
try {
townBlock.setOutpost(Boolean.parseBoolean(line));
} catch (Exception e) {
}
line = rs.getString("permissions");
if ((line != null) && !line.isEmpty())
try {
townBlock.setPermissions(line.trim().replaceAll("#", ","));
//set = true;
} catch (Exception e) {
}
result = rs.getBoolean("changed");
if (result != null)
try {
townBlock.setChanged(result);
} catch (Exception e) {
}
result = rs.getBoolean("locked");
if (result != null)
try {
townBlock.setLocked(result);
} catch (Exception e) {
}
}
// 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
// }
// }
s.close();
} catch (SQLException e) {
TownyMessaging.sendErrorMsg("Loading Error: Exception while reading TownBlocks ");
e.printStackTrace();
return false;
}
}
return true;
}
use of com.palmergames.bukkit.towny.object.Resident in project Towny by ElgarL.
the class TownySQLSource method loadTown.
@SuppressWarnings("deprecation")
@Override
public boolean loadTown(Town town) {
String line;
String[] tokens;
TownyMessaging.sendDebugMsg("Loading town " + town.getName());
if (!getContext())
return false;
try {
Statement s = cntx.createStatement();
ResultSet rs = s.executeQuery("SELECT * FROM " + tb_prefix + "TOWNS " + " WHERE name='" + town.getName() + "'");
String search;
while (rs.next()) {
line = rs.getString("residents");
if (line != null) {
search = (line.contains("#")) ? "#" : ",";
tokens = line.split(search);
for (String token : tokens) {
if (!token.isEmpty()) {
Resident resident = getResident(token);
if (resident != null)
town.addResident(resident);
}
}
}
town.setMayor(getResident(rs.getString("mayor")));
// line = rs.getString("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(rs.getString("townBoard"));
line = rs.getString("tag");
if (line != null)
try {
town.setTag(line);
} catch (TownyException e) {
town.setTag("");
}
town.setPermissions(rs.getString("protectionStatus").replaceAll("#", ","));
town.setBonusBlocks(rs.getInt("bonus"));
town.setTaxPercentage(rs.getBoolean("taxpercent"));
town.setTaxes(rs.getFloat("taxes"));
town.setHasUpkeep(rs.getBoolean("hasUpkeep"));
town.setPlotPrice(rs.getFloat("plotPrice"));
town.setPlotTax(rs.getFloat("plotTax"));
town.setEmbassyPlotPrice(rs.getFloat("embassyPlotPrice"));
town.setEmbassyPlotTax(rs.getFloat("embassyPlotTax"));
town.setCommercialPlotPrice(rs.getFloat("commercialPlotPrice"));
town.setCommercialPlotTax(rs.getFloat("commercialPlotTax"));
town.setOpen(rs.getBoolean("open"));
town.setPublic(rs.getBoolean("public"));
town.setAdminDisabledPVP(rs.getBoolean("admindisabledpvp"));
town.setPurchasedBlocks(rs.getInt("purchased"));
line = rs.getString("homeBlock");
if (line != null) {
search = (line.contains("#")) ? "#" : ",";
tokens = line.split(search);
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.forceSetHomeBlock(homeBlock);
} catch (NumberFormatException e) {
TownyMessaging.sendErrorMsg("[Warning] " + town.getName() + " homeBlock tried to load invalid location.");
} catch (NotRegisteredException e) {
TownyMessaging.sendErrorMsg("[Warning] " + town.getName() + " homeBlock tried to load invalid TownBlock.");
} catch (TownyException e) {
TownyMessaging.sendErrorMsg("[Warning] " + town.getName() + " does not have a home block.");
}
} catch (NotRegisteredException e) {
TownyMessaging.sendErrorMsg("[Warning] " + town.getName() + " homeBlock tried to load invalid world.");
}
}
line = rs.getString("spawn");
if (line != null) {
search = (line.contains("#")) ? "#" : ",";
tokens = line.split(search);
if (tokens.length >= 4)
try {
World world = plugin.getServerWorld(tokens[0]);
double x = Double.parseDouble(tokens[1]);
double y = Double.parseDouble(tokens[2]);
double z = Double.parseDouble(tokens[3]);
Location loc = new Location(world, x, y, z);
if (tokens.length == 6) {
loc.setPitch(Float.parseFloat(tokens[4]));
loc.setYaw(Float.parseFloat(tokens[5]));
}
town.forceSetSpawn(loc);
} catch (NumberFormatException e) {
} catch (NotRegisteredException e) {
} catch (NullPointerException e) {
}
// Load outpost spawns
line = rs.getString("outpostSpawns");
if (line != null) {
String[] outposts = line.split(";");
for (String spawn : outposts) {
search = (line.contains("#")) ? "#" : ",";
tokens = spawn.split(search);
if (tokens.length >= 4)
try {
World world = plugin.getServerWorld(tokens[0]);
double x = Double.parseDouble(tokens[1]);
double y = Double.parseDouble(tokens[2]);
double z = Double.parseDouble(tokens[3]);
Location loc = new Location(world, x, y, z);
if (tokens.length == 6) {
loc.setPitch(Float.parseFloat(tokens[4]));
loc.setYaw(Float.parseFloat(tokens[5]));
}
town.forceAddOutpostSpawn(loc);
} catch (NumberFormatException e) {
} catch (NotRegisteredException e) {
} catch (NullPointerException e) {
}
}
}
}
/*
* Attempt these for older databases.
*/
try {
line = rs.getString("townBlocks");
if (line != null)
utilLoadTownBlocks(line, town, null);
} catch (SQLException e) {
}
s.close();
return true;
}
s.close();
return false;
} catch (SQLException e) {
TownyMessaging.sendErrorMsg("SQL: Load Town sql Error - " + e.getMessage());
} catch (Exception e) {
TownyMessaging.sendErrorMsg("SQL: Load Town unknown Error - ");
e.printStackTrace();
}
return false;
}
use of com.palmergames.bukkit.towny.object.Resident in project Towny by ElgarL.
the class TownySQLSource method loadResident.
/*
* Load individual towny object
*/
@SuppressWarnings("deprecation")
@Override
public boolean loadResident(Resident resident) {
TownyMessaging.sendDebugMsg("Loading resident " + resident.getName());
if (!getContext())
return false;
try {
Statement s = cntx.createStatement();
ResultSet rs = s.executeQuery("SELECT * FROM " + tb_prefix + "RESIDENTS " + " WHERE name='" + resident.getName() + "'");
String search;
while (rs.next()) {
try {
resident.setLastOnline(rs.getLong("lastOnline"));
} catch (Exception e) {
e.printStackTrace();
}
try {
resident.setRegistered(rs.getLong("registered"));
} catch (Exception e) {
e.printStackTrace();
}
try {
resident.setNPC(rs.getBoolean("isNPC"));
} catch (Exception e) {
e.printStackTrace();
}
try {
resident.setTitle(rs.getString("title"));
} catch (Exception e) {
e.printStackTrace();
}
try {
resident.setSurname(rs.getString("surname"));
} catch (Exception e) {
e.printStackTrace();
}
String line = rs.getString("town");
if ((line != null) && (!line.isEmpty())) {
resident.setTown(getTown(line));
TownyMessaging.sendDebugMsg("Resident " + resident.getName() + " set to Town " + line);
}
line = rs.getString("town-ranks");
if ((line != null) && (!line.isEmpty())) {
search = (line.contains("#")) ? "#" : ",";
resident.setTownRanks(new ArrayList<String>(Arrays.asList((line.split(search)))));
TownyMessaging.sendDebugMsg("Resident " + resident.getName() + " set Town-ranks " + line);
}
line = rs.getString("nation-ranks");
if ((line != null) && (!line.isEmpty())) {
search = (line.contains("#")) ? "#" : ",";
resident.setNationRanks(new ArrayList<String>(Arrays.asList((line.split(search)))));
TownyMessaging.sendDebugMsg("Resident " + resident.getName() + " set Nation-ranks " + line);
}
try {
line = rs.getString("friends");
if (line != null) {
search = (line.contains("#")) ? "#" : ",";
String[] tokens = line.split(search);
for (String token : tokens) {
if (!token.isEmpty()) {
Resident friend = getResident(token);
if (friend != null)
resident.addFriend(friend);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
try {
resident.setPermissions(rs.getString("protectionStatus").replaceAll("#", ","));
} catch (Exception e) {
e.printStackTrace();
}
/*
* Attempt these for older databases.
*/
try {
line = rs.getString("townBlocks");
if ((line != null) && (!line.isEmpty()))
utilLoadTownBlocks(line, null, resident);
} catch (SQLException e) {
}
s.close();
return true;
}
return false;
} catch (SQLException e) {
TownyMessaging.sendErrorMsg("SQL: Load resident sql error : " + e.getMessage());
} catch (Exception e) {
TownyMessaging.sendErrorMsg("SQL: Load resident unknown error");
e.printStackTrace();
}
return false;
}
use of com.palmergames.bukkit.towny.object.Resident in project Towny by ElgarL.
the class TownyFlatFileSource method loadResident.
/*
* Load individual towny object
*/
@Override
public boolean loadResident(Resident resident) {
String line;
String path = getResidentFilename(resident);
File fileResident = new File(path);
if (fileResident.exists() && fileResident.isFile()) {
try {
KeyValueFile kvFile = new KeyValueFile(path);
resident.setLastOnline(Long.parseLong(kvFile.get("lastOnline")));
line = kvFile.get("registered");
if (line != null)
resident.setRegistered(Long.parseLong(line));
else
resident.setRegistered(resident.getLastOnline());
line = kvFile.get("isNPC");
if (line != null)
resident.setNPC(Boolean.parseBoolean(line));
line = kvFile.get("title");
if (line != null)
resident.setTitle(line);
line = kvFile.get("surname");
if (line != null)
resident.setSurname(line);
line = kvFile.get("town");
if (line != null)
resident.setTown(getTown(line));
line = kvFile.get("town-ranks");
if (line != null)
resident.setTownRanks(new ArrayList<String>(Arrays.asList((line.split(",")))));
line = kvFile.get("nation-ranks");
if (line != null)
resident.setNationRanks(new ArrayList<String>(Arrays.asList((line.split(",")))));
line = kvFile.get("friends");
if (line != null) {
String[] tokens = line.split(",");
for (String token : tokens) {
if (!token.isEmpty()) {
Resident friend = getResident(token);
if (friend != null)
resident.addFriend(friend);
}
}
}
line = kvFile.get("protectionStatus");
if (line != null)
resident.setPermissions(line);
line = kvFile.get("townBlocks");
if (line != null)
utilLoadTownBlocks(line, null, resident);
} catch (Exception e) {
TownyMessaging.sendErrorMsg("Loading Error: Exception while reading resident file " + resident.getName());
return false;
}
return true;
} else
return false;
}
Aggregations