diff options
author | KHobbits <rob@khobbits.co.uk> | 2014-04-17 02:18:28 +0100 |
---|---|---|
committer | KHobbits <rob@khobbits.co.uk> | 2014-04-17 02:18:28 +0100 |
commit | 6c1dd72fb0f7024134897617a28875980e74d031 (patch) | |
tree | e47f5cf5d54929ecfdad2e05e025b90fe58e45ee | |
parent | 8e5c7b58d6a695bedaee37c17a943342ddbce350 (diff) | |
download | Essentials-6c1dd72fb0f7024134897617a28875980e74d031.tar Essentials-6c1dd72fb0f7024134897617a28875980e74d031.tar.gz Essentials-6c1dd72fb0f7024134897617a28875980e74d031.tar.lz Essentials-6c1dd72fb0f7024134897617a28875980e74d031.tar.xz Essentials-6c1dd72fb0f7024134897617a28875980e74d031.zip |
Add progress status and /ess uuidconvert command for manual conversion.
-rw-r--r-- | Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java | 70 | ||||
-rw-r--r-- | Essentials/src/com/earth2me/essentials/commands/Commandessentials.java | 12 |
2 files changed, 68 insertions, 14 deletions
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java b/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java index b94512676..d701f0459 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java @@ -499,18 +499,44 @@ public class EssentialsUpgrade { return; } + + uuidFileConvert(ess); + + doneFile.setProperty("uuidFileChange", true); + doneFile.save(); + } + + public static void uuidFileConvert(IEssentials ess) + { + ess.getLogger().info("Starting Essentials UUID userdata conversion"); final File userdir = new File(ess.getDataFolder(), "userdata"); if (!userdir.exists()) { return; } + + int countFiles = 0; + int countFails = 0; + + ess.getLogger().info("Found " + userdir.list().length + " files to convert..."); + for (String string : userdir.list()) { if (!string.endsWith(".yml")) { continue; } + + final int showProgress = countFiles % 1000; + + if (showProgress == 0) + { + ess.getLogger().info("Converted " + countFiles + "/" + userdir.list().length); + } + + countFiles++; + final String name = string.substring(0, string.length() - 4); EssentialsUserConf config; UUID uuid = null; @@ -528,31 +554,47 @@ public class EssentialsUpgrade String uuidString = conf.getString("uuid", null); - try - { - uuid = UUID.fromString(uuidString); - } - catch (Exception ex2) - { - org.bukkit.OfflinePlayer player = ess.getServer().getOfflinePlayer(name); - uuid = player.getUniqueId(); - } - - if (uuid == null && conf.getBoolean("npc", false)) + for (int i = 0; i < 4; i++) { - uuid = UUID.randomUUID(); + try + { + uuid = UUID.fromString(uuidString); + break; + } + catch (Exception ex2) + { + org.bukkit.OfflinePlayer player = ess.getServer().getOfflinePlayer(name); + uuid = player.getUniqueId(); + } + + if (uuid != null) + { + break; + } + + if (uuid == null && conf.getBoolean("npc", false)) + { + uuid = UUID.randomUUID(); + break; + } } + if (uuid != null) { config = new EssentialsUserConf(name, uuid, new File(userdir, uuid + ".yml")); config.convertLegacyFile(); ess.getUserMap().trackUUID(uuid, name); + continue; } + countFails++; } } - doneFile.setProperty("uuidFileChange", true); - doneFile.save(); + + ess.getLogger().info("Completed Essentials UUID userdata conversion."); + ess.getLogger().info("Attempted to convert " + countFiles + " users. Failed to convert: " + countFails); + ess.getLogger().info("To rerun the conversion type /essentials uuidconvert"); + } public void beforeSettings() diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java b/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java index 5d1e3d9b7..2a6229fe2 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.CommandSource; +import com.earth2me.essentials.EssentialsUpgrade; import static com.earth2me.essentials.I18n.tl; import com.earth2me.essentials.User; import com.earth2me.essentials.UserMap; @@ -58,6 +59,10 @@ public class Commandessentials extends EssentialsCommand { run_cleanup(server, sender, commandLabel, args); } + else if (args[0].equalsIgnoreCase("uuidconvert")) + { + run_uuidconvert(server, sender, commandLabel, args); + } else { run_reload(server, sender, commandLabel, args); @@ -313,4 +318,11 @@ public class Commandessentials extends EssentialsCommand }); } + + private void run_uuidconvert(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception + { + sender.sendMessage("Starting Essentials UUID userdata conversion, this may lag the server."); + EssentialsUpgrade.uuidFileConvert(ess); + sender.sendMessage("UUID conversion complete, check your server log for more information."); + } } |