/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mafia.server.bus.events;

import com.mafia.server.bus.notify.NotifyGame;
import com.mafia.server.bus.notify.NotifyViewState;
import com.mafia.server.model.state.Game;
import com.mafia.server.model.state.Player;
import com.mafia.server.model.state.Repository;
import javax.websocket.Session;

/**
 *
 * @author Just1689
 */
public class PlayerEvents {

    public static void playerQuits(Session session) {
        Player player = Repository.getPlayerBySession(session);
        if (player != null) {
            player.getGame().removePlayer(player);
        }
        //Todo: notify?
    }

    public static Player makePlayer(String name, String passCode, String sessionId) {
        return new Player(name, passCode, sessionId);
    }

    public static void joinGame(Player player, Game game) {
        player.setGame(game);
        game.addPlayer(player);
        NotifyViewState.nofity(game);
    }

}

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mafia.server.bus.events;

import com.mafia.server.bus.notify.NotifyViewState;
import com.mafia.server.model.state.Game;
import com.mafia.server.model.state.Player;
import com.mafia.server.model.state.Repository;
import javax.websocket.Session;

/**
 *
 * @author Just1689
 */
public class PlayerEvents {
    
    public static void playerQuits(Session session) {
        Player player = Repository.getPlayerBySession(session);
        if (player != null) {
            if (player.getGame() == null) {
                return;
            }
            player.getGame().removePlayer(player);
            GameEvents.checkGame(player.getGame());
            
        }
    }
    
    public static Player makePlayer(String name, String passCode, String sessionId) {
        return new Player(name, passCode, sessionId);
    }
    
    public static void joinGame(Player player, Game game) {
        player.setGame(game);
        game.addPlayer(player);
        NotifyViewState.nofity(game);
    }
    
}

Check game when player quits
Check game when player quits
