mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-10-31 15:59:40 +01:00
Add progress status and /ess uuidconvert command for manual conversion.
This commit is contained in:
parent
65b1821196
commit
87f90e9bdd
@ -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
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
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))
|
||||
{
|
||||
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()
|
||||
|
@ -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.");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user