Also update flatfile with uuids

This commit is contained in:
TfT_02 2014-07-23 23:34:11 +02:00
parent 384bb6306a
commit 7118f8850d
3 changed files with 14 additions and 8 deletions

View File

@ -27,6 +27,7 @@ import com.gmail.nossr50.datatypes.database.UpgradeType;
import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.AbilityType; import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType; 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.Misc;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.StringUtils;
@ -45,6 +46,10 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
usersFile = new File(mcMMO.getUsersFilePath()); usersFile = new File(mcMMO.getUsersFilePath());
checkStructure(); checkStructure();
updateLeaderboards(); updateLeaderboards();
if (mcMMO.getUpgradeManager().shouldUpgrade(UpgradeType.ADD_UUIDS)) {
new UUIDUpdateAsyncTask(mcMMO.p, getStoredUsers()).runTaskAsynchronously(mcMMO.p);
}
} }
public void purgePowerlessUsers() { public void purgePowerlessUsers() {

View File

@ -16,7 +16,7 @@ import com.gmail.nossr50.util.uuid.UUIDFetcher;
public class UUIDUpdateAsyncTask extends BukkitRunnable { public class UUIDUpdateAsyncTask extends BukkitRunnable {
private mcMMO plugin; 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<String> userNames; private List<String> userNames;
private int size; private int size;
@ -28,13 +28,11 @@ public class UUIDUpdateAsyncTask extends BukkitRunnable {
this.userNames = userNames; this.userNames = userNames;
this.checkedUsers = 0; this.checkedUsers = 0;
this.startMillis = System.currentTimeMillis();
} }
@Override @Override
public void run() { public void run() {
startMillis = System.currentTimeMillis();
size = userNames.size(); size = userNames.size();
plugin.getLogger().info("Starting to check and update UUIDs, total amount of users: " + 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<String> userNamesSection; List<String> userNamesSection;
Map<String,UUID> fetchedUUIDs = new HashMap<String,UUID>(); Map<String,UUID> fetchedUUIDs = new HashMap<String,UUID>();
while (!userNames.isEmpty()) { while (size != 0) {
if (size > MAX_LOOKUP) { if (size > MAX_LOOKUP) {
userNamesSection = userNames.subList(size - MAX_LOOKUP, size); userNamesSection = userNames.subList(size - MAX_LOOKUP, size);
size -= MAX_LOOKUP;
} }
else { else {
userNamesSection = userNames.subList(0, size); userNamesSection = userNames.subList(0, size);
size = 0;
} }
try { try {
fetchedUUIDs.putAll(new UUIDFetcher(userNamesSection).call()); fetchedUUIDs.putAll(new UUIDFetcher(userNamesSection).call());
} }
catch (Exception ex) { catch (Exception e) {
plugin.getLogger().severe("Unable to fetch UUIDs!");
return; return;
} }
@ -69,6 +69,7 @@ public class UUIDUpdateAsyncTask extends BukkitRunnable {
if (mcMMO.getDatabaseManager().saveUserUUIDs(fetchedUUIDs)) { if (mcMMO.getDatabaseManager().saveUserUUIDs(fetchedUUIDs)) {
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_UUIDS); mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_UUIDS);
plugin.getLogger().info("UUID upgrade completed!");
} }
} }
} }

View File

@ -15,4 +15,4 @@ Options:
# The interval at which the server updates a couple of users to get their UUID, in seconds # The interval at which the server updates a couple of users to get their UUID, in seconds
UUIDConvertInterval: 30 UUIDConvertInterval: 30
# Amount of users to convert every interval # Amount of users to convert every interval
UUIDConvertAmount: 5 UUIDConvertAmount: 100