Class ClientDisconnectEvent

java.lang.Object
de.craftsblock.craftscore.event.Event
de.craftsblock.craftsnet.events.sockets.ClientDisconnectEvent
All Implemented Interfaces:
GenericSocketEventBase

public class ClientDisconnectEvent extends de.craftsblock.craftscore.event.Event implements GenericSocketEventBase
The ClientDisconnectEvent class represents an event related to a client disconnection from a websocket connection. It extends the base Event class and provides information about the SocketExchange and the SocketMapping associated with the disconnection event.
Since:
2.1.1-SNAPSHOT
See Also:
  • Constructor Details

    • ClientDisconnectEvent

      public ClientDisconnectEvent(SocketExchange exchange, int closeCode, String closeReason, boolean closeByServer)
      Constructs a new ClientDisconnectEvent with the specified SocketExchange and SocketMapping.
      Parameters:
      exchange - The SocketExchange object representing the socket connection and its associated data.
      closeCode - The close code.
      closeReason - The close reason.
      closeByServer - Whether the connection was closed by the server or the client.
  • Method Details

    • getExchange

      @NotNull public @NotNull SocketExchange getExchange()
      Gets the SocketExchange which stores the involved client, server and some other data.
      Specified by:
      getExchange in interface GenericSocketEventBase
      Returns:
      The SocketExchange.
    • getMappings

      Gets a EnumMap of all RouteRegistry.EndpointMapping associated with the client disconnect event.
      Returns:
      A EnumMap of RouteRegistry.EndpointMapping objects representing the mapping for the socket connection.
    • hasMappings

      public boolean hasMappings()
      Checks if the client disconnection event has at least one valid SocketMapping associated with it.
      Returns:
      true if the event has at least one valid SocketMapping, false otherwise.
    • getRawCloseCode

      public int getRawCloseCode()
      Gets the raw close code why the connection was closed.
      Returns:
      The raw close code if it was present, -1 otherwise
    • getCloseCode

      public ClosureCode getCloseCode()
      Gets the close code parsed to a ClosureCode why the connection was closed.
      Returns:
      The parsed close code if it was present, and it is registered in the ClosureCode enum, null otherwise
    • getCloseReason

      public String getCloseReason()
      Gets the reason why the connection was closed.
      Returns:
      The close reason if it was present, null otherwise
    • wasClosedByServer

      public boolean wasClosedByServer()
      Gets whether the server disconnected the client or the client disconnected.
      Returns:
      true if the server closed the connection, false otherwise.