Interface Session

All Known Implementing Classes:
TcpClientSession, TcpServerSession, TcpSession

public interface Session
A network session.
  • Method Details

    • connect

      void connect()
      Connects this session to its host and port.
    • connect

      void connect(boolean wait)
      Connects this session to its host and port.
      Parameters:
      wait - Whether to wait for the connection to be established before returning.
    • connect

      void connect(boolean wait, boolean transferring)
      Connects this session to its host and port.
      Parameters:
      wait - Whether to wait for the connection to be established before returning.
      transferring - Whether the session is a client being transferred.
    • getHost

      String getHost()
      Gets the host the session is connected to.
      Returns:
      The connected host.
    • getPort

      int getPort()
      Gets the port the session is connected to.
      Returns:
      The connected port.
    • getLocalAddress

      SocketAddress getLocalAddress()
      Gets the local address of the session.
      Returns:
      The local address, or null if the session is not connected.
    • getRemoteAddress

      SocketAddress getRemoteAddress()
      Gets the remote address of the session.
      Returns:
      The remote address, or null if the session is not connected.
    • getPacketProtocol

      PacketProtocol getPacketProtocol()
      Gets the packet protocol of the session.
      Returns:
      The session's packet protocol.
    • getCodecHelper

      PacketCodecHelper getCodecHelper()
      Gets the session's PacketCodecHelper.
      Returns:
      The session's packet codec helper.
    • getFlags

      Map<String,Object> getFlags()
      Gets this session's set flags. If this session belongs to a server, the server's flags will be included in the results.
      Returns:
      This session's flags.
    • hasFlag

      boolean hasFlag(Flag<?> flag)
      Checks whether this session has a flag set. If this session belongs to a server, the server's flags will also be checked.
      Parameters:
      flag - Flag to check for.
      Returns:
      Whether this session has a flag set.
    • getFlag

      <T> T getFlag(Flag<T> flag)
      Gets the value of the given flag as an instance of the given type. If this session belongs to a server, the server's flags will be checked for the flag as well.
      Type Parameters:
      T - Type of the flag.
      Parameters:
      flag - Flag to check for.
      Returns:
      Value of the flag.
      Throws:
      IllegalStateException - If the flag's value isn't of the required type.
    • getFlag

      <T> T getFlag(Flag<T> flag, T def)
      Gets the value of the given flag as an instance of the given type. If this session belongs to a server, the server's flags will be checked for the flag as well. If the flag is not set, the specified default value will be returned.
      Type Parameters:
      T - Type of the flag.
      Parameters:
      flag - Flag to check for.
      def - Default value of the flag.
      Returns:
      Value of the flag.
      Throws:
      IllegalStateException - If the flag's value isn't of the required type.
    • setFlag

      <T> void setFlag(Flag<T> flag, T value)
      Sets the value of a flag. This does not change a server's flags if this session belongs to a server.
      Type Parameters:
      T - Type of the flag.
      Parameters:
      flag - Flag to check for.
      value - Value to set the flag to.
    • setFlags

      void setFlags(Map<String,Object> flags)
      Sets the values for a collection of flags.
      Parameters:
      flags - Collection of flags
    • getListeners

      List<SessionListener> getListeners()
      Gets the listeners listening on this session.
      Returns:
      This session's listeners.
    • addListener

      void addListener(SessionListener listener)
      Adds a listener to this session.
      Parameters:
      listener - Listener to add.
    • removeListener

      void removeListener(SessionListener listener)
      Removes a listener from this session.
      Parameters:
      listener - Listener to remove.
    • callEvent

      void callEvent(SessionEvent event)
      Calls an event on the listeners of this session.
      Parameters:
      event - Event to call.
    • callPacketReceived

      void callPacketReceived(Packet packet)
      Notifies all listeners that a packet was just received.
      Parameters:
      packet - Packet to notify.
    • callPacketSent

      void callPacketSent(Packet packet)
      Notifies all listeners that a packet was just sent.
      Parameters:
      packet - Packet to notify.
    • setCompression

      void setCompression(@Nullable CompressionConfig compressionConfig)
      Sets the compression config for this session.
      Parameters:
      compressionConfig - the compression to compress with, or null to disable compression
    • setEncryption

      void setEncryption(@Nullable EncryptionConfig encryptionConfig)
      Sets encryption for this session.
      Parameters:
      encryptionConfig - the encryption to encrypt with, or null to disable encryption
    • isConnected

      boolean isConnected()
      Returns true if the session is connected.
      Returns:
      True if the session is connected.
    • send

      void send(Packet packet)
      Sends a packet.
      Parameters:
      packet - Packet to send.
    • disconnect

      default void disconnect(@NonNull String reason)
      Disconnects the session. This method just wraps the reason into a Component. It is recommended to use Components instead as they provide more flexibility.
      Parameters:
      reason - Reason for disconnecting.
      See Also:
    • disconnect

      default void disconnect(@NonNull String reason, @Nullable Throwable cause)
      Disconnects the session. This method just wraps the reason into a Component. It is recommended to use Components instead as they provide more flexibility.
      Parameters:
      reason - Reason for disconnecting.
      cause - Throwable responsible for disconnecting.
      See Also:
    • disconnect

      default void disconnect(@NonNull net.kyori.adventure.text.Component reason)
      Disconnects the session.
      Parameters:
      reason - Reason for disconnecting.
    • disconnect

      void disconnect(@NonNull net.kyori.adventure.text.Component reason, @Nullable Throwable cause)
      Disconnects the session.
      Parameters:
      reason - Reason for disconnecting.
      cause - Throwable responsible for disconnecting.