Don't allow old UUID's to accidentally overwrite current UUID for user mapping.

Add some extra logging and uuid debug.
This commit is contained in:
KHobbits 2014-06-07 18:08:25 +01:00
parent 3887fdd47d
commit 2215b0f53f
5 changed files with 59 additions and 31 deletions

View File

@ -646,7 +646,7 @@ public class EssentialsUpgrade
conf.forceSave();
config = new EssentialsUserConf(name, uuid, new File(userdir, uuid + ".yml"));
config.convertLegacyFile();
ess.getUserMap().trackUUID(uuid, name);
ess.getUserMap().trackUUID(uuid, name, false);
continue;
}
countFails++;

View File

@ -841,7 +841,7 @@ public abstract class UserData extends PlayerExtension implements IConf
this.lastAccountName = lastAccountName;
config.setProperty("lastAccountName", lastAccountName);
config.save();
ess.getUserMap().trackUUID(getConfigUUID(), lastAccountName);
ess.getUserMap().trackUUID(getConfigUUID(), lastAccountName, true);
}
public void setNPC(boolean set)

View File

@ -29,7 +29,7 @@ public class UserMap extends CacheLoader<String, User> implements IConf
private final transient ConcurrentSkipListMap<String, UUID> names = new ConcurrentSkipListMap<String, UUID>();
private final transient ConcurrentSkipListMap<UUID, ArrayList<String>> history = new ConcurrentSkipListMap<UUID, ArrayList<String>>();
private UUIDMap uuidMap;
public UserMap(final IEssentials ess)
{
super();
@ -39,7 +39,7 @@ public class UserMap extends CacheLoader<String, User> implements IConf
//users = CacheBuilder.newBuilder().maximumSize(ess.getSettings().getMaxUserCacheCount()).softValues().removalListener(remListener).build(this);
users = CacheBuilder.newBuilder().maximumSize(ess.getSettings().getMaxUserCacheCount()).softValues().build(this);
}
private void loadAllUsersAsync(final IEssentials ess)
{
ess.runTaskAsynchronously(new Runnable()
@ -77,12 +77,12 @@ public class UserMap extends CacheLoader<String, User> implements IConf
}
});
}
public boolean userExists(final UUID uuid)
{
return keys.contains(uuid);
}
public User getUser(final String name)
{
try
@ -93,13 +93,13 @@ public class UserMap extends CacheLoader<String, User> implements IConf
final UUID uuid = names.get(sanitizedName);
return getUser(uuid);
}
final File userFile = getUserFileFromString(sanitizedName);
if (userFile.exists())
{
ess.getLogger().info("Importing user " + name + " to usermap.");
User user = new User(new OfflinePlayer(sanitizedName, ess.getServer()), ess);
trackUUID(user.getBase().getUniqueId(), user.getName());
trackUUID(user.getBase().getUniqueId(), user.getName(), true);
return user;
}
return null;
@ -109,7 +109,7 @@ public class UserMap extends CacheLoader<String, User> implements IConf
return null;
}
}
public User getUser(final UUID uuid)
{
try
@ -125,8 +125,8 @@ public class UserMap extends CacheLoader<String, User> implements IConf
return null;
}
}
public void trackUUID(final UUID uuid, final String name)
public void trackUUID(final UUID uuid, final String name, boolean replace)
{
if (uuid != null)
{
@ -134,15 +134,31 @@ public class UserMap extends CacheLoader<String, User> implements IConf
if (name != null && name.length() > 0)
{
final String keyName = StringUtil.safeString(name);
if (!names.containsKey(keyName) || !names.get(keyName).equals(uuid))
if (!names.containsKey(keyName))
{
names.put(keyName, uuid);
uuidMap.writeUUIDMap();
}
else if (!names.get(keyName).equals(uuid))
{
if (replace)
{
ess.getLogger().info("Found new UUID for " + name + ". Replacing " + names.get(keyName).toString() + " with " + uuid.toString());
names.put(keyName, uuid);
uuidMap.writeUUIDMap();
}
else
{
if (ess.getSettings().isDebug())
{
ess.getLogger().info("Found old UUID for " + name + ". Not adding to usermap.");
}
}
}
}
}
}
@Override
public User load(final String stringUUID) throws Exception
{
@ -151,36 +167,36 @@ public class UserMap extends CacheLoader<String, User> implements IConf
if (player != null)
{
final User user = new User(player, ess);
trackUUID(uuid, user.getName());
trackUUID(uuid, user.getName(), true);
return user;
}
final File userFile = getUserFileFromID(uuid);
if (userFile.exists())
{
player = new OfflinePlayer(uuid, ess.getServer());
final User user = new User(player, ess);
((OfflinePlayer)player).setName(user.getLastAccountName());
trackUUID(uuid, user.getName());
trackUUID(uuid, user.getName(), false);
return user;
}
throw new Exception("User not found!");
}
@Override
public void reloadConfig()
{
getUUIDMap().forceWriteUUIDMap();
loadAllUsersAsync(ess);
}
public void invalidateAll()
{
users.invalidateAll();
}
public void removeUser(final String name)
{
if (names == null)
@ -197,43 +213,43 @@ public class UserMap extends CacheLoader<String, User> implements IConf
names.remove(name);
names.remove(StringUtil.safeString(name));
}
public Set<UUID> getAllUniqueUsers()
{
return Collections.unmodifiableSet(keys.clone());
}
public int getUniqueUsers()
{
return keys.size();
}
protected ConcurrentSkipListMap<String, UUID> getNames()
{
return names;
}
protected ConcurrentSkipListMap<UUID, ArrayList<String>> getHistory()
{
return history;
}
public List<String> getUserHistory(final UUID uuid)
{
return history.get(uuid);
}
public UUIDMap getUUIDMap()
{
return uuidMap;
}
private File getUserFileFromID(final UUID uuid)
{
final File userFolder = new File(ess.getDataFolder(), "userdata");
return new File(userFolder, uuid.toString() + ".yml");
}
public File getUserFileFromString(final String name)
{
final File userFolder = new File(ess.getDataFolder(), "userdata");

View File

@ -64,7 +64,7 @@ public class Economy
npcConfig.setProperty("lastAccountName", name);
npcConfig.setProperty("money", ess.getSettings().getStartingBalance());
npcConfig.forceSave();
ess.getUserMap().trackUUID(npcUUID, name);
ess.getUserMap().trackUUID(npcUUID, name, true);
}
private static void deleteNPC(String name)

View File

@ -355,15 +355,27 @@ public class Commandessentials extends EssentialsCommand
{
if (player.getName().equalsIgnoreCase(name))
{
sender.sendMessage("Online player: " + player.getUniqueId().toString());
onlineUUID = player.getUniqueId();
break;
}
}
UUID essUUID = ess.getUserMap().getUser(name).getConfigUUID();
org.bukkit.OfflinePlayer player = ess.getServer().getOfflinePlayer(name);
UUID bukkituuid = player.getUniqueId();
sender.sendMessage("Bukkit Lookup: " + bukkituuid.toString());
if (onlineUUID != null && onlineUUID != bukkituuid)
{
sender.sendMessage("Online player: " + onlineUUID.toString());
}
if (essUUID != null && essUUID != bukkituuid)
{
sender.sendMessage("Essentials config: " + essUUID.toString());
}
UUID npcuuid = UUID.nameUUIDFromBytes(("NPC:" + name).getBytes(Charsets.UTF_8));
sender.sendMessage("NPC UUID: " + npcuuid.toString());