소스 검색

Add saveUserUUIDs to FlatfileDatabaseManager so mcMMO compiles

Minimal changes were made but it hasn't been tested at all and almost certainly doesn't work.
zreed 11 년 전
부모
커밋
384bb6306a
1개의 변경된 파일42개의 추가작업 그리고 0개의 파일을 삭제
  1. 42 0
      src/main/java/com/gmail/nossr50/database/FlatfileDatabaseManager.java

+ 42 - 0
src/main/java/com/gmail/nossr50/database/FlatfileDatabaseManager.java

@@ -535,6 +535,48 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
         return worked;
         return worked;
     }
     }
 
 
+    public boolean saveUserUUIDs(Map<String, UUID> user_data) {
+
+        BufferedReader in = null;
+        FileWriter out = null;
+        String usersFilePath = mcMMO.getUsersFilePath();
+
+        synchronized (fileWritingLock) {
+            try {
+                in = new BufferedReader(new FileReader(usersFilePath));
+                StringBuilder writer = new StringBuilder();
+                String line;
+
+                while (((line = in.readLine()) != null) && !user_data.isEmpty()) {
+                    String[] character = line.split(":");
+                    if (user_data.containsKey(character[0])) {
+                        if (character.length < 42) {
+                            mcMMO.p.getLogger().severe("Could not update UUID for " + character[0] + "!");
+                            mcMMO.p.getLogger().severe("Database entry is invalid.");
+                            return false;
+                        }
+
+                        line = line.replace(character[41], user_data.remove(character[0]).toString());
+                    }
+
+                    writer.append(line).append("\r\n");
+                }
+
+                out = new FileWriter(usersFilePath); // Write out the new file
+                out.write(writer.toString());
+            }
+            catch (Exception e) {
+                mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
+            }
+            finally {
+                tryClose(in);
+                tryClose(out);
+            }
+        }
+
+        return true;
+    }
+
     public List<String> getStoredUsers() {
     public List<String> getStoredUsers() {
         ArrayList<String> users = new ArrayList<String>();
         ArrayList<String> users = new ArrayList<String>();
         BufferedReader in = null;
         BufferedReader in = null;