From bab99babccd398ac0e50dbfb8ae065b3944a7bc5 Mon Sep 17 00:00:00 2001 From: TfT_02 Date: Wed, 23 Jul 2014 23:34:11 +0200 Subject: [PATCH] Also update flatfile with uuids --- .../nossr50/database/FlatfileDatabaseManager.java | 7 +++++++ .../runnables/database/UUIDUpdateAsyncTask.java | 15 ++++++++------- src/main/resources/hidden.yml | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/database/FlatfileDatabaseManager.java b/src/main/java/com/gmail/nossr50/database/FlatfileDatabaseManager.java index 8b9120b8a..3f2faaa6a 100644 --- a/src/main/java/com/gmail/nossr50/database/FlatfileDatabaseManager.java +++ b/src/main/java/com/gmail/nossr50/database/FlatfileDatabaseManager.java @@ -27,6 +27,7 @@ import com.gmail.nossr50.datatypes.database.UpgradeType; import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.datatypes.skills.AbilityType; import com.gmail.nossr50.datatypes.skills.SkillType; +import com.gmail.nossr50.runnables.database.UUIDUpdateAsyncTask; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.StringUtils; @@ -45,6 +46,12 @@ public final class FlatfileDatabaseManager implements DatabaseManager { usersFile = new File(mcMMO.getUsersFilePath()); checkStructure(); updateLeaderboards(); + + if (mcMMO.getUpgradeManager().shouldUpgrade(UpgradeType.ADD_UUIDS)) { + List storedUsers = getStoredUsers(); + System.out.println("storedUsers.size() " + storedUsers.size()); + new UUIDUpdateAsyncTask(mcMMO.p, storedUsers).runTaskAsynchronously(mcMMO.p); + } } public void purgePowerlessUsers() { diff --git a/src/main/java/com/gmail/nossr50/runnables/database/UUIDUpdateAsyncTask.java b/src/main/java/com/gmail/nossr50/runnables/database/UUIDUpdateAsyncTask.java index 7d03a8efd..c7ffc2fbb 100644 --- a/src/main/java/com/gmail/nossr50/runnables/database/UUIDUpdateAsyncTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/database/UUIDUpdateAsyncTask.java @@ -16,7 +16,7 @@ import com.gmail.nossr50.util.uuid.UUIDFetcher; public class UUIDUpdateAsyncTask extends BukkitRunnable { private mcMMO plugin; - private static final int MAX_LOOKUP = HiddenConfig.getInstance().getUUIDConvertAmount(); + private static final int MAX_LOOKUP = Math.max(HiddenConfig.getInstance().getUUIDConvertAmount(), 100); private List userNames; private int size; @@ -28,13 +28,11 @@ public class UUIDUpdateAsyncTask extends BukkitRunnable { this.userNames = userNames; this.checkedUsers = 0; + this.startMillis = System.currentTimeMillis(); } @Override public void run() { - - startMillis = System.currentTimeMillis(); - size = userNames.size(); plugin.getLogger().info("Starting to check and update UUIDs, total amount of users: " + size); @@ -42,19 +40,21 @@ public class UUIDUpdateAsyncTask extends BukkitRunnable { List userNamesSection; Map fetchedUUIDs = new HashMap(); - while (!userNames.isEmpty()) { - + while (size != 0) { if (size > MAX_LOOKUP) { userNamesSection = userNames.subList(size - MAX_LOOKUP, size); + size -= MAX_LOOKUP; } else { userNamesSection = userNames.subList(0, size); + size = 0; } try { fetchedUUIDs.putAll(new UUIDFetcher(userNamesSection).call()); } - catch (Exception ex) { + catch (Exception e) { + plugin.getLogger().severe("Unable to fetch UUIDs!"); return; } @@ -69,6 +69,7 @@ public class UUIDUpdateAsyncTask extends BukkitRunnable { if (mcMMO.getDatabaseManager().saveUserUUIDs(fetchedUUIDs)) { mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_UUIDS); + plugin.getLogger().info("UUID upgrade completed!"); } } } diff --git a/src/main/resources/hidden.yml b/src/main/resources/hidden.yml index abc7a5ba9..4f7349691 100644 --- a/src/main/resources/hidden.yml +++ b/src/main/resources/hidden.yml @@ -15,4 +15,4 @@ Options: # The interval at which the server updates a couple of users to get their UUID, in seconds UUIDConvertInterval: 30 # Amount of users to convert every interval - UUIDConvertAmount: 5 + UUIDConvertAmount: 100