Class 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 a requested effect.
    Since:
    1.0.0
    See Also:
    Request
    • Method Detail

      • fromJSON

        @AvailableSince("3.3.0")
        @NotNull
        @CheckReturnValue
        public static @NotNull Response fromJSON​(@NotNull
                                                 @NotNull String json)
                                          throws com.google.gson.JsonSyntaxException
        Creates a Response 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 the packet type is not EFFECT_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
      • 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 not REMOTE_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 not REMOTE_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 not GENERIC_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 not GENERIC_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 interface JsonObject
        Returns:
        JSON string
        Since:
        1.0.0
      • isTerminating

        @AvailableSince("3.3.0")
        public boolean isTerminating()
                              throws IllegalStateException
        Determines if this Response marks the end to a series of responses to a Request.
        Returns:
        true if this response marks the end of a series of responses
        Throws:
        IllegalStateException
        Since:
        3.3.0
      • equals

        public boolean equals​(@Nullable
                              @Nullable Object o)
        Overrides:
        equals in class Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • isOriginKnown

        @AvailableSince("3.3.0")
        public boolean isOriginKnown()
        Determines if the Request that originated this Response is known. If not, send() will throw an IllegalStateException.
        Returns:
        true if the request is known
        Since:
        3.3.0
      • send

        @AvailableSince("3.0.0")
        public boolean send()
                     throws IllegalStateException
        Sends this Response to the client or server that delivered the related Request.
        Returns:
        whether the response was successfully sent (false if an IOException occurred, true otherwise)
        Throws:
        IllegalStateException - if isOriginKnown() returns false (i.e. the response was created without a Request)
        Since:
        3.0.0