Package server.commands

Source Code of server.commands.Leave

package server.commands;

import java.io.IOException;
import java.util.List;

import org.quickserver.net.server.ClientHandler;

import server.constants.CommandList;
import server.constants.Messages;
import server.protocol.ClientInfo;
import server.protocol.GameRoom;

/**
* The Class Leave. Handles the leave command when players leaves from server
* and sends the gamesheet, dice and message to clients.
*/
public class Leave implements Command {

  public void execute(ClientHandler handler, GameRoom room,
      List<String> splitted) throws IOException {
    ClientInfo data = (ClientInfo) handler.getClientData();
    room.removeClient(handler);
    methods.sendPlayers(handler, room);
    if (!room.isInProgress())
      return;
    room.getGameSheet().removePlayer(handler);
    if (room.getDice().getCurOwner().equals(data.getName())
        && room.getClients().size() != 0) {
      methods.switchDiceOwner(room);
    }
    methods.sendSheet(handler, room);
    methods.sendDice(handler, room);
    methods.sendMessage(handler, room, Messages.LEFTGAME(data.getName()));
    methods.sendMessage(handler, room, CommandList.RESETCMD);
  }

}
TOP

Related Classes of server.commands.Leave

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.