From 4577da3336e718ff65baef468fcf02a36dafa8b9 Mon Sep 17 00:00:00 2001 From: William Date: Wed, 12 Oct 2022 15:37:26 +0100 Subject: [PATCH] Restore users with at least one health point --- .../william278/husksync/command/UserDataCommand.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/net/william278/husksync/command/UserDataCommand.java b/common/src/main/java/net/william278/husksync/command/UserDataCommand.java index 791bdb4d..66f14eda 100644 --- a/common/src/main/java/net/william278/husksync/command/UserDataCommand.java +++ b/common/src/main/java/net/william278/husksync/command/UserDataCommand.java @@ -2,6 +2,7 @@ package net.william278.husksync.command; import net.william278.husksync.HuskSync; import net.william278.husksync.data.DataSaveCause; +import net.william278.husksync.data.UserData; import net.william278.husksync.player.OnlineUser; import net.william278.husksync.util.DataDumper; import org.jetbrains.annotations.NotNull; @@ -173,8 +174,13 @@ public class UserDataCommand extends CommandBase implements TabCompletable { .ifPresent(player::sendMessage); return; } - plugin.getDatabase().setUserData(user, data.get().userData(), - DataSaveCause.BACKUP_RESTORE); + + // Restore users with a minimum of one health (prevent restoring players with <=0 health) + final UserData userData = data.get().userData(); + userData.getStatus().ifPresent(status -> status.health = Math.max(1, status.health)); + + // Set the users data and send a message + plugin.getDatabase().setUserData(user, userData, DataSaveCause.BACKUP_RESTORE); plugin.getRedisManager().sendUserDataUpdate(user, data.get().userData()).join(); plugin.getLocales().getLocale("data_restored", user.username,