Try to use consistent UUIDs and not rely on Bukkit lookup while saving.

This commit is contained in:
KHobbits 2014-06-07 15:45:57 +01:00
parent 9d9af25c7f
commit 7e9328bd25
4 changed files with 38 additions and 25 deletions

View file

@ -12,8 +12,8 @@ import org.bukkit.Bukkit;
public class EssentialsUserConf extends EssentialsConf
{
final String username;
final UUID uuid;
public final String username;
public final UUID uuid;
public EssentialsUserConf(final String username, final UUID uuid, final File configFile)
{

View file

@ -240,7 +240,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, net.es
{
if (!base.isOnline())
{
this.base = new OfflinePlayer(base.getUniqueId(), ess.getServer());
this.base = new OfflinePlayer(getConfigUUID(), ess.getServer());
}
cleanup();
}

View file

@ -50,7 +50,10 @@ public abstract class UserData extends PlayerExtension implements IConf
{
config.forceSave();
config.getFile().delete();
ess.getUserMap().removeUser(this.getBase().getName());
if (config.username != null)
{
ess.getUserMap().removeUser(config.username);
}
}
public final void cleanup()
@ -838,7 +841,7 @@ public abstract class UserData extends PlayerExtension implements IConf
this.lastAccountName = lastAccountName;
config.setProperty("lastAccountName", lastAccountName);
config.save();
ess.getUserMap().trackUUID(base.getUniqueId(), lastAccountName);
ess.getUserMap().trackUUID(getConfigUUID(), lastAccountName);
}
public void setNPC(boolean set)
@ -968,6 +971,11 @@ public abstract class UserData extends PlayerExtension implements IConf
return new HashMap<String, Object>();
}
public UUID getConfigUUID()
{
return config.uuid;
}
public void save()
{
config.save();

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
@ -109,7 +109,7 @@ public class UserMap extends CacheLoader<String, User> implements IConf
return null;
}
}
public User getUser(final UUID uuid)
{
try
@ -125,7 +125,7 @@ public class UserMap extends CacheLoader<String, User> implements IConf
return null;
}
}
public void trackUUID(final UUID uuid, final String name)
{
if (uuid != null)
@ -142,7 +142,7 @@ public class UserMap extends CacheLoader<String, User> implements IConf
}
}
}
@Override
public User load(final String stringUUID) throws Exception
{
@ -154,9 +154,9 @@ public class UserMap extends CacheLoader<String, User> implements IConf
trackUUID(uuid, user.getName());
return user;
}
final File userFile = getUserFileFromID(uuid);
if (userFile.exists())
{
player = new OfflinePlayer(uuid, ess.getServer());
@ -165,24 +165,29 @@ public class UserMap extends CacheLoader<String, User> implements IConf
trackUUID(uuid, user.getName());
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)
{
ess.getLogger().warning("Name collection is null, cannot remove user.");
return;
}
UUID uuid = names.get(name);
if (uuid != null)
{
@ -192,12 +197,12 @@ 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();
@ -207,28 +212,28 @@ public class UserMap extends CacheLoader<String, User> implements IConf
{
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");