# Class CommandHandler

java.lang.Object
it.polimi.ingsw.is25am31.view.tui.input.CommandHandler

public class CommandHandler extends Object
Handles the execution of commands received from the `CommandParser`. This class translates user input commands into actions performed on the `ClientModel` and sends requests to the `VirtualServer`.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `CommandHandler(VirtualServer server, ClientModel model, UiRenderer renderer)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `handleAbandon()`
  Handles the "abandon race" command.
  `void`
  `handleAddCrewMember(String[] tokens)`
  Handles the "humans"/"alien" command.
  `protected void`
  `handleApply()`
  Handles the "apply" command.
  `protected void`
  `handleAttach(String[] tokens)`
  Handles the "attach component" command.
  `void`
  `handleCreate()`
  Handles the "create" command.
  `void`
  `handleDrawCard(String[] tokens)`
  Handles the "draw card" command.
  `void`
  `handleDrawComponent(String[] tokens)`
  Handles the "draw component" command.
  `void`
  `handleDrawFaceUpComponent(String[] tokens)`
  Handles the "draw face up component" command.
  `void`
  `handleEndAssembling(String[] tokens)`
  Handles the "end assembling phase" command.
  `void`
  `handleEndCrewPlacing()`
  Handles the "end crew placing phase" command.
  `void`
  `handleJoin(String[] tokens)`
  Handles the "join" command.
  `protected void`
  `handleQuit()`
  Handles the "quit" command.
  `protected void`
  `handleRemoveComponent(String[] tokens)`
  Handles the "remove component" command.
  `protected void`
  `handleRoll()`
  Handles the "apply" command.
  `void`
  `handleRotate(String[] tokens)`
  Handles the "rotate" command.
  `protected void`
  `handleSet(String[] tokens)`
  Handles the "set" command (used to set context for card effects).
  `void`
  `handleSetNickname(String[] tokens)`
  Handles the "set nickname" command.
  `void`
  `handleSetPosition(String[] tokens)`
  Handles the "set position" command.
  `void`
  `handleShow(String[] tokens)`
  Handles the "show (ship, subdeck, face up components)" command.
  `protected void`
  `handleStart()`
  Handles the "start hourglass" command.
  `protected void`
  `handleStartFinal()`
  Handles the "start final hourglass" command.
  `void`
  `handleStartGame(String[] tokens)`
  Handles the "start game" command.
  `void`
  `handleViewGameList()`
  Handles the "view list" command.
  `void`
  `setClientId(UUID clientId)`
  `void`
  `setNotified()`
  Sets the `notified` field to `true` and starts a new thread that resets it to `false` after a delay of 100 milliseconds.
  This method is used to notify the handler if an exception has been reported; if this is not the case, a message of confirmation of correct input can be shown to the user.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### CommandHandler

    public CommandHandler(VirtualServer server, ClientModel model, UiRenderer renderer)

- ## Method Details

  - ### setNotified

    public void setNotified()
    Sets the `notified` field to `true` and starts a new thread that resets it to `false` after a delay of 100 milliseconds.
    This method is used to notify the handler if an exception has been reported; if this is not the case, a message of confirmation of correct input can be shown to the user.

  - ### setClientId

    public void setClientId(UUID clientId)

  - ### handleStartGame

    public void handleStartGame(String[] tokens) throws InterruptedException
    Handles the "start game" command.
    Throws:
      `InterruptedException`

  - ### handleSetNickname

    public void handleSetNickname(String[] tokens) throws InterruptedException
    Handles the "set nickname" command.
    Parameters:
      `tokens` - An array of strings representing the command and its arguments.
    Throws:
      `InterruptedException`

  - ### handleSet

    protected void handleSet(String[] tokens) throws InterruptedException
    Handles the "set" command (used to set context for card effects).
    Parameters:
      `tokens` - An array of strings representing the command and its arguments.
    Throws:
      `InterruptedException`

  - ### handleApply

    protected void handleApply()
    Handles the "apply" command.

  - ### handleQuit

    protected void handleQuit() throws Exception
    Handles the "quit" command.
    Throws:
      `Exception`

  - ### handleStart

    protected void handleStart() throws Exception
    Handles the "start hourglass" command.
    Throws:
      `Exception`

  - ### handleStartFinal

    protected void handleStartFinal() throws Exception
    Handles the "start final hourglass" command.
    Throws:
      `Exception`

  - ### handleRemoveComponent

    protected void handleRemoveComponent(String[] tokens) throws Exception
    Handles the "remove component" command.
    Throws:
      `Exception`

  - ### handleDrawComponent

    public void handleDrawComponent(String[] tokens) throws Exception
    Handles the "draw component" command.
    Throws:
      `Exception`

  - ### handleDrawFaceUpComponent

    public void handleDrawFaceUpComponent(String[] tokens) throws Exception
    Handles the "draw face up component" command.
    Throws:
      `Exception`

  - ### handleAttach

    protected void handleAttach(String[] tokens) throws InterruptedException
    Handles the "attach component" command.
    Throws:
      `InterruptedException`

  - ### handleRoll

    protected void handleRoll()
    Handles the "apply" command.

  - ### handleShow

    public void handleShow(String[] tokens) throws Exception
    Handles the "show (ship, subdeck, face up components)" command.
    Throws:
      `Exception`

  - ### handleEndAssembling

    public void handleEndAssembling(String[] tokens) throws Exception
    Handles the "end assembling phase" command.
    Throws:
      `Exception`

  - ### handleEndCrewPlacing

    public void handleEndCrewPlacing() throws Exception
    Handles the "end crew placing phase" command.
    Throws:
      `Exception`

  - ### handleDrawCard

    public void handleDrawCard(String[] tokens) throws Exception
    Handles the "draw card" command.
    Throws:
      `Exception`

  - ### handleSetPosition

    public void handleSetPosition(String[] tokens) throws InterruptedException
    Handles the "set position" command.
    Throws:
      `InterruptedException`

  - ### handleAddCrewMember

    public void handleAddCrewMember(String[] tokens) throws InterruptedException
    Handles the "humans"/"alien" command.
    Throws:
      `InterruptedException`

  - ### handleRotate

    public void handleRotate(String[] tokens) throws InterruptedException
    Handles the "rotate" command.
    Throws:
      `InterruptedException`

  - ### handleAbandon

    public void handleAbandon()
    Handles the "abandon race" command.

  - ### handleCreate

    public void handleCreate()
    Handles the "create" command.

  - ### handleJoin

    public void handleJoin(String[] tokens) throws Exception
    Handles the "join" command.
    Throws:
      `Exception`

  - ### handleViewGameList

    public void handleViewGameList() throws Exception
    Handles the "view list" command.
    Throws:
      `Exception`