diff --git a/common/src/main/java/me/lucko/luckperms/common/managers/impl/GenericUserManager.java b/common/src/main/java/me/lucko/luckperms/common/managers/impl/GenericUserManager.java index dfc7ab594..780e9ae66 100644 --- a/common/src/main/java/me/lucko/luckperms/common/managers/impl/GenericUserManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/managers/impl/GenericUserManager.java @@ -142,12 +142,19 @@ public class GenericUserManager extends AbstractManager im @Override public void scheduleUnload(UUID uuid) { plugin.getScheduler().doAsyncLater(() -> { - User user = getIfLoaded(plugin.getUuidCache().getUUID(uuid)); - if (user != null && !plugin.isPlayerOnline(uuid)) { - user.unregisterData(); - unload(user); + // check once to see if the user can be unloaded. + if (getIfLoaded(plugin.getUuidCache().getUUID(uuid)) != null && !plugin.isPlayerOnline(uuid)) { + + // check again in 40 ticks, we want to be sure the player won't have re-logged before we unload them. + plugin.getScheduler().doAsyncLater(() -> { + User user = getIfLoaded(plugin.getUuidCache().getUUID(uuid)); + if (user != null && !plugin.isPlayerOnline(uuid)) { + user.unregisterData(); + unload(user); + plugin.getUuidCache().clearCache(uuid); + } + }, 40L); } - plugin.getUuidCache().clearCache(uuid); }, 40L); } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/AbstractStorage.java b/common/src/main/java/me/lucko/luckperms/common/storage/AbstractStorage.java index f34be3457..cd2a4cb01 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/AbstractStorage.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/AbstractStorage.java @@ -104,7 +104,10 @@ public class AbstractStorage implements Storage { public CompletableFuture loadUser(UUID uuid, String username) { return makeFuture(() -> { if (backing.loadUser(uuid, username)) { - plugin.getApiProvider().getEventFactory().handleUserLoad(plugin.getUserManager().getIfLoaded(uuid)); + User u = plugin.getUserManager().getIfLoaded(uuid); + if (u != null) { + plugin.getApiProvider().getEventFactory().handleUserLoad(u); + } return true; } return false;