Fix Essentials#getUser not caching newly created NPC users (#5129)

This commit is contained in:
Josh Roy 2022-10-10 20:36:33 -04:00 committed by GitHub
parent f7cbc7b0d3
commit e91ce0c44c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -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()); LOGGER.log(Level.INFO, "Constructing new userfile from base player " + base.getName());
} }
user = userMap.loadUncachedUser(base); 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 { } else {
user.update(base); user.update(base);
} }

View File

@ -149,6 +149,10 @@ public class ModernUserMap extends CacheLoader<UUID, User> implements IUserMap {
return null; return null;
} }
public void addCachedUser(final User user) {
userCache.put(user.getUUID(), user);
}
@Override @Override
public Map<String, UUID> getNameCache() { public Map<String, UUID> getNameCache() {
return uuidCache.getNameCache(); return uuidCache.getNameCache();