geforkt von Mirrors/FastAsyncWorldEdit
Fixed sessions not saving on shutdown
Dieser Commit ist enthalten in:
Ursprung
41c307a4b5
Commit
4d0df10f88
@ -150,7 +150,7 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
|
|||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
WorldEdit worldEdit = WorldEdit.getInstance();
|
WorldEdit worldEdit = WorldEdit.getInstance();
|
||||||
worldEdit.getSessionManager().clear();
|
worldEdit.getSessionManager().unload();
|
||||||
worldEdit.getPlatformManager().unregister(server);
|
worldEdit.getPlatformManager().unregister(server);
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
config.unload();
|
config.unload();
|
||||||
|
@ -266,13 +266,50 @@ public class SessionManager {
|
|||||||
sessions.remove(getKey(owner));
|
sessions.remove(getKey(owner));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called to unload this session manager.
|
||||||
|
*/
|
||||||
|
public synchronized void unload() {
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove all sessions.
|
* Remove all sessions.
|
||||||
*/
|
*/
|
||||||
public synchronized void clear() {
|
public synchronized void clear() {
|
||||||
|
saveChangedSessions();
|
||||||
sessions.clear();
|
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
|
@Subscribe
|
||||||
public void onConfigurationLoad(ConfigurationLoadEvent event) {
|
public void onConfigurationLoad(ConfigurationLoadEvent event) {
|
||||||
LocalConfiguration config = event.getConfiguration();
|
LocalConfiguration config = event.getConfiguration();
|
||||||
@ -302,32 +339,7 @@ public class SessionManager {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
synchronized (SessionManager.this) {
|
synchronized (SessionManager.this) {
|
||||||
long now = System.currentTimeMillis();
|
saveChangedSessions();
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -136,7 +136,9 @@ public class ForgeWorldEdit {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void serverStopping(FMLServerStoppingEvent event) {
|
public void serverStopping(FMLServerStoppingEvent event) {
|
||||||
WorldEdit.getInstance().getPlatformManager().unregister(platform);
|
WorldEdit worldEdit = WorldEdit.getInstance();
|
||||||
|
worldEdit.getSessionManager().unload();
|
||||||
|
worldEdit.getPlatformManager().unregister(platform);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -147,7 +147,9 @@ public class SpongeWorldEdit {
|
|||||||
|
|
||||||
@Listener
|
@Listener
|
||||||
public void serverStopping(GameStoppingServerEvent event) {
|
public void serverStopping(GameStoppingServerEvent event) {
|
||||||
WorldEdit.getInstance().getPlatformManager().unregister(platform);
|
WorldEdit worldEdit = WorldEdit.getInstance();
|
||||||
|
worldEdit.getSessionManager().unload();
|
||||||
|
worldEdit.getPlatformManager().unregister(platform);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Listener
|
@Listener
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren