diff options
author | KHobbits <rob@khobbits.co.uk> | 2014-04-15 00:07:35 +0100 |
---|---|---|
committer | KHobbits <rob@khobbits.co.uk> | 2014-04-15 00:07:35 +0100 |
commit | 3dbf69f163c85a7ed4010fe9cfc9e0cbb7d38951 (patch) | |
tree | b28b9cc9d9e2248b26567ddff9e669ac254442f8 /Essentials | |
parent | e8ace540367401d4ab10a52ecdac69103b356cb5 (diff) | |
download | Essentials-3dbf69f163c85a7ed4010fe9cfc9e0cbb7d38951.tar Essentials-3dbf69f163c85a7ed4010fe9cfc9e0cbb7d38951.tar.gz Essentials-3dbf69f163c85a7ed4010fe9cfc9e0cbb7d38951.tar.lz Essentials-3dbf69f163c85a7ed4010fe9cfc9e0cbb7d38951.tar.xz Essentials-3dbf69f163c85a7ed4010fe9cfc9e0cbb7d38951.zip |
Allow usermap to support legacy users, and restore ability to create user on first access, as well as server join.
Diffstat (limited to 'Essentials')
-rw-r--r-- | Essentials/src/com/earth2me/essentials/UserMap.java | 46 |
1 files changed, 38 insertions, 8 deletions
diff --git a/Essentials/src/com/earth2me/essentials/UserMap.java b/Essentials/src/com/earth2me/essentials/UserMap.java index 1c81aa5a1..951c92125 100644 --- a/Essentials/src/com/earth2me/essentials/UserMap.java +++ b/Essentials/src/com/earth2me/essentials/UserMap.java @@ -127,16 +127,33 @@ public class UserMap extends CacheLoader<UUID, User> implements IConf public User getUser(final String name) { try - { + { final String sanitizedName = StringUtil.sanitizeFileName(name); if (names.containsKey(sanitizedName)) { - ess.getLogger().info("Trying to grab user via string, found matching key."); final UUID uuid = names.get(sanitizedName); return users.get(uuid); } - ess.getLogger().info("Trying to grab user via string, failed, returning null."); - return null; // TODO: THIS IS PROBABLY NOT RIGHT + + for (Player player : ess.getServer().getOnlinePlayers()) + { + String sanitizedPlayer = StringUtil.sanitizeFileName(player.getName()); + if (sanitizedPlayer.equalsIgnoreCase(sanitizedName)) + { + User user = new User(player, ess); + trackUUID(user.getBase().getUniqueId(), user.getName()); + return new User(player, ess); + } + } + + final File userFile = getUserFileFromString(sanitizedName); + if (userFile.exists()) + { + User user = new User(new OfflinePlayer(sanitizedName, ess.getServer()), ess); + trackUUID(user.getBase().getUniqueId(), user.getName()); + return user; + } + return null; } catch (ExecutionException ex) { @@ -166,8 +183,12 @@ public class UserMap extends CacheLoader<UUID, User> implements IConf public void trackUUID(final UUID uuid, final String name) { - names.put(StringUtil.sanitizeFileName(name), uuid); - writeUUIDMap(); + if (uuid != null) + { + names.put(StringUtil.sanitizeFileName(name), uuid); + keys.add(uuid); + writeUUIDMap(); + } } public void writeUUIDMap() @@ -221,8 +242,11 @@ public class UserMap extends CacheLoader<UUID, User> implements IConf public void removeUser(final String name) { UUID uuid = names.get(name); - keys.remove(uuid); - users.invalidate(uuid); + if (uuid != null) + { + keys.remove(uuid); + users.invalidate(uuid); + } names.remove(name); names.remove(StringUtil.sanitizeFileName(name)); } @@ -242,4 +266,10 @@ public class UserMap extends CacheLoader<UUID, User> implements IConf 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"); + return new File(userFolder, StringUtil.sanitizeFileName(name) + ".yml"); + } } |