Ensure players remain locked on disconnect and shutdown, close #67

feat/data-edit-commands
William278 2 years ago
parent 5af8ae0da5
commit 532a65eca8

@ -154,7 +154,6 @@ public abstract class EventListener {
optionalUserData -> optionalUserData.ifPresent(userData -> plugin.getRedisManager() optionalUserData -> optionalUserData.ifPresent(userData -> plugin.getRedisManager()
.setUserData(user, userData).thenRun(() -> plugin.getDatabase() .setUserData(user, userData).thenRun(() -> plugin.getDatabase()
.setUserData(user, userData, DataSaveCause.DISCONNECT))))) .setUserData(user, userData, DataSaveCause.DISCONNECT)))))
.thenRun(() -> lockedPlayers.remove(user.uuid))
.exceptionally(throwable -> { .exceptionally(throwable -> {
plugin.getLoggingAdapter().log(Level.SEVERE, plugin.getLoggingAdapter().log(Level.SEVERE,
"An exception occurred handling a player disconnection"); "An exception occurred handling a player disconnection");
@ -210,10 +209,17 @@ public abstract class EventListener {
public final void handlePluginDisable() { public final void handlePluginDisable() {
disabling = true; disabling = true;
plugin.getOnlineUsers().stream().filter(user -> !lockedPlayers.contains(user.uuid)).forEach( // Save data for all online users
user -> user.getUserData(plugin.getLoggingAdapter(), plugin.getSettings()).join().ifPresent( plugin.getOnlineUsers().stream()
userData -> plugin.getDatabase().setUserData(user, userData, DataSaveCause.SERVER_SHUTDOWN).join())); .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.getDatabase().close();
plugin.getRedisManager().close(); plugin.getRedisManager().close();
} }

Loading…
Cancel
Save