package cz.jzitnik.events.handlers;

import cz.jzitnik.annotations.EventHandler;
import cz.jzitnik.events.ExitEvent;
import cz.jzitnik.states.RunningState;
import cz.jzitnik.utils.DependencyManager;
import cz.jzitnik.utils.StateManager;
import cz.jzitnik.utils.events.AbstractEventHandler;

@EventHandler(ExitEvent.class)
public class ExitEventHandler extends AbstractEventHandler<ExitEvent> {
    public ExitEventHandler(DependencyManager dm) {
        super(dm);
    }

    @Override
    public void handle(ExitEvent event) {
        StateManager stateManager = dm.getDependencyOrThrow(StateManager.class);
        RunningState runningState = stateManager.getOrThrow(RunningState.class);
        runningState.setRunning(false);
        System.exit(0); // Pls don't blame me
    }
}
