9
0
mirror of https://github.com/WiIIiam278/HuskSync.git synced 2025-12-25 01:29:19 +00:00

Restore users with at least one health point

This commit is contained in:
William
2022-10-12 15:37:26 +01:00
parent c3b339b3dd
commit 4577da3336

View File

@@ -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,