From 87f90e9bdd95e0c2254a4fadcbdc4b02ea983ae3 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Thu, 17 Apr 2014 02:18:28 +0100 Subject: Add progress status and /ess uuidconvert command for manual conversion. --- .../com/earth2me/essentials/EssentialsUpgrade.java | 70 +++++++++++++++++----- .../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."); + } } -- cgit v1.2.3