Package dev.qixils.crowdcontrol.socket
Class Response
- java.lang.Object
-
- dev.qixils.crowdcontrol.socket.Response
-
- All Implemented Interfaces:
JsonObject
public final class Response extends Object implements JsonObject
An outgoing packet to the Crowd Control TCP server carrying the result of executing arequested
effect.- See Also:
Request
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Response.Builder
Mutable builder for the immutableResponse
class.static class
Response.ResultType
The result of processing an incoming packet.
-
Constructor Summary
Constructors Constructor Description Response(@NotNull Request request, Response.ResultType type, @NotNull String message, long timeRemaining)
Constructs a response to aRequest
given its ID, the result of executing the effect, and an associated message.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getId()
Gets the ID of the outgoing packet.@NotNull String
getMessage()
Gets the message that will be delivered along with the result.Request
getRequest()
Gets the uniqueRequest
that caused this response.Response.ResultType
getResultType()
Gets the result of executing an effect.long
getTimeRemaining()
Gets the milliseconds left until the referenced effect ends.void
send()
@NotNull Response.Builder
toBuilder()
Gets a mutableResponse.Builder
representing this Response.@NotNull String
toJSON()
Outputs this object as a JSON string for use in the server connection.
-
-
-
Constructor Detail
-
Response
@CheckReturnValue public Response(@NotNull @NotNull Request request, @NotNull Response.ResultType type, @NotNull @NotNull String message, long timeRemaining)
Constructs a response to aRequest
given its ID, the result of executing the effect, and an associated message.- Parameters:
request
- originating requesttype
- result of executionmessage
- result messagetimeRemaining
- remaining duration for the referenced effect in milliseconds
-
-
Method Detail
-
getRequest
public Request getRequest()
Gets the uniqueRequest
that caused this response.- Returns:
- original request
-
getId
@CheckReturnValue public int getId()
Gets the ID of the outgoing packet. Corresponds to a unique transaction.- Returns:
- packet ID
-
getResultType
@NotNull @CheckReturnValue public Response.ResultType getResultType()
Gets the result of executing an effect.- Returns:
- effect result
-
getMessage
@NotNull @CheckReturnValue public @NotNull String getMessage()
Gets the message that will be delivered along with the result.- Returns:
- result message
-
getTimeRemaining
@CheckReturnValue public long getTimeRemaining()
Gets the milliseconds left until the referenced effect ends.- Returns:
- effect duration in milliseconds
-
toJSON
@NotNull @CheckReturnValue public @NotNull String toJSON()
Outputs this object as a JSON string for use in the server connection.- Specified by:
toJSON
in interfaceJsonObject
- Returns:
- JSON string
-
toBuilder
@NotNull @CheckReturnValue public @NotNull Response.Builder toBuilder()
Gets a mutableResponse.Builder
representing this Response.- Returns:
- new builder
-
send
public void send() throws IllegalStateException
- Throws:
IllegalStateException
- the relatedRequest
does not have an associated client or server
-
-