60 lines
1.7 KiB
Java
60 lines
1.7 KiB
Java
package envoy.client.util;
|
|
|
|
import java.util.logging.Level;
|
|
|
|
import javafx.scene.control.Alert;
|
|
import javafx.scene.control.Alert.AlertType;
|
|
|
|
import envoy.client.data.Context;
|
|
import envoy.client.event.*;
|
|
import envoy.client.helper.*;
|
|
import envoy.client.ui.SceneContext.SceneInfo;
|
|
import envoy.data.User.UserStatus;
|
|
import envoy.event.UserStatusChange;
|
|
import envoy.util.EnvoyLog;
|
|
|
|
import dev.kske.eventbus.EventBus;
|
|
|
|
/**
|
|
* Contains methods that change something about the currently logged in user.
|
|
*
|
|
* @author Leon Hofmeister
|
|
* @since Envoy Client v0.3-beta
|
|
*/
|
|
public final class UserUtil {
|
|
|
|
private UserUtil() {}
|
|
|
|
/**
|
|
* Logs the current user out and reopens
|
|
* {@link envoy.client.ui.controller.LoginScene}.
|
|
*
|
|
* @since Envoy Client v0.2-beta
|
|
*/
|
|
public static void logout() {
|
|
final var alert = new Alert(AlertType.CONFIRMATION);
|
|
alert.setTitle("Logout?");
|
|
alert.setContentText("Are you sure you want to log out?");
|
|
|
|
AlertHelper.confirmAction(alert, () -> {
|
|
EnvoyLog.getLogger(ShutdownHelper.class).log(Level.INFO, "A logout was requested");
|
|
EventBus.getInstance().dispatch(new EnvoyCloseEvent());
|
|
EventBus.getInstance().dispatch(new Logout());
|
|
Context.getInstance().getSceneContext().load(SceneInfo.LOGIN_SCENE);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Notifies the application that the status of the currently logged in user has
|
|
* changed
|
|
*
|
|
* @param newStatus the new status
|
|
* @since Envoy Client v0.3-beta
|
|
*/
|
|
public static void changeStatus(UserStatus newStatus) {
|
|
EventBus.getInstance().dispatch(new OwnStatusChange(newStatus));
|
|
if (Context.getInstance().getClient().isOnline())
|
|
Context.getInstance().getClient().send(new UserStatusChange(Context.getInstance().getLocalDB().getUser().getID(), newStatus));
|
|
}
|
|
}
|