Restore users with at least one health point

feat/data-edit-commands
William 2 years ago
parent c3b339b3dd
commit 4577da3336

@ -2,6 +2,7 @@ package net.william278.husksync.command;
import net.william278.husksync.HuskSync; import net.william278.husksync.HuskSync;
import net.william278.husksync.data.DataSaveCause; import net.william278.husksync.data.DataSaveCause;
import net.william278.husksync.data.UserData;
import net.william278.husksync.player.OnlineUser; import net.william278.husksync.player.OnlineUser;
import net.william278.husksync.util.DataDumper; import net.william278.husksync.util.DataDumper;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -173,8 +174,13 @@ public class UserDataCommand extends CommandBase implements TabCompletable {
.ifPresent(player::sendMessage); .ifPresent(player::sendMessage);
return; 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.getRedisManager().sendUserDataUpdate(user, data.get().userData()).join();
plugin.getLocales().getLocale("data_restored", plugin.getLocales().getLocale("data_restored",
user.username, user.username,

Loading…
Cancel
Save