Permalink
Browse files

Fixed sessions not saving on shutdown

  • Loading branch information...
me4502 committed Aug 19, 2018
1 parent 41c307a commit 4d0df10f883c79007668e62cf4b663ecd51516dd
@@ -150,7 +150,7 @@ private void loadAdapter() {
@Override
public void onDisable() {
WorldEdit worldEdit = WorldEdit.getInstance();
worldEdit.getSessionManager().clear();
worldEdit.getSessionManager().unload();
worldEdit.getPlatformManager().unregister(server);
if (config != null) {
config.unload();
@@ -266,13 +266,50 @@ public synchronized void remove(SessionOwner owner) {
sessions.remove(getKey(owner));
}
/**
* Called to unload this session manager.
*/
public synchronized void unload() {
clear();
}
/**
* Remove all sessions.
*/
public synchronized void clear() {
saveChangedSessions();
sessions.clear();
}
private synchronized void saveChangedSessions() {
long now = System.currentTimeMillis();
Iterator<SessionHolder> it = sessions.values().iterator();
Map<SessionKey, LocalSession> saveQueue = new HashMap<>();
while (it.hasNext()) {
SessionHolder stored = it.next();
if (stored.key.isActive()) {
stored.lastActive = now;
if (stored.session.compareAndResetDirty()) {
saveQueue.put(stored.key, stored.session);
}
} else {
if (now - stored.lastActive > EXPIRATION_GRACE) {
if (stored.session.compareAndResetDirty()) {
saveQueue.put(stored.key, stored.session);
}
it.remove();
}
}
}
if (!saveQueue.isEmpty()) {
commit(saveQueue);
}
}
@Subscribe
public void onConfigurationLoad(ConfigurationLoadEvent event) {
LocalConfiguration config = event.getConfiguration();
@@ -302,32 +339,7 @@ private SessionHolder(SessionKey key, LocalSession session) {
@Override
public void run() {
synchronized (SessionManager.this) {
long now = System.currentTimeMillis();
Iterator<SessionHolder> it = sessions.values().iterator();
Map<SessionKey, LocalSession> saveQueue = new HashMap<>();
while (it.hasNext()) {
SessionHolder stored = it.next();
if (stored.key.isActive()) {
stored.lastActive = now;
if (stored.session.compareAndResetDirty()) {
saveQueue.put(stored.key, stored.session);
}
} else {
if (now - stored.lastActive > EXPIRATION_GRACE) {
if (stored.session.compareAndResetDirty()) {
saveQueue.put(stored.key, stored.session);
}
it.remove();
}
}
}
if (!saveQueue.isEmpty()) {
commit(saveQueue);
}
saveChangedSessions();
}
}
}
@@ -136,7 +136,9 @@ public void serverAboutToStart(FMLServerAboutToStartEvent event) {
@EventHandler
public void serverStopping(FMLServerStoppingEvent event) {
WorldEdit.getInstance().getPlatformManager().unregister(platform);
WorldEdit worldEdit = WorldEdit.getInstance();
worldEdit.getSessionManager().unload();
worldEdit.getPlatformManager().unregister(platform);
}
@EventHandler
@@ -147,7 +147,9 @@ public void serverAboutToStart(GameAboutToStartServerEvent event) {
@Listener
public void serverStopping(GameStoppingServerEvent event) {
WorldEdit.getInstance().getPlatformManager().unregister(platform);
WorldEdit worldEdit = WorldEdit.getInstance();
worldEdit.getSessionManager().unload();
worldEdit.getPlatformManager().unregister(platform);
}
@Listener

0 comments on commit 4d0df10

Please sign in to comment.