Package dev.qixils.crowdcontrol.socket
Class Request
- java.lang.Object
-
- dev.qixils.crowdcontrol.socket.Request
-
- All Implemented Interfaces:
JsonObject
,Respondable
@AvailableSince("1.0.0") public class Request extends Object implements JsonObject, Respondable
An incoming packet from the Crowd Control TCP server which represents an effect to be played.- Since:
- 1.0.0
- See Also:
Response
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Request.Builder
Mutable builder for the immutableRequest
class.static class
Request.Target
A recipient of an effect.static class
Request.Type
The type of incoming packet.
-
Constructor Summary
Constructors Constructor Description Request(int id, @NotNull Request.Type type, @Nullable String message)
Instantiates anon-effect type
Request
with the given parameters.Request(int id, @NotNull Request.Type type, @Nullable String effect, @Nullable String viewer, @Nullable String message, @Nullable Integer cost, @Nullable Duration duration, Request.Target @Nullable [] targets, Object @Nullable [] parameters)
Instantiates aRequest
with the given parameters.Request(int id, @NotNull Request.Type type, @Nullable String effect, @Nullable String viewer, @Nullable String message, @Nullable Integer cost, Request.Target @Nullable [] targets)
Deprecated.Obsoleted byRequest(int, Type, String, String, String, Integer, Duration, Target[], Object[])
; to be removed in v3.6.0
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description @NotNull Response.Builder
buildResponse()
boolean
equals(@Nullable Object o)
static @NotNull Request
fromJSON(@NotNull String json)
Creates aRequest
object from JSON.@Nullable Integer
getCost()
Gets the cost of the effect specified in this Request.@Nullable Duration
getDuration()
Gets the streamer-specified duration of this effect.@Nullable String
getEffect()
Gets the name of the effect to play.int
getId()
Gets the ID of the incoming packet.@Nullable String
getMessage()
Gets the message from the incoming packet.Object @Nullable []
getParameters()
Gets the miscellaneous parameters for this effect.Request.Target @NotNull []
getTargets()
Gets the streamers being targeted by this effect.@NotNull Request.Type
getType()
Gets theType
of the request.@NotNull String
getViewer()
Gets the name of the viewer who triggered the effect.int
hashCode()
boolean
isGlobal()
Determines if this Request is triggering an effect for all users.@NotNull Request.Builder
toBuilder()
Creates a mutableRequest.Builder
with a copy of the data in thisRequest
.@NotNull String
toJSON()
Outputs this object as a JSON string.String
toString()
-
-
-
Constructor Detail
-
Request
@AvailableSince("3.3.0") @Deprecated @ScheduledForRemoval(inVersion="3.6.0") public Request(int id, @NotNull @NotNull Request.Type type, @Nullable @Nullable String effect, @Nullable @Nullable String viewer, @Nullable @Nullable String message, @Nullable @Nullable Integer cost, Request.Target @Nullable [] targets) throws IllegalArgumentException
Deprecated.Obsoleted byRequest(int, Type, String, String, String, Integer, Duration, Target[], Object[])
; to be removed in v3.6.0Instantiates aRequest
with the given parameters.- Parameters:
id
- the ID of the requesteffect
- the effect to be playedmessage
- the message to be displayedviewer
- the viewer who requested the effectcost
- the cost of the effecttype
- the packet type to sendtargets
- the targets of the effect- Throws:
IllegalArgumentException
- If a provided argument is invalid. Specifically:- if the given ID is negative
- if the given packet type is null
- if the given packet type is an
effect type
and the effect or viewer is null - if the given packet type is not an
Request.Type.isEffectType()
effect type} and the effect, viewer, cost, or targets is non-null - if the given packet type is
Request.Type.LOGIN
and the message is null
- Since:
- 3.3.0
-
Request
@AvailableSince("3.5.0") @Experimental public Request(int id, @NotNull @NotNull Request.Type type, @Nullable @Nullable String effect, @Nullable @Nullable String viewer, @Nullable @Nullable String message, @Nullable @Nullable Integer cost, @Nullable @Nullable Duration duration, Request.Target @Nullable [] targets, Object @Nullable [] parameters) throws IllegalArgumentException
Instantiates aRequest
with the given parameters.This constructor is marked as
experimental
because it is frequently deprecated and eventually removed in new releases. Please useRequest.Builder
where possible instead.- Parameters:
id
- the ID of the requesteffect
- the effect to be playedmessage
- the message to be displayedviewer
- the viewer who requested the effectcost
- the cost of the effectduration
- the duration of the effecttype
- the packet type to sendtargets
- the targets of the effectparameters
- the miscellaneous parameters of the effect- Throws:
IllegalArgumentException
- If a provided argument is invalid. Specifically:- if the given ID is negative
- if the given packet type is null
- if the given packet type is an
effect type
and the effect or viewer is null - if the given packet type is not an
Request.Type.isEffectType()
effect type} and the effect, viewer, cost, or targets is non-null - if the given packet type is
Request.Type.LOGIN
and the message is null
- Since:
- 3.5.0
-
Request
@AvailableSince("3.3.0") public Request(int id, @NotNull @NotNull Request.Type type, @Nullable @Nullable String message) throws IllegalArgumentException
Instantiates anon-effect type
Request
with the given parameters.- Parameters:
id
- the ID of the requesttype
- the packet type to sendmessage
- the message to be displayed- Throws:
IllegalArgumentException
- If a provided argument is invalid. Specifically:- if the given ID is negative
- if the given packet type is null
- if the given packet type is an
effect type
- if the given packet type is
Request.Type.LOGIN
and the message is null
- Since:
- 3.3.0
-
-
Method Detail
-
fromJSON
@NotNull @CheckReturnValue @Internal @AvailableSince("1.0.0") public static @NotNull Request fromJSON(@NotNull @NotNull String json) throws com.google.gson.JsonSyntaxException
Creates aRequest
object from JSON.- Parameters:
json
- input json data from the Crowd Control TCP server- Returns:
- a new Request object
- Throws:
com.google.gson.JsonSyntaxException
- the JSON failed to be parsed- Since:
- 1.0.0
-
getId
@AvailableSince("1.0.0") @CheckReturnValue public int getId()
Gets the ID of the incoming packet. Corresponds to a unique transaction.- Returns:
- packet ID
- Since:
- 1.0.0
-
getMessage
@AvailableSince("3.0.0") @Nullable @CheckReturnValue public @Nullable String getMessage()
Gets the message from the incoming packet.- Returns:
- message
- Since:
- 3.0.0
-
getEffect
@AvailableSince("1.0.0") @Nullable @CheckReturnValue public @Nullable String getEffect()
Gets the name of the effect to play. May be null ifgetType()
is not aneffect type
.- Returns:
- effect name
- Since:
- 1.0.0
-
getViewer
@AvailableSince("1.0.0") @NotNull @CheckReturnValue public @NotNull String getViewer()
Gets the name of the viewer who triggered the effect.- Returns:
- viewer name
- Since:
- 1.0.0
-
getCost
@AvailableSince("2.0.0") @Nullable @CheckReturnValue public @Nullable Integer getCost()
Gets the cost of the effect specified in this Request.- Returns:
- effect cost
- Since:
- 2.0.0
-
getType
@AvailableSince("1.0.0") @NotNull @CheckReturnValue public @NotNull Request.Type getType()
Gets theType
of the request.- Returns:
- request type
- Since:
- 1.0.0
-
getTargets
@AvailableSince("3.0.0") @CheckReturnValue public Request.Target @NotNull [] getTargets()
Gets the streamers being targeted by this effect. An empty array suggests that all players may be targeted.- Returns:
- possibly empty array of
Request.Target
- Since:
- 3.0.0
-
getDuration
@AvailableSince("3.5.0") @Nullable @CheckReturnValue public @Nullable Duration getDuration()
Gets the streamer-specified duration of this effect. A null value suggests that the effect is not timed.- Returns:
- duration if applicable, null otherwise
- Since:
- 3.5.0
-
getParameters
@AvailableSince("3.5.0") @CheckReturnValue public Object @Nullable [] getParameters()
Gets the miscellaneous parameters for this effect. This may be used by, for example, sliders defined in your CS file.- Returns:
- array of objects if applicable, null otherwise
- Since:
- 3.5.0
-
isGlobal
@AvailableSince("3.0.0") @CheckReturnValue public boolean isGlobal()
Determines if this Request is triggering an effect for all users.- Returns:
- if the triggered effect is global
- Since:
- 3.0.0
-
toJSON
@AvailableSince("3.3.0") @Internal @NotNull @CheckReturnValue public @NotNull String toJSON()
Outputs this object as a JSON string.- Specified by:
toJSON
in interfaceJsonObject
- Returns:
- JSON string
- Since:
- 3.3.0
-
toBuilder
@AvailableSince("3.3.0") @NotNull @CheckReturnValue public @NotNull Request.Builder toBuilder()
Creates a mutableRequest.Builder
with a copy of the data in thisRequest
.- Returns:
- a new
Request.Builder
- Since:
- 3.3.0
-
buildResponse
@AvailableSince("3.0.0") @CheckReturnValue public @NotNull Response.Builder buildResponse()
- Specified by:
buildResponse
in interfaceRespondable
- Returns:
- new response builder
- Since:
- 3.0.0
-
-