Fix for data migration.

Overwriting new data with old data because both the file with the
lowercased name and a newer file with correct-cased player name both
exist.
This commit is contained in:
ryanhamshire 2015-01-19 17:57:52 -08:00
parent 14f2486b37
commit 58ea48df06
3 changed files with 21 additions and 0 deletions

View File

@ -129,6 +129,7 @@ public abstract class DataStore
if(UUIDFetcher.lookupCache != null) if(UUIDFetcher.lookupCache != null)
{ {
UUIDFetcher.lookupCache.clear(); UUIDFetcher.lookupCache.clear();
UUIDFetcher.correctedNames.clear();
} }
GriefPrevention.AddLogEntry("Update finished."); GriefPrevention.AddLogEntry("Update finished.");

View File

@ -158,6 +158,17 @@ public class FlatFileDataStore extends DataStore
{ {
String currentFilename = playerFile.getName(); String currentFilename = playerFile.getName();
//if corrected casing and a record already exists using the correct casing, skip this one
String correctedCasing = UUIDFetcher.correctedNames.get(currentFilename);
if(correctedCasing != null)
{
File correctedCasingFile = new File(playerDataFolder.getPath() + File.separator + correctedCasing);
if(correctedCasingFile.exists())
{
continue;
}
}
//try to convert player name to UUID //try to convert player name to UUID
UUID playerID = null; UUID playerID = null;
try try

View File

@ -24,6 +24,9 @@ class UUIDFetcher {
//cache for username -> uuid lookups //cache for username -> uuid lookups
static HashMap<String, UUID> lookupCache; static HashMap<String, UUID> lookupCache;
//record of username -> proper casing updates
static HashMap<String, String> correctedNames;
public UUIDFetcher(List<String> names, boolean rateLimiting) { public UUIDFetcher(List<String> names, boolean rateLimiting) {
this.names = names; this.names = names;
@ -41,6 +44,11 @@ class UUIDFetcher {
lookupCache = new HashMap<String, UUID>(); lookupCache = new HashMap<String, UUID>();
} }
if(correctedNames == null)
{
correctedNames = new HashMap<String, String>();
}
GriefPrevention.AddLogEntry("UUID conversion process started. Please be patient - this may take a while."); GriefPrevention.AddLogEntry("UUID conversion process started. Please be patient - this may take a while.");
//try to get correct casing from local data //try to get correct casing from local data
@ -56,6 +64,7 @@ class UUIDFetcher {
if(!player.getName().equals(name)) if(!player.getName().equals(name))
{ {
GriefPrevention.AddLogEntry(name + " --> " + player.getName()); GriefPrevention.AddLogEntry(name + " --> " + player.getName());
correctedNames.put(name, player.getName());
names.set(i, player.getName()); names.set(i, player.getName());
} }
break; break;