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.Source
The source of an effect.static class
Request.Target
A recipient of an effect.static class
Request.Type
The type of incoming packet.
-
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
getLogin()
Gets the name or ID of the streamer in the game.@Nullable String
getMessage()
Gets the message from the incoming packet.@Nullable SocketManager
getOriginatingSocket()
@Nullable String
getPassword()
Gets the submitted password.@Nullable Request.Target
getPlayer()
If this is aRequest.Type.PLAYER_INFO
packet, gets the player's info.@Nullable Integer
getQuantity()
Gets the quantity of the item to be added or removed.int
getQuantityOrDefault()
Gets the quantity of the item to be added or removed.@Nullable Request.Source
getSource()
Request.Target @NotNull []
getTargets()
Gets the streamers being targeted by this effect.@NotNull Request.Type
getType()
Gets theType
of the request.@Nullable Object
getValue()
Gets the value returned by the remote function.@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.void
setOriginatingSocket(@Nullable SocketManager originatingSocket)
void
setSource(@Nullable Request.Source source)
@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()
-
-
-
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
-
getValue
@AvailableSince("3.6.0") @CheckReturnValue @Nullable public @Nullable Object getValue()
Gets the value returned by the remote function. Applicable only whengetType()
isRequest.Type.REMOTE_FUNCTION_RESULT
.- Returns:
- the value returned by the remote function
- Since:
- 3.6.0
-
getQuantity
@AvailableSince("3.6.0") @CheckReturnValue @Nullable public @Nullable Integer getQuantity()
Gets the quantity of the item to be added or removed. May be null for non-effect requests or for effects that do not involve items.- Returns:
- the quantity of the item to be added or removed
- Since:
- 3.6.0
-
getQuantityOrDefault
@AvailableSince("3.6.0") @CheckReturnValue public int getQuantityOrDefault()
Gets the quantity of the item to be added or removed. If null or below 1, returns 1.- Returns:
- the quantity of the item to be added or removed
- Since:
- 3.6.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
-
getLogin
@AvailableSince("3.6.1") @Nullable @CheckReturnValue public @Nullable String getLogin()
Gets the name or ID of the streamer in the game. Null whengetType()
is notRequest.Type.LOGIN
.- Returns:
- streamer name or ID
- Since:
- 3.6.1
-
getPassword
@AvailableSince("3.6.1") @Nullable @CheckReturnValue public @Nullable String getPassword()
Gets the submitted password. Non-null whengetType()
isRequest.Type.LOGIN
.- Returns:
- password
- Since:
- 3.6.1
-
getPlayer
@AvailableSince("3.6.2") @Nullable @CheckReturnValue public @Nullable Request.Target getPlayer()
If this is aRequest.Type.PLAYER_INFO
packet, gets the player's info.- Returns:
- player info
- Since:
- 3.6.2
-
getOriginatingSocket
@AvailableSince("3.6.0") @Internal @Nullable public @Nullable SocketManager getOriginatingSocket()
- Returns:
- originating socket
- Since:
- 3.6.0
-
setOriginatingSocket
@Internal public void setOriginatingSocket(@Nullable @Nullable SocketManager originatingSocket)
Sets theSocket
that thisRequest
originated from.This method is for internal use only, see
Request.Builder.originatingSocket(SocketManager)
if you need to set this value.- Parameters:
originatingSocket
- originating socket- Since:
- 3.6.0
-
getSource
@AvailableSince("3.6.0") @Nullable public @Nullable Request.Source getSource()
- Returns:
- originating streamer
- Since:
- 3.6.0
-
setSource
@Internal public void setSource(@Nullable @Nullable Request.Source source)
Sets thestreamer
that thisRequest
originated from.This method is for internal use only, see
Request.Builder.source(Source)
if you need to set this value.- Parameters:
source
- originating streamer- Since:
- 3.6.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
-
-