mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2024-07-07 04:55:10 +00:00
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:
parent
86b57804c6
commit
0364d4e0de
|
@ -500,13 +500,15 @@ public class EssentialsUpgrade
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Boolean ignoreUFCache = doneFile.getBoolean("ignore-userfiles-cache", false);
|
||||||
|
|
||||||
final File userdir = new File(ess.getDataFolder(), "userdata");
|
final File userdir = new File(ess.getDataFolder(), "userdata");
|
||||||
if (!userdir.exists())
|
if (!userdir.exists())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int countFiles = 0;
|
int countFiles = 0;
|
||||||
int countReqFiles = 0;
|
int countReqFiles = 0;
|
||||||
for (String string : userdir.list())
|
for (String string : userdir.list())
|
||||||
|
@ -515,12 +517,12 @@ public class EssentialsUpgrade
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
countFiles++;
|
countFiles++;
|
||||||
|
|
||||||
final String name = string.substring(0, string.length() - 4);
|
final String name = string.substring(0, string.length() - 4);
|
||||||
UUID uuid = null;
|
UUID uuid = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
uuid = UUID.fromString(name);
|
uuid = UUID.fromString(name);
|
||||||
|
@ -529,21 +531,21 @@ public class EssentialsUpgrade
|
||||||
{
|
{
|
||||||
countReqFiles++;
|
countReqFiles++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (countFiles > 100)
|
if (countFiles > 100)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (countReqFiles < 1)
|
if (countReqFiles < 1)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ess.getLogger().info("#### Starting Essentials UUID userdata conversion in a few seconds. ####");
|
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.");
|
ess.getLogger().info("We recommend you take a backup of your server before upgrading from the old username system.");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Thread.sleep(10000);
|
Thread.sleep(10000);
|
||||||
|
@ -553,13 +555,13 @@ public class EssentialsUpgrade
|
||||||
// NOOP
|
// NOOP
|
||||||
}
|
}
|
||||||
|
|
||||||
uuidFileConvert(ess);
|
uuidFileConvert(ess, ignoreUFCache);
|
||||||
|
|
||||||
doneFile.setProperty("uuidFileChange", true);
|
doneFile.setProperty("uuidFileChange", true);
|
||||||
doneFile.save();
|
doneFile.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void uuidFileConvert(IEssentials ess)
|
public static void uuidFileConvert(IEssentials ess, Boolean ignoreUFCache)
|
||||||
{
|
{
|
||||||
ess.getLogger().info("Starting Essentials UUID userdata conversion");
|
ess.getLogger().info("Starting Essentials UUID userdata conversion");
|
||||||
|
|
||||||
|
@ -607,8 +609,10 @@ public class EssentialsUpgrade
|
||||||
conf.load();
|
conf.load();
|
||||||
conf.setProperty("lastAccountName", name);
|
conf.setProperty("lastAccountName", name);
|
||||||
conf.save();
|
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++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
|
@ -625,7 +629,7 @@ public class EssentialsUpgrade
|
||||||
uuid = UUID.nameUUIDFromBytes(("NPC:" + name).getBytes(Charsets.UTF_8));
|
uuid = UUID.nameUUIDFromBytes(("NPC:" + name).getBytes(Charsets.UTF_8));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
org.bukkit.OfflinePlayer player = ess.getServer().getOfflinePlayer(name);
|
org.bukkit.OfflinePlayer player = ess.getServer().getOfflinePlayer(name);
|
||||||
uuid = player.getUniqueId();
|
uuid = player.getUniqueId();
|
||||||
}
|
}
|
||||||
|
@ -634,7 +638,7 @@ public class EssentialsUpgrade
|
||||||
{
|
{
|
||||||
countBukkit++;
|
countBukkit++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uuid != null)
|
if (uuid != null)
|
||||||
|
@ -649,7 +653,7 @@ public class EssentialsUpgrade
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ess.getUserMap().getUUIDMap().forceWriteUUIDMap();
|
ess.getUserMap().getUUIDMap().forceWriteUUIDMap();
|
||||||
|
|
||||||
ess.getLogger().info("Converted " + countFiles + "/" + countFiles + ". Conversion complete.");
|
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("Converted via cache: " + countEssCache + " :: Converted via lookup: " + countBukkit + " :: Failed to convert: " + countFails);
|
||||||
ess.getLogger().info("To rerun the conversion type /essentials uuidconvert");
|
ess.getLogger().info("To rerun the conversion type /essentials uuidconvert");
|
||||||
|
|
|
@ -11,6 +11,7 @@ import com.earth2me.essentials.utils.NumberUtil;
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
@ -299,7 +300,7 @@ public class Commandessentials extends EssentialsCommand
|
||||||
{
|
{
|
||||||
user.setLastLogin(currTime);
|
user.setLastLogin(currTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user.isNPC())
|
if (user.isNPC())
|
||||||
{
|
{
|
||||||
continue;
|
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
|
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.");
|
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.");
|
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
|
private void run_uuidtest(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception
|
||||||
{
|
{
|
||||||
if (args.length < 2)
|
if (args.length < 2)
|
||||||
|
@ -344,7 +348,7 @@ public class Commandessentials extends EssentialsCommand
|
||||||
}
|
}
|
||||||
String name = args[1];
|
String name = args[1];
|
||||||
sender.sendMessage("Looking up UUID for " + name);
|
sender.sendMessage("Looking up UUID for " + name);
|
||||||
|
|
||||||
for (Player player : server.getOnlinePlayers())
|
for (Player player : server.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
if (player.getName().equalsIgnoreCase(name))
|
if (player.getName().equalsIgnoreCase(name))
|
||||||
|
@ -352,15 +356,15 @@ public class Commandessentials extends EssentialsCommand
|
||||||
sender.sendMessage("Online player: " + player.getUniqueId().toString());
|
sender.sendMessage("Online player: " + player.getUniqueId().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
org.bukkit.OfflinePlayer player = ess.getServer().getOfflinePlayer(name);
|
org.bukkit.OfflinePlayer player = ess.getServer().getOfflinePlayer(name);
|
||||||
UUID bukkituuid = player.getUniqueId();
|
UUID bukkituuid = player.getUniqueId();
|
||||||
sender.sendMessage("Bukkit Lookup: " + bukkituuid.toString());
|
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());
|
sender.sendMessage("NPC UUID: " + npcuuid.toString());
|
||||||
|
|
||||||
UUID offlineuuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8));
|
UUID offlineuuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8));
|
||||||
sender.sendMessage("Offline Mode UUID: " + offlineuuid.toString());
|
sender.sendMessage("Offline Mode UUID: " + offlineuuid.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue