Use strings for cachemap key, should prevent accidental key issues.

This commit is contained in:
KHobbits 2014-06-01 21:50:24 +01:00
parent 812de5c35c
commit 3a50850734

View File

@ -18,14 +18,13 @@ import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.ConcurrentSkipListSet; import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import net.ess3.api.IEssentials; import net.ess3.api.IEssentials;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class UserMap extends CacheLoader<UUID, User> implements IConf public class UserMap extends CacheLoader<String, User> implements IConf
{ {
private final transient IEssentials ess; private final transient IEssentials ess;
private final transient Cache<UUID, User> users; private final transient Cache<String, User> users;
private final transient ConcurrentSkipListSet<UUID> keys = new ConcurrentSkipListSet<UUID>(); private final transient ConcurrentSkipListSet<UUID> keys = new ConcurrentSkipListSet<UUID>();
private final transient ConcurrentSkipListMap<String, UUID> names = new ConcurrentSkipListMap<String, UUID>(); 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 final transient ConcurrentSkipListMap<UUID, ArrayList<String>> history = new ConcurrentSkipListMap<UUID, ArrayList<String>>();
@ -92,7 +91,7 @@ public class UserMap extends CacheLoader<UUID, User> implements IConf
if (names.containsKey(sanitizedName)) if (names.containsKey(sanitizedName))
{ {
final UUID uuid = names.get(sanitizedName); final UUID uuid = names.get(sanitizedName);
return users.get(uuid); return getUser(uuid);
} }
final File userFile = getUserFileFromString(sanitizedName); final File userFile = getUserFileFromString(sanitizedName);
@ -105,10 +104,6 @@ public class UserMap extends CacheLoader<UUID, User> implements IConf
} }
return null; return null;
} }
catch (ExecutionException ex)
{
return null;
}
catch (UncheckedExecutionException ex) catch (UncheckedExecutionException ex)
{ {
return null; return null;
@ -119,7 +114,7 @@ public class UserMap extends CacheLoader<UUID, User> implements IConf
{ {
try try
{ {
return users.get(uuid); return users.get(uuid.toString());
} }
catch (ExecutionException ex) catch (ExecutionException ex)
{ {
@ -149,8 +144,9 @@ public class UserMap extends CacheLoader<UUID, User> implements IConf
} }
@Override @Override
public User load(final UUID uuid) throws Exception public User load(final String stringUUID) throws Exception
{ {
UUID uuid = UUID.fromString(stringUUID);
Player player = ess.getServer().getPlayer(uuid); Player player = ess.getServer().getPlayer(uuid);
if (player != null) if (player != null)
{ {