Fix users being cleaned up too early and then logging back into the server - closes #271

This commit is contained in:
Luck 2017-05-06 18:24:44 +01:00
parent 8326539d40
commit 7dc41e15d3
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
2 changed files with 16 additions and 6 deletions

View File

@ -142,12 +142,19 @@ public class GenericUserManager extends AbstractManager<UserIdentifier, User> 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);
}

View File

@ -104,7 +104,10 @@ public class AbstractStorage implements Storage {
public CompletableFuture<Boolean> 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;