Delay uuidconversion for 10s and show warning.

UUID conversion should now better handle offline conversion.
This commit is contained in:
KHobbits 2014-04-26 23:49:38 +01:00
parent a1cdfa19b0
commit b40aa43872
5 changed files with 154 additions and 13 deletions

View File

@ -102,6 +102,10 @@ public class EssentialsConf extends YamlConfiguration
{
convertLegacyFile();
}
else if (altFileExists())
{
convertAltFile();
}
else if (templateName != null)
{
LOGGER.log(Level.INFO, tl("creatingConfigFromTemplate", configFile.toString()));
@ -193,6 +197,16 @@ public class EssentialsConf extends YamlConfiguration
{
LOGGER.log(Level.SEVERE, "Unable to import legacy config file.");
}
public boolean altFileExists()
{
return false;
}
public void convertAltFile()
{
LOGGER.log(Level.SEVERE, "Unable to import alt config file.");
}
private void createFromTemplate()
{

View File

@ -500,6 +500,58 @@ public class EssentialsUpgrade
{
return;
}
final File userdir = new File(ess.getDataFolder(), "userdata");
if (!userdir.exists())
{
return;
}
int countFiles = 0;
int countReqFiles = 0;
for (String string : userdir.list())
{
if (!string.endsWith(".yml") || string.length() < 5)
{
continue;
}
countFiles++;
final String name = string.substring(0, string.length() - 4);
UUID uuid = null;
try
{
uuid = UUID.fromString(name);
}
catch (IllegalArgumentException ex)
{
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);
}
catch (InterruptedException ex)
{
// NOOP
}
uuidFileConvert(ess);
@ -597,8 +649,8 @@ public class EssentialsUpgrade
}
}
ess.getUserMap().getUUIDMap().forceWriteUUIDMap();
ess.getLogger().info("Completed Essentials UUID userdata conversion. Attempted to convert " + countFiles + " users.");
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

@ -1,8 +1,10 @@
package com.earth2me.essentials;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
import java.io.File;
import java.io.IOException;
import java.util.Locale;
import java.util.UUID;
import java.util.logging.Level;
import org.bukkit.Bukkit;
@ -23,14 +25,14 @@ public class EssentialsUserConf extends EssentialsConf
@Override
public boolean legacyFileExists()
{
File file = new File(configFile.getParentFile(), username + ".yml");
final File file = new File(configFile.getParentFile(), username + ".yml");
return file.exists();
}
@Override
public void convertLegacyFile()
{
File file = new File(configFile.getParentFile(), username + ".yml");
final File file = new File(configFile.getParentFile(), username + ".yml");
try
{
Files.move(file, new File(configFile.getParentFile(), uuid + ".yml"));
@ -42,4 +44,33 @@ public class EssentialsUserConf extends EssentialsConf
setProperty("lastAccountName", username);
}
private File getAltFile()
{
final UUID fn = UUID.nameUUIDFromBytes(("OfflinePlayer:" + username.toLowerCase(Locale.ENGLISH)).getBytes(Charsets.UTF_8));
return new File(configFile.getParentFile(), fn.toString() + ".yml");
}
@Override
public boolean altFileExists()
{
if (username.equals(username.toLowerCase()))
{
return false;
}
return getAltFile().exists();
}
@Override
public void convertAltFile()
{
try
{
Files.move(getAltFile(), new File(configFile.getParentFile(), uuid + ".yml"));
}
catch (IOException ex)
{
Bukkit.getLogger().log(Level.WARNING, "Failed to migrate user: " + username, ex);
}
}
}

View File

@ -8,6 +8,7 @@ import com.earth2me.essentials.UserMap;
import com.earth2me.essentials.metrics.Metrics;
import com.earth2me.essentials.utils.DateUtil;
import com.earth2me.essentials.utils.NumberUtil;
import com.google.common.base.Charsets;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@ -63,6 +64,10 @@ public class Commandessentials extends EssentialsCommand
{
run_uuidconvert(server, sender, commandLabel, args);
}
else if (args[0].equalsIgnoreCase("uuidtest"))
{
run_uuidtest(server, sender, commandLabel, args);
}
else
{
run_reload(server, sender, commandLabel, args);
@ -325,4 +330,32 @@ public class Commandessentials extends EssentialsCommand
EssentialsUpgrade.uuidFileConvert(ess);
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)
{
throw new Exception("/<command> uuidtest <name>");
}
String name = args[1];
sender.sendMessage("Looking up UUID for " + name);
for (Player player : server.getOnlinePlayers())
{
if (player.getName().equalsIgnoreCase(name))
{
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));
sender.sendMessage("NPC UUID: " + npcuuid.toString());
UUID offlineuuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8));
sender.sendMessage("Offline Mode UUID: " + offlineuuid.toString());
}
}

View File

@ -54,7 +54,8 @@ public class Commandseen extends EssentialsCommand
seenIP(server, sender, args[0]);
return;
}
else if (FormatUtil.validIP(args[0]) && (server.getIPBans().contains(args[0]))) {
else if (FormatUtil.validIP(args[0]) && (server.getIPBans().contains(args[0])))
{
sender.sendMessage(tl("isIpBanned", args[0]));
return;
}
@ -72,13 +73,18 @@ public class Commandseen extends EssentialsCommand
user.setDisplayNick();
sender.sendMessage(tl("seenOnline", user.getDisplayName(), DateUtil.formatDateDiff(user.getLastLogin())));
if (ess.getSettings().isDebug())
{
ess.getLogger().info("UUID: " + user.getBase().getUniqueId().toString());
}
List<String> history = ess.getUserMap().getUserHistory(user.getBase().getUniqueId());
if (history != null && history.size() > 1)
{
sender.sendMessage(tl("seenAccounts", StringUtil.joinListSkip(", ", user.getName(), history)));
}
if (user.isAfk())
{
sender.sendMessage(tl("whoisAFK", tl("true")));
@ -86,14 +92,14 @@ public class Commandseen extends EssentialsCommand
if (user.isJailed())
{
sender.sendMessage(tl("whoisJail", (user.getJailTimeout() > 0
? DateUtil.formatDateDiff(user.getJailTimeout())
: tl("true"))));
? DateUtil.formatDateDiff(user.getJailTimeout())
: tl("true"))));
}
if (user.isMuted())
{
sender.sendMessage(tl("whoisMuted", (user.getMuteTimeout() > 0
? DateUtil.formatDateDiff(user.getMuteTimeout())
: tl("true"))));
? DateUtil.formatDateDiff(user.getMuteTimeout())
: tl("true"))));
}
final String location = user.getGeoLocation();
if (location != null && (!(sender.isPlayer()) || ess.getUser(sender.getPlayer()).isAuthorized("essentials.geoip.show")))
@ -117,13 +123,18 @@ public class Commandseen extends EssentialsCommand
{
sender.sendMessage(tl("userUnknown", user.getName()));
}
if (ess.getSettings().isDebug())
{
ess.getLogger().info("UUID: " + user.getBase().getUniqueId().toString());
}
List<String> history = ess.getUserMap().getUserHistory(user.getBase().getUniqueId());
if (history != null && history.size() > 1)
{
sender.sendMessage(tl("seenAccounts", StringUtil.joinListSkip(", ", user.getName(), history)));
}
if (user.getBase().isBanned())
{
sender.sendMessage(tl("whoisBanned", showBan ? user.getBanReason() : tl("true")));