From 384bb6306acab30c1f5cd5442db46d3987127d04 Mon Sep 17 00:00:00 2001 From: zreed Date: Wed, 23 Jul 2014 16:50:32 -0400 Subject: [PATCH] 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. --- .../database/FlatfileDatabaseManager.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/main/java/com/gmail/nossr50/database/FlatfileDatabaseManager.java b/src/main/java/com/gmail/nossr50/database/FlatfileDatabaseManager.java index daa14b962..8b9120b8a 100644 --- a/src/main/java/com/gmail/nossr50/database/FlatfileDatabaseManager.java +++ b/src/main/java/com/gmail/nossr50/database/FlatfileDatabaseManager.java @@ -535,6 +535,48 @@ public final class FlatfileDatabaseManager implements DatabaseManager { return worked; } + public boolean saveUserUUIDs(Map 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 getStoredUsers() { ArrayList users = new ArrayList(); BufferedReader in = null;