Allow disabling userfile cache on uuid convert.

Add "ignore-userfiles-cache: true" to "upgrades-done.yml" to disable cache, forcing uuid lookup requests.
This commit is contained in:
KHobbits 2014-05-04 13:22:33 +01:00
parent 86b57804c6
commit 0364d4e0de
2 changed files with 34 additions and 26 deletions

View File

@ -500,13 +500,15 @@ public class EssentialsUpgrade
{
return;
}
Boolean ignoreUFCache = doneFile.getBoolean("ignore-userfiles-cache", false);
final File userdir = new File(ess.getDataFolder(), "userdata");
if (!userdir.exists())
{
return;
}
int countFiles = 0;
int countReqFiles = 0;
for (String string : userdir.list())
@ -515,12 +517,12 @@ public class EssentialsUpgrade
{
continue;
}
countFiles++;
final String name = string.substring(0, string.length() - 4);
UUID uuid = null;
try
{
uuid = UUID.fromString(name);
@ -529,21 +531,21 @@ public class EssentialsUpgrade
{
countReqFiles++;
}
if (countFiles > 100)
{
break;
}
}
}
if (countReqFiles < 1)
{
return;
}
ess.getLogger().info("#### Starting Essentials UUID userdata conversion in a few seconds. ####");
ess.getLogger().info("We recommend you take a backup of your server before upgrading from the old username system.");
try
{
Thread.sleep(10000);
@ -553,13 +555,13 @@ public class EssentialsUpgrade
// NOOP
}
uuidFileConvert(ess);
uuidFileConvert(ess, ignoreUFCache);
doneFile.setProperty("uuidFileChange", true);
doneFile.save();
}
public static void uuidFileConvert(IEssentials ess)
public static void uuidFileConvert(IEssentials ess, Boolean ignoreUFCache)
{
ess.getLogger().info("Starting Essentials UUID userdata conversion");
@ -607,8 +609,10 @@ public class EssentialsUpgrade
conf.load();
conf.setProperty("lastAccountName", name);
conf.save();
String uuidConf = ignoreUFCache ? "force-uuid" : "uuid";
String uuidString = conf.getString("uuid", null);
String uuidString = conf.getString(uuidConf, null);
for (int i = 0; i < 4; i++)
{
@ -625,7 +629,7 @@ public class EssentialsUpgrade
uuid = UUID.nameUUIDFromBytes(("NPC:" + name).getBytes(Charsets.UTF_8));
break;
}
org.bukkit.OfflinePlayer player = ess.getServer().getOfflinePlayer(name);
uuid = player.getUniqueId();
}
@ -634,7 +638,7 @@ public class EssentialsUpgrade
{
countBukkit++;
break;
}
}
}
if (uuid != null)
@ -649,7 +653,7 @@ public class EssentialsUpgrade
}
}
ess.getUserMap().getUUIDMap().forceWriteUUIDMap();
ess.getLogger().info("Converted " + countFiles + "/" + countFiles + ". Conversion complete.");
ess.getLogger().info("Converted via cache: " + countEssCache + " :: Converted via lookup: " + countBukkit + " :: Failed to convert: " + countFails);
ess.getLogger().info("To rerun the conversion type /essentials uuidconvert");

View File

@ -11,6 +11,7 @@ import com.earth2me.essentials.utils.NumberUtil;
import com.google.common.base.Charsets;
import java.io.IOException;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Material;
@ -299,7 +300,7 @@ public class Commandessentials extends EssentialsCommand
{
user.setLastLogin(currTime);
}
if (user.isNPC())
{
continue;
@ -328,14 +329,17 @@ 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);
Boolean ignoreUFCache = (args.length > 2 && args[1].toLowerCase(Locale.ENGLISH).contains("ignore"));
EssentialsUpgrade.uuidFileConvert(ess, ignoreUFCache);
sender.sendMessage("UUID conversion complete, check your server log for more information.");
}
private void run_uuidtest(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception
{
if (args.length < 2)
@ -344,7 +348,7 @@ public class Commandessentials extends EssentialsCommand
}
String name = args[1];
sender.sendMessage("Looking up UUID for " + name);
for (Player player : server.getOnlinePlayers())
{
if (player.getName().equalsIgnoreCase(name))
@ -352,15 +356,15 @@ public class Commandessentials extends EssentialsCommand
sender.sendMessage("Online player: " + player.getUniqueId().toString());
}
}
org.bukkit.OfflinePlayer player = ess.getServer().getOfflinePlayer(name);
UUID bukkituuid = player.getUniqueId();
sender.sendMessage("Bukkit Lookup: " + bukkituuid.toString());
UUID npcuuid = UUID.nameUUIDFromBytes(("NPC:" + name).getBytes(Charsets.UTF_8));
UUID npcuuid = UUID.nameUUIDFromBytes(("NPC:" + name).getBytes(Charsets.UTF_8));
sender.sendMessage("NPC UUID: " + npcuuid.toString());
UUID offlineuuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8));
sender.sendMessage("Offline Mode UUID: " + offlineuuid.toString());
sender.sendMessage("Offline Mode UUID: " + offlineuuid.toString());
}
}