Interface Session
- All Known Implementing Classes:
TcpClientSession,TcpServerSession,TcpSession
public interface Session
A network session.
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(SessionListener listener) Adds a listener to this session.voidcallEvent(SessionEvent event) Calls an event on the listeners of this session.voidcallPacketReceived(Packet packet) Notifies all listeners that a packet was just received.voidcallPacketSent(Packet packet) Notifies all listeners that a packet was just sent.voidconnect()Connects this session to its host and port.voidconnect(boolean wait) Connects this session to its host and port.voidconnect(boolean wait, boolean transferring) Connects this session to its host and port.default voiddisconnect(@NonNull String reason) Disconnects the session.default voiddisconnect(@NonNull String reason, @Nullable Throwable cause) Disconnects the session.default voiddisconnect(@NonNull net.kyori.adventure.text.Component reason) Disconnects the session.voiddisconnect(@NonNull net.kyori.adventure.text.Component reason, @Nullable Throwable cause) Disconnects the session.Gets the session'sPacketCodecHelper.<T> TGets the value of the given flag as an instance of the given type.<T> TGets the value of the given flag as an instance of the given type.getFlags()Gets this session's set flags.getHost()Gets the host the session is connected to.Gets the listeners listening on this session.Gets the local address of the session.Gets the packet protocol of the session.intgetPort()Gets the port the session is connected to.Gets the remote address of the session.booleanChecks whether this session has a flag set.booleanReturns true if the session is connected.voidremoveListener(SessionListener listener) Removes a listener from this session.voidSends a packet.voidsetCompression(@Nullable CompressionConfig compressionConfig) Sets the compression config for this session.voidsetEncryption(@Nullable EncryptionConfig encryptionConfig) Sets encryption for this session.<T> voidSets the value of a flag.voidSets the values for a collection of flags.
-
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'sPacketCodecHelper.- Returns:
- The session's packet codec helper.
-
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
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
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
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
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
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
Adds a listener to this session.- Parameters:
listener- Listener to add.
-
removeListener
Removes a listener from this session.- Parameters:
listener- Listener to remove.
-
callEvent
Calls an event on the listeners of this session.- Parameters:
event- Event to call.
-
callPacketReceived
Notifies all listeners that a packet was just received.- Parameters:
packet- Packet to notify.
-
callPacketSent
Notifies all listeners that a packet was just sent.- Parameters:
packet- Packet to notify.
-
setCompression
Sets the compression config for this session.- Parameters:
compressionConfig- the compression to compress with, or null to disable compression
-
setEncryption
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
Sends a packet.- Parameters:
packet- Packet to send.
-
disconnect
Disconnects the session. This method just wraps the reason into aComponent. It is recommended to use Components instead as they provide more flexibility.- Parameters:
reason- Reason for disconnecting.- See Also:
-
disconnect
Disconnects the session. This method just wraps the reason into aComponent. 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
Disconnects the session.- Parameters:
reason- Reason for disconnecting.cause- Throwable responsible for disconnecting.
-