From b40aa438723395f9b56a820447fb74b8ddcb61c3 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Sat, 26 Apr 2014 23:49:38 +0100 Subject: Delay uuidconversion for 10s and show warning. UUID conversion should now better handle offline conversion. --- .../com/earth2me/essentials/EssentialsConf.java | 14 ++++++ .../com/earth2me/essentials/EssentialsUpgrade.java | 56 +++++++++++++++++++++- .../earth2me/essentials/EssentialsUserConf.java | 35 +++++++++++++- .../essentials/commands/Commandessentials.java | 33 +++++++++++++ .../earth2me/essentials/commands/Commandseen.java | 29 +++++++---- 5 files changed, 154 insertions(+), 13 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/EssentialsConf.java b/Essentials/src/com/earth2me/essentials/EssentialsConf.java index 2d5e550ad..2ebb2b53e 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsConf.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsConf.java @@ -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() { diff --git a/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java b/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java index e6704c5fb..75d659915 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java @@ -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"); } diff --git a/Essentials/src/com/earth2me/essentials/EssentialsUserConf.java b/Essentials/src/com/earth2me/essentials/EssentialsUserConf.java index ef5b9f863..f55d2c876 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsUserConf.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsUserConf.java @@ -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); + } + } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java b/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java index 2a6229fe2..5da28f0e7 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java @@ -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("/ uuidtest "); + } + 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()); + } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandseen.java b/Essentials/src/com/earth2me/essentials/commands/Commandseen.java index 9bf924e63..51a03c616 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandseen.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandseen.java @@ -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 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 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"))); -- cgit v1.2.3