Search in sources :

Example 1 with KeyValueFile

use of com.palmergames.util.KeyValueFile 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;
}
Also used : ArrayList(java.util.ArrayList) Resident(com.palmergames.bukkit.towny.object.Resident) KeyValueFile(com.palmergames.util.KeyValueFile) File(java.io.File) KeyValueFile(com.palmergames.util.KeyValueFile) 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 2 with KeyValueFile

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;
}
Also used : Nation(com.palmergames.bukkit.towny.object.Nation) Town(com.palmergames.bukkit.towny.object.Town) KeyValueFile(com.palmergames.util.KeyValueFile) File(java.io.File) KeyValueFile(com.palmergames.util.KeyValueFile) 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) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 3 with KeyValueFile

use of com.palmergames.util.KeyValueFile in project Towny by ElgarL.

the class TownyFlatFileSource method loadTown.

@Override
public boolean loadTown(Town town) {
    String line;
    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()) {
                        TownyMessaging.sendDebugMsg("Town Fetching Resident: " + token);
                        Resident resident = getResident(token);
                        if (resident != null) {
                            try {
                                town.addResident(resident);
                            } catch (AlreadyRegisteredException e) {
                                TownyMessaging.sendErrorMsg("Loading Error: " + resident.getName() + " is already a member of a town (" + resident.getTown().getName() + ").");
                            }
                        }
                    }
                }
            }
            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("adminDisabledPvP");
            if (line != null)
                try {
                    town.setAdminDisabledPVP(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.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 = kvFile.get("spawn");
            if (line != null) {
                tokens = line.split(",");
                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 = kvFile.get("outpostspawns");
            if (line != null) {
                String[] outposts = line.split(";");
                for (String spawn : outposts) {
                    tokens = spawn.split(",");
                    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) {
                        }
                }
            }
        } catch (Exception e) {
            TownyMessaging.sendErrorMsg("Loading Error: Exception while reading town file " + town.getName());
            return false;
        }
        return true;
    } else
        return false;
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException) KeyValueFile(com.palmergames.util.KeyValueFile) 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) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException) Resident(com.palmergames.bukkit.towny.object.Resident) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) File(java.io.File) KeyValueFile(com.palmergames.util.KeyValueFile) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) Location(org.bukkit.Location)

Example 4 with KeyValueFile

use of com.palmergames.util.KeyValueFile in project Towny by ElgarL.

the class TownyFlatFileSource method loadWorld.

@Override
public boolean loadWorld(TownyWorld world) {
    String line = "";
    String[] tokens;
    String path = getWorldFilename(world);
    // create the world file if it doesn't exist
    try {
        FileMgmt.checkFiles(new String[] { path });
    } catch (IOException e1) {
        TownyMessaging.sendErrorMsg("Loading Error: Exception while reading file " + path);
    }
    File fileWorld = new File(path);
    if (fileWorld.exists() && fileWorld.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("World Fetching Town: " + token);
                        Town town = getTown(token);
                        if (town != null) {
                            town.setWorld(world);
                        // world.addTown(town); not needed as it's handled in the Town object
                        }
                    }
                }
            }
            line = kvFile.get("claimable");
            if (line != null)
                try {
                    world.setClaimable(Boolean.parseBoolean(line));
                } catch (Exception e) {
                }
            line = kvFile.get("pvp");
            if (line != null)
                try {
                    world.setPVP(Boolean.parseBoolean(line));
                } catch (Exception e) {
                }
            line = kvFile.get("forcepvp");
            if (line != null)
                try {
                    world.setForcePVP(Boolean.parseBoolean(line));
                } catch (Exception e) {
                }
            line = kvFile.get("forcetownmobs");
            if (line != null)
                try {
                    world.setForceTownMobs(Boolean.parseBoolean(line));
                } catch (Exception e) {
                }
            line = kvFile.get("worldmobs");
            if (line != null)
                try {
                    world.setWorldMobs(Boolean.parseBoolean(line));
                } catch (Exception e) {
                }
            line = kvFile.get("firespread");
            if (line != null)
                try {
                    world.setFire(Boolean.parseBoolean(line));
                } catch (Exception e) {
                }
            line = kvFile.get("forcefirespread");
            if (line != null)
                try {
                    world.setForceFire(Boolean.parseBoolean(line));
                } catch (Exception e) {
                }
            line = kvFile.get("explosions");
            if (line != null)
                try {
                    world.setExpl(Boolean.parseBoolean(line));
                } catch (Exception e) {
                }
            line = kvFile.get("forceexplosions");
            if (line != null)
                try {
                    world.setForceExpl(Boolean.parseBoolean(line));
                } catch (Exception e) {
                }
            line = kvFile.get("endermanprotect");
            if (line != null)
                try {
                    world.setEndermanProtect(Boolean.parseBoolean(line));
                } catch (Exception e) {
                }
            line = kvFile.get("disableplayertrample");
            if (line != null)
                try {
                    world.setDisablePlayerTrample(Boolean.parseBoolean(line));
                } catch (Exception e) {
                }
            line = kvFile.get("disablecreaturetrample");
            if (line != null)
                try {
                    world.setDisableCreatureTrample(Boolean.parseBoolean(line));
                } catch (Exception e) {
                }
            line = kvFile.get("unclaimedZoneBuild");
            if (line != null)
                try {
                    world.setUnclaimedZoneBuild(Boolean.parseBoolean(line));
                } catch (Exception e) {
                }
            line = kvFile.get("unclaimedZoneDestroy");
            if (line != null)
                try {
                    world.setUnclaimedZoneDestroy(Boolean.parseBoolean(line));
                } catch (Exception e) {
                }
            line = kvFile.get("unclaimedZoneSwitch");
            if (line != null)
                try {
                    world.setUnclaimedZoneSwitch(Boolean.parseBoolean(line));
                } catch (Exception e) {
                }
            line = kvFile.get("unclaimedZoneItemUse");
            if (line != null)
                try {
                    world.setUnclaimedZoneItemUse(Boolean.parseBoolean(line));
                } catch (Exception e) {
                }
            line = kvFile.get("unclaimedZoneName");
            if (line != null)
                try {
                    world.setUnclaimedZoneName(line);
                } catch (Exception e) {
                }
            line = kvFile.get("unclaimedZoneIgnoreIds");
            if (line != null)
                try {
                    List<String> mats = new ArrayList<String>();
                    for (String s : line.split(",")) if (!s.isEmpty())
                        try {
                            int id = Integer.parseInt(s);
                            mats.add(BukkitTools.getMaterial(id).name());
                        } catch (NumberFormatException e) {
                            mats.add(s);
                        }
                    world.setUnclaimedZoneIgnore(mats);
                } catch (Exception e) {
                }
            line = kvFile.get("usingPlotManagementDelete");
            if (line != null)
                try {
                    world.setUsingPlotManagementDelete(Boolean.parseBoolean(line));
                } catch (Exception e) {
                }
            line = kvFile.get("plotManagementDeleteIds");
            if (line != null)
                try {
                    // List<Integer> nums = new ArrayList<Integer>();
                    List<String> mats = new ArrayList<String>();
                    for (String s : line.split(",")) if (!s.isEmpty())
                        try {
                            int id = Integer.parseInt(s);
                            mats.add(BukkitTools.getMaterial(id).name());
                        } catch (NumberFormatException e) {
                            mats.add(s);
                        }
                    world.setPlotManagementDeleteIds(mats);
                } catch (Exception e) {
                }
            line = kvFile.get("usingPlotManagementMayorDelete");
            if (line != null)
                try {
                    world.setUsingPlotManagementMayorDelete(Boolean.parseBoolean(line));
                } catch (Exception e) {
                }
            line = kvFile.get("plotManagementMayorDelete");
            if (line != null)
                try {
                    List<String> materials = new ArrayList<String>();
                    for (String s : line.split(",")) if (!s.isEmpty())
                        try {
                            materials.add(s.toUpperCase().trim());
                        } catch (NumberFormatException e) {
                        }
                    world.setPlotManagementMayorDelete(materials);
                } catch (Exception e) {
                }
            line = kvFile.get("usingPlotManagementRevert");
            if (line != null)
                try {
                    world.setUsingPlotManagementRevert(Boolean.parseBoolean(line));
                } catch (Exception e) {
                }
            line = kvFile.get("usingPlotManagementRevertSpeed");
            if (line != null)
                try {
                    world.setPlotManagementRevertSpeed(Long.parseLong(line));
                } catch (Exception e) {
                }
            line = kvFile.get("plotManagementIgnoreIds");
            if (line != null)
                try {
                    List<String> mats = new ArrayList<String>();
                    for (String s : line.split(",")) if (!s.isEmpty())
                        try {
                            int id = Integer.parseInt(s);
                            mats.add(BukkitTools.getMaterial(id).name());
                        } catch (NumberFormatException e) {
                            mats.add(s);
                        }
                    world.setPlotManagementIgnoreIds(mats);
                } catch (Exception e) {
                }
            line = kvFile.get("usingPlotManagementWildRegen");
            if (line != null)
                try {
                    world.setUsingPlotManagementWildRevert(Boolean.parseBoolean(line));
                } catch (Exception e) {
                }
            line = kvFile.get("PlotManagementWildRegenEntities");
            if (line != null)
                try {
                    List<String> entities = new ArrayList<String>();
                    for (String s : line.split(",")) if (!s.isEmpty())
                        try {
                            entities.add(s.trim());
                        } catch (NumberFormatException e) {
                        }
                    world.setPlotManagementWildRevertEntities(entities);
                } catch (Exception e) {
                }
            line = kvFile.get("usingPlotManagementWildRegenDelay");
            if (line != null)
                try {
                    world.setPlotManagementWildRevertDelay(Long.parseLong(line));
                } catch (Exception e) {
                }
            line = kvFile.get("usingTowny");
            if (line != null)
                try {
                    world.setUsingTowny(Boolean.parseBoolean(line));
                } catch (Exception e) {
                }
        // loadTownBlocks(world);
        } catch (Exception e) {
            TownyMessaging.sendErrorMsg("Loading Error: Exception while reading world file " + path);
            return false;
        }
        return true;
    } else {
        TownyMessaging.sendErrorMsg("Loading Error: File error while reading " + world.getName());
        return false;
    }
}
Also used : Town(com.palmergames.bukkit.towny.object.Town) KeyValueFile(com.palmergames.util.KeyValueFile) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) File(java.io.File) KeyValueFile(com.palmergames.util.KeyValueFile) 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 KeyValueFile

use of com.palmergames.util.KeyValueFile 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;
}
Also used : Resident(com.palmergames.bukkit.towny.object.Resident) KeyValueFile(com.palmergames.util.KeyValueFile) File(java.io.File) KeyValueFile(com.palmergames.util.KeyValueFile) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) IOException(java.io.IOException) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException)

Aggregations

AlreadyRegisteredException (com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException)8 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)8 KeyValueFile (com.palmergames.util.KeyValueFile)8 File (java.io.File)8 IOException (java.io.IOException)8 TownyException (com.palmergames.bukkit.towny.exceptions.TownyException)5 Resident (com.palmergames.bukkit.towny.object.Resident)5 EOFException (java.io.EOFException)5 FileNotFoundException (java.io.FileNotFoundException)5 InvalidNameException (javax.naming.InvalidNameException)5 Town (com.palmergames.bukkit.towny.object.Town)4 Nation (com.palmergames.bukkit.towny.object.Nation)2 TownBlock (com.palmergames.bukkit.towny.object.TownBlock)2 ArrayList (java.util.ArrayList)2 TownyWorld (com.palmergames.bukkit.towny.object.TownyWorld)1 List (java.util.List)1 Location (org.bukkit.Location)1 World (org.bukkit.World)1