diff options
author | KHobbits <rob@khobbits.co.uk> | 2014-05-27 18:04:02 +0100 |
---|---|---|
committer | KHobbits <rob@khobbits.co.uk> | 2014-05-27 18:04:02 +0100 |
commit | 9a8dfb8be3cb778bf391b57ea74c702b2da81f8c (patch) | |
tree | b3891220d05bda70cb3187c3dcf1c5415f0dc283 | |
parent | e8b39f7e3c39269d54ef1b9e88725c3b315aa3b1 (diff) | |
download | Essentials-9a8dfb8be3cb778bf391b57ea74c702b2da81f8c.tar Essentials-9a8dfb8be3cb778bf391b57ea74c702b2da81f8c.tar.gz Essentials-9a8dfb8be3cb778bf391b57ea74c702b2da81f8c.tar.lz Essentials-9a8dfb8be3cb778bf391b57ea74c702b2da81f8c.tar.xz Essentials-9a8dfb8be3cb778bf391b57ea74c702b2da81f8c.zip |
Remove online player lookup in usermap.getUUIDMap(), throw log entry on failback.
-rw-r--r-- | Essentials/src/com/earth2me/essentials/UserMap.java | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/Essentials/src/com/earth2me/essentials/UserMap.java b/Essentials/src/com/earth2me/essentials/UserMap.java index 50bbb8ff9..84ae92aee 100644 --- a/Essentials/src/com/earth2me/essentials/UserMap.java +++ b/Essentials/src/com/earth2me/essentials/UserMap.java @@ -4,6 +4,9 @@ import com.earth2me.essentials.utils.StringUtil; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; +import com.google.common.cache.RemovalCause; +import com.google.common.cache.RemovalListener; +import com.google.common.cache.RemovalNotification; import com.google.common.util.concurrent.UncheckedExecutionException; import java.io.File; import java.util.ArrayList; @@ -33,6 +36,8 @@ public class UserMap extends CacheLoader<UUID, User> implements IConf super(); this.ess = ess; uuidMap = new UUIDMap(ess); + //RemovalListener<UUID, User> remListener = new UserMapRemovalListener(); + //users = CacheBuilder.newBuilder().maximumSize(ess.getSettings().getMaxUserCacheCount()).softValues().removalListener(remListener).build(this); users = CacheBuilder.newBuilder().maximumSize(ess.getSettings().getMaxUserCacheCount()).softValues().build(this); } @@ -89,21 +94,11 @@ public class UserMap extends CacheLoader<UUID, User> implements IConf final UUID uuid = names.get(sanitizedName); return users.get(uuid); } - - for (Player player : ess.getServer().getOnlinePlayers()) - { - String sanitizedPlayer = StringUtil.safeString(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()) { + ess.getLogger().info("Importing user " + name + " to usermap."); User user = new User(new OfflinePlayer(sanitizedName, ess.getServer()), ess); trackUUID(user.getBase().getUniqueId(), user.getName()); return user; @@ -185,6 +180,11 @@ public class UserMap extends CacheLoader<UUID, User> implements IConf loadAllUsersAsync(ess); } + public void invalidateAll() + { + users.invalidateAll(); + } + public void removeUser(final String name) { UUID uuid = names.get(name); @@ -238,4 +238,16 @@ public class UserMap extends CacheLoader<UUID, User> implements IConf final File userFolder = new File(ess.getDataFolder(), "userdata"); return new File(userFolder, StringUtil.sanitizeFileName(name) + ".yml"); } +// class UserMapRemovalListener implements RemovalListener +// { +// @Override +// public void onRemoval(final RemovalNotification notification) +// { +// Object value = notification.getValue(); +// if (value != null) +// { +// ((User)value).cleanup(); +// } +// } +// } } |