Browse Source

save() added to PlayerProfile, won't compile as is. But this should do the trick for us.

nossr50 14 years ago
parent
commit
3a85abadfa
1 changed files with 28 additions and 1 deletions
  1. 28 1
      vMinecraftUsers.java

+ 28 - 1
vMinecraftUsers.java

@@ -104,7 +104,7 @@ public class vMinecraftUsers {
 //Author:	cerevisiae
 //=====================================================================
 class PlayerList
-{
+{       
 	ArrayList<PlayerProfile> players;
 	
 	//=====================================================================
@@ -235,6 +235,33 @@ class PlayerList
 	        } catch (Exception e) {
 	            log.log(Level.SEVERE, "Exception while reading " + location + " (Are you sure you formatted it correctly?)", e);
 	        }
+            //=====================================================================
+        // Function:    save
+        // Input:       none
+        // Output:      Writes current values of PlayerProfile to disk
+        // Use:         Call this function to save current values
+        //=====================================================================
+        public void save(){
+            try {
+                String location = "vminecraftusers.txt";
+                BufferedWriter bw = new BufferedWriter(new FileWriter(location, true));
+                Scanner scanner = new Scanner(new File(location));
+                while (scanner.hasNextLine()) {
+	                String line = scanner.nextLine();
+	                if (line.startsWith("#") || line.equals("") || line.startsWith("")) {
+	                    continue;
+	                }
+	                String[] split = line.split(":");
+	                if (!split[0].equalsIgnoreCase(playerName.toString())) {
+	                    continue;
+	                }
+	                bw.write(playerName + ":" + nickName + ":" + suffix + ":" + tag + ":" + ignoreList + ":" + aliasList);
+	            }
+	            scanner.close();
+	        } catch (Exception e) {
+	            String location = "vminecraftusers.txt";
+                    log.log(Level.SEVERE, "Exception while writing to " + location + " (Are you sure you formatted it correctly?)", e);
+	        }
 		}
 
 		//=====================================================================