diff --git a/Essentials/src/main/java/com/earth2me/essentials/Essentials.java b/Essentials/src/main/java/com/earth2me/essentials/Essentials.java index c9369255d..75692e220 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Essentials.java @@ -1074,6 +1074,11 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials { LOGGER.log(Level.INFO, "Constructing new userfile from base player " + base.getName()); } user = userMap.loadUncachedUser(base); + + // The above method will end up creating a new user, but it will not be added to the cache. + // Since we already call UserMap#getUser() above, we are already okay with adding the user to the cache, + // so we need to manually add the user to the cache in order to avoid a memory leak and maintain behavior. + userMap.addCachedUser(user); } else { user.update(base); } diff --git a/Essentials/src/main/java/com/earth2me/essentials/userstorage/ModernUserMap.java b/Essentials/src/main/java/com/earth2me/essentials/userstorage/ModernUserMap.java index 2ea21e487..56e4d5e32 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/userstorage/ModernUserMap.java +++ b/Essentials/src/main/java/com/earth2me/essentials/userstorage/ModernUserMap.java @@ -149,6 +149,10 @@ public class ModernUserMap extends CacheLoader implements IUserMap { return null; } + public void addCachedUser(final User user) { + userCache.put(user.getUUID(), user); + } + @Override public Map getNameCache() { return uuidCache.getNameCache();