Class ConnecticalPacket
java.lang.Object
dev.logicologist.connectical.packet.ConnecticalPacket
- Direct Known Subclasses:
ConnectionAuthenticatedPacket
,ConnectionAuthPacket
,ConnectionHeartbeatPacket
,ConnectionInsecurePacket
,TestPacket
Abstract class that should be extended by all packet classes. Contains a usable Connectical instance, and contains
the packedId for recieved packets.
Only fields that are serializable (and primitives) will be sent in the packet. This includes all fields that are inherited from any extended or implemented classes which also inherit this class.
Unless a no-arg constructor is used, the constructor to use must be annotated with ConnecticalConstructor
,
where the matchingFields parameter is used to specify the name of the fields being sent with the parameters of the
constructor that is specified. The same constructor/fields do not have to be identical on both client and server, as
long as the data sent/recieved is sufficient for each side respectively.
If you wish to exclude a field from being sent, mark it with ConnecticalIgnoredField
.
- Version:
- 1.0.0
- Author:
- Logical
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract void
Called when this packet is received.void
replicateToClients
(UUID... ignoredClients) Replicate this packet to all clients, including the client it was sent from if applicable.void
sendToClient
(UUID clientUuid) Send this packet to a specific client.void
sendToClientForResponse
(UUID clientUuid, Predicate<ConnecticalPacket> onPacketResponse, Runnable onTimeout, long timeout, TimeUnit timeUnit) Send this packet to a specific client for a response.void
sendToClientsForResponses
(Predicate<ConnecticalPacket> onPacketResponse, Runnable onTimeout, long timeout, TimeUnit timeUnit, int responseLimit, UUID... ignoredClients) Send this packet to all clients for a number of responses.void
Send this packet to the server.void
sendToServerForResponse
(Predicate<ConnecticalPacket> onPacketResponse, Runnable onTimeout, long timeout, TimeUnit timeUnit) Send this packet to the server for a response.void
setPacketId
(UUID uuid)
-
Field Details
-
connectical
-
packetId
-
-
Constructor Details
-
ConnecticalPacket
public ConnecticalPacket()
-
-
Method Details
-
sendToServer
public void sendToServer()Send this packet to the server. Can only be used on a client. -
replicateToClients
Replicate this packet to all clients, including the client it was sent from if applicable. If any client IDs are specified in the ignoredClients parameter, they will not receive the packet. -
sendToClient
Send this packet to a specific client. Can only be used on a server.- Parameters:
clientUuid
- The UUID of the client to send this packet to.
-
sendToServerForResponse
public void sendToServerForResponse(Predicate<ConnecticalPacket> onPacketResponse, Runnable onTimeout, long timeout, TimeUnit timeUnit) Send this packet to the server for a response. Can only be used on a client.- Parameters:
onPacketResponse
- The action to perform when a response is received. As this action is a predicate, return true if the packet has been fully handled. Return false if not, and the default action will be performed afterward.onTimeout
- The action to perform when a timeout occurs. Can be null.timeout
- The amount of time to wait for a response.timeUnit
- The unit of time to use for the timeout.
-
sendToClientForResponse
public void sendToClientForResponse(UUID clientUuid, Predicate<ConnecticalPacket> onPacketResponse, Runnable onTimeout, long timeout, TimeUnit timeUnit) Send this packet to a specific client for a response. Can only be used on a server.- Parameters:
clientUuid
- The UUID of the client to send this packet to.onPacketResponse
- The action to perform when a response is received. As this action is a predicate, return true if the packet has been fully handled. Return false if not, and the default action will be performed afterward.onTimeout
- The action to perform when a timeout occurs. Can be null.timeout
- The amount of time to wait for a response.timeUnit
- The unit of time to use for the timeout.
-
sendToClientsForResponses
public void sendToClientsForResponses(Predicate<ConnecticalPacket> onPacketResponse, Runnable onTimeout, long timeout, TimeUnit timeUnit, int responseLimit, UUID... ignoredClients) Send this packet to all clients for a number of responses. Can only be used on a server.- Parameters:
onPacketResponse
- The action to perform when a response is received.onTimeout
- The action to perform when a timeout occurs. Can be null.timeout
- The amount of time to wait for a response.timeUnit
- The unit of time to use for the timeout.responseLimit
- The maximum number of responses to await.
-
onReceive
Called when this packet is received. -
setPacketId
-