Skip to content

Maintain strong reference for online users #6247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.earth2me.essentials.textreader.KeywordReplacer;
import com.earth2me.essentials.textreader.TextInput;
import com.earth2me.essentials.textreader.TextPager;
import com.earth2me.essentials.userstorage.ModernUserMap;
import com.earth2me.essentials.utils.AdventureUtil;
import com.earth2me.essentials.utils.CommonPlaceholders;
import com.earth2me.essentials.utils.DateUtil;
Expand Down Expand Up @@ -345,6 +346,7 @@ public void delayedJoin(final Player player, final String message) {

ess.getBackup().onPlayerJoin();
final User dUser = ess.getUser(player);
((ModernUserMap) ess.getUsers()).getOnlineUserCache().put(player.getUniqueId(), dUser);
dUser.update(player);

dUser.startTransaction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public final void reset() {

public final void cleanup() {
config.blockingSave();
ess.getUsers().invalidate(getConfigUUID());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class ModernUserMap extends CacheLoader<UUID, User> implements IUserMap {
private final transient IEssentials ess;
private final transient ModernUUIDCache uuidCache;
private final transient LoadingCache<UUID, User> userCache;
private final transient ConcurrentMap<UUID, User> onlineUserCache;

private final boolean debugPrintStackWithWarn;
private final long debugMaxWarnsPerType;
Expand All @@ -50,6 +51,7 @@ public ModernUserMap(final IEssentials ess) {
this.debugPrintStackWithWarn = Boolean.parseBoolean(printStackProperty);
this.debugLogCache = Boolean.parseBoolean(logCacheProperty);
this.debugNonPlayerWarnCounts = new ConcurrentHashMap<>();
this.onlineUserCache = new ConcurrentHashMap<>();
}

@Override
Expand Down Expand Up @@ -91,6 +93,10 @@ public User getUser(final Player base) {
return user;
}

public ConcurrentMap<UUID, User> getOnlineUserCache() {
return onlineUserCache;
}

@Override
public User getUser(final String name) {
if (name == null) {
Expand Down Expand Up @@ -207,6 +213,7 @@ public void blockingSave() {
public void invalidate(final UUID uuid) {
userCache.invalidate(uuid);
uuidCache.removeCache(uuid);
onlineUserCache.remove(uuid);
}

private File getUserFile(final UUID uuid) {
Expand All @@ -215,6 +222,7 @@ private File getUserFile(final UUID uuid) {

public void shutdown() {
uuidCache.shutdown();
onlineUserCache.clear();
}

private void debugLogCache(final User user) {
Expand Down
Loading