Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int load(Player player) throws Exception {
- List<String> fileLine = new ArrayList<String>();
- File file = new File("./data/characters/" + player.getUsername() + ".txt");
- // Checks if character file exits
- if (!file.exists()) {
- return 2;
- }
- BufferedReader reader = new BufferedReader(new FileReader("./data/characters/" + player.getUsername() + ".txt"));
- String line = reader.readLine();
- // Reads each line of file and adds it to a list
- while (line != null) {
- fileLine.add(line);
- line = reader.readLine();
- }
- String[] currentLine;
- String lineType;
- // Validate password
- for (int i = 0; i < fileLine.size(); i++) {
- currentLine = fileLine.get(i).split(" ");
- lineType = currentLine[0];
- if (lineType.equalsIgnoreCase("PASSWORD")) {
- if (currentLine[2].equals(player.getPassword()))
- break;
- else
- reader.close();
- return 3;
- }
- }
- // Iterate through list and defines player variables
- try {
- for (int i = 0; i < fileLine.size(); i++) {
- currentLine = fileLine.get(i).split(" ");
- lineType = currentLine[0];
- switch (lineType) {
- case "USERNAME":
- player.setUsername(currentLine[2]);
- break;
- case "PASSWORD":
- player.setPassword(currentLine[2]);
- break;
- case "DISPLAY_NAME":
- player.setDisplayName(currentLine[2]);
- break;
- case "USERGROUP":
- player.setStaffRights(Integer.parseInt(currentLine[2]));
- break;
- }
- }
- } catch (Exception e) {
- reader.close();
- return 24;
- }
- reader.close();
- return 2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement