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 arequestedeffect.- See Also:
Request
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classResponse.BuilderMutable builder for the immutableResponseclass.static classResponse.ResultTypeThe 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 aRequestgiven 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 intgetId()Gets the ID of the outgoing packet.@NotNull StringgetMessage()Gets the message that will be delivered along with the result.RequestgetRequest()Gets the uniqueRequestthat caused this response.Response.ResultTypegetResultType()Gets the result of executing an effect.longgetTimeRemaining()Gets the milliseconds left until the referenced effect ends.voidsend()@NotNull Response.BuildertoBuilder()Gets a mutableResponse.Builderrepresenting this Response.@NotNull StringtoJSON()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 aRequestgiven 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 uniqueRequestthat 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:
toJSONin interfaceJsonObject- Returns:
- JSON string
-
toBuilder
@NotNull @CheckReturnValue public @NotNull Response.Builder toBuilder()
Gets a mutableResponse.Builderrepresenting this Response.- Returns:
- new builder
-
send
public void send() throws IllegalStateException- Throws:
IllegalStateException- the relatedRequestdoes not have an associated client or server
-
-