From 532a65eca8cfc410f5a08246401b0d25e81e2faa Mon Sep 17 00:00:00 2001 From: William278 Date: Wed, 16 Nov 2022 12:06:01 +0000 Subject: [PATCH] Ensure players remain locked on disconnect and shutdown, close #67 --- .../husksync/listener/EventListener.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/net/william278/husksync/listener/EventListener.java b/common/src/main/java/net/william278/husksync/listener/EventListener.java index 06c5ef9e..66c6df89 100644 --- a/common/src/main/java/net/william278/husksync/listener/EventListener.java +++ b/common/src/main/java/net/william278/husksync/listener/EventListener.java @@ -154,7 +154,6 @@ public abstract class EventListener { optionalUserData -> optionalUserData.ifPresent(userData -> plugin.getRedisManager() .setUserData(user, userData).thenRun(() -> plugin.getDatabase() .setUserData(user, userData, DataSaveCause.DISCONNECT))))) - .thenRun(() -> lockedPlayers.remove(user.uuid)) .exceptionally(throwable -> { plugin.getLoggingAdapter().log(Level.SEVERE, "An exception occurred handling a player disconnection"); @@ -210,10 +209,17 @@ public abstract class EventListener { public final void handlePluginDisable() { disabling = true; - plugin.getOnlineUsers().stream().filter(user -> !lockedPlayers.contains(user.uuid)).forEach( - user -> user.getUserData(plugin.getLoggingAdapter(), plugin.getSettings()).join().ifPresent( - userData -> plugin.getDatabase().setUserData(user, userData, DataSaveCause.SERVER_SHUTDOWN).join())); + // Save data for all online users + plugin.getOnlineUsers().stream() + .filter(user -> !lockedPlayers.contains(user.uuid)) + .forEach(user -> { + lockedPlayers.add(user.uuid); + user.getUserData(plugin.getLoggingAdapter(), plugin.getSettings()).join() + .ifPresent(userData -> plugin.getDatabase() + .setUserData(user, userData, DataSaveCause.SERVER_SHUTDOWN).join()); + }); + // Close outstanding connections plugin.getDatabase().close(); plugin.getRedisManager().close(); }