/*
 * 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);
    }

}

@@ -220,55 +220,8 @@
 s;%0A%0A
-import com.mafia.server.bus.notify.NotifyGame;%0A
 impo
@@ -494,16 +494,20 @@
 vents %7B%0A
+    
 %0A    pub
@@ -663,87 +663,214 @@
     
-player.getGame().removePlayer(player);%0A        %7D%0A        //Todo: notify?
+if (player.getGame() == null) %7B%0A                return;%0A            %7D%0A            player.getGame().removePlayer(player);%0A            GameEvents.checkGame(player.getGame());%0A            %0A        %7D
 %0A    %7D%0A
+    
 %0A   
@@ -1012,16 +1012,20 @@
 ;%0A    %7D%0A
+    
 %0A    pub
@@ -1183,11 +1183,15 @@
 ;%0A    %7D%0A
+    
 %0A%7D%0A

Check game when player quits