Package dev.qixils.crowdcontrol.socket
Class Response
- java.lang.Object
-
- dev.qixils.crowdcontrol.socket.Response
-
- All Implemented Interfaces:
JsonObject
@AvailableSince("1.0.0") public class Response extends Object implements JsonObject
An outgoing packet to the Crowd Control TCP server carrying the result of executing arequested
effect.- Since:
- 1.0.0
- 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.PacketType
Determines the type of packet being sent.static class
Response.ResultType
The result of processing an incoming packet.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(@Nullable Object o)
static @NotNull Response
fromJSON(@NotNull String json)
Creates aResponse
object from JSON.@Nullable Object @Nullable []
getArguments()
Gets a copy of the arguments to be passed to the remote function.@Nullable Map<@NotNull String,@Nullable Object>
getData()
Gets a view of the event data.@Nullable String
getEventType()
Gets the name of the event being fired.int
getId()
Gets the ID of the outgoing packet.String @Nullable []
getIds()
Gets the IDs receiving a status update.@Nullable IdType
getIdType()
Gets the type of effect receiving a status update.@Nullable String
getMessage()
Gets the message that will be delivered along with the result.@Nullable String
getMethod()
Gets the name of the remote function to be executed.@NotNull Response.PacketType
getPacketType()
Gets the type of packet represented by this response.@UnknownNullability("non-null for regular use cases") Response.ResultType
getResultType()
Gets the result of executing an effect.@Nullable Duration
getTimeRemaining()
Gets the time left until the referenced effect ends.int
hashCode()
@Nullable Boolean
isInternal()
Gets whether this packet is internal.boolean
isOriginKnown()
boolean
isTerminating()
boolean
send()
@NotNull Response.Builder
toBuilder()
Creates a mutableResponse.Builder
with a copy of the data in thisResponse
.@NotNull String
toJSON()
Outputs this object as a JSON string for use in the server connection.String
toString()
-
-
-
Method Detail
-
fromJSON
@AvailableSince("3.3.0") @NotNull @CheckReturnValue public static @NotNull Response fromJSON(@NotNull @NotNull String json) throws com.google.gson.JsonSyntaxException
Creates aResponse
object from JSON.- Parameters:
json
- input json data from the Crowd Control game- Returns:
- a new Response object
- Throws:
com.google.gson.JsonSyntaxException
- the JSON failed to be parsed- Since:
- 3.3.0
-
getId
@AvailableSince("1.0.0") @CheckReturnValue public int getId()
Gets the ID of the outgoing packet. Corresponds to a unique transaction.- Returns:
- packet ID
- Since:
- 1.0.0
-
getResultType
@AvailableSince("1.0.0") @CheckReturnValue public @UnknownNullability("non-null for regular use cases") Response.ResultType getResultType()
Gets the result of executing an effect.This will return
null
when thepacket type
is notEFFECT_RESULT
. However, this generally shouldn't be a concern unless you are directly working with library internals.- Returns:
- effect result type or
null
- Since:
- 1.0.0
-
getPacketType
@AvailableSince("3.3.0") @NotNull @CheckReturnValue public @NotNull Response.PacketType getPacketType()
Gets the type of packet represented by this response.- Returns:
- packet type
- Since:
- 3.3.0
-
getMessage
@AvailableSince("1.0.0") @Nullable @CheckReturnValue public @Nullable String getMessage()
Gets the message that will be delivered along with the result. May benull
if amessage is not required
pergetPacketType()
.- Returns:
- result message
- Since:
- 1.0.0
-
getTimeRemaining
@AvailableSince("2.0.0") @CheckReturnValue @Nullable public @Nullable Duration getTimeRemaining()
Gets the time left until the referenced effect ends.- Returns:
- effect duration
- Since:
- 2.0.0
-
getIds
@AvailableSince("3.7.0") @CheckReturnValue public String @Nullable [] getIds()
Gets the IDs receiving a status update.- Returns:
- effect IDs
- Since:
- 3.7.0
-
getIdType
@AvailableSince("3.7.0") @CheckReturnValue @Nullable public @Nullable IdType getIdType()
Gets the type of effect receiving a status update.- Returns:
- effect type
- Since:
- 3.7.0
-
getMethod
@AvailableSince("3.6.0") @CheckReturnValue @Nullable public @Nullable String getMethod()
Gets the name of the remote function to be executed. Null if the packet type is notREMOTE_FUNCTION
.- Returns:
- remote function name
- Since:
- 3.6.0
-
getArguments
@AvailableSince("3.6.0") @CheckReturnValue @Nullable public @Nullable Object @Nullable [] getArguments()
Gets a copy of the arguments to be passed to the remote function. Null if the packet type is notREMOTE_FUNCTION
.- Returns:
- remote function arguments
- Since:
- 3.6.0
-
getData
@AvailableSince("3.6.1") @CheckReturnValue @Nullable public @Nullable Map<@NotNull String,@Nullable Object> getData()
Gets a view of the event data. Null if the packet type is notGENERIC_EVENT
.- Returns:
- event data
- Since:
- 3.6.1
-
getEventType
@AvailableSince("3.6.1") @CheckReturnValue @Nullable public @Nullable String getEventType()
Gets the name of the event being fired. Null if the packet type is notGENERIC_EVENT
.- Returns:
- event name
- Since:
- 3.6.1
-
isInternal
@AvailableSince("3.6.1") @CheckReturnValue @Nullable public @Nullable Boolean isInternal()
Gets whether this packet is internal.- Returns:
- true if this packet is internal, false if not, null if unknown or not applicable
- Since:
- 3.6.1
-
toJSON
@AvailableSince("1.0.0") @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
- Since:
- 1.0.0
-
toBuilder
@AvailableSince("2.0.0") @NotNull @CheckReturnValue public @NotNull Response.Builder toBuilder()
Creates a mutableResponse.Builder
with a copy of the data in thisResponse
.- Returns:
- a new
Response.Builder
- Since:
- 2.0.0
-
isTerminating
@AvailableSince("3.3.0") public boolean isTerminating() throws IllegalStateException
- Returns:
- true if this response marks the end of a series of responses
- Throws:
IllegalStateException
- Since:
- 3.3.0
-
isOriginKnown
@AvailableSince("3.3.0") public boolean isOriginKnown()
Determines if theRequest
that originated thisResponse
is known. If not,send()
will throw anIllegalStateException
.- Returns:
- true if the request is known
- Since:
- 3.3.0
-
send
@AvailableSince("3.0.0") public boolean send() throws IllegalStateException
- Returns:
- whether the response was successfully sent (false if an IOException occurred, true otherwise)
- Throws:
IllegalStateException
- ifisOriginKnown()
returns false (i.e. the response was created without aRequest
)- Since:
- 3.0.0
-
-