Class CrowdControl

java.lang.Object
live.crowdcontrol.cc4j.CrowdControl

public class CrowdControl extends Object
  • Field Details

    • QUEUE_DURATION

      public static final int QUEUE_DURATION
      Amount of time in seconds that effects are allowed to execute for.
      See Also:
    • effects

      @NotNull protected final @NotNull Map<String,Supplier<CCEffect>> effects
    • players

      @NotNull protected final @NotNull Map<UUID,ConnectedPlayer> players
    • effectPool

      @NotNull protected final @NotNull ExecutorService effectPool
    • timedEffectPool

      @NotNull protected final @NotNull ScheduledExecutorService timedEffectPool
    • eventPool

      @NotNull protected final @NotNull ExecutorService eventPool
    • httpUtil

      @NotNull protected final @NotNull HttpUtil httpUtil
    • gameID

      @NotNull protected final @NotNull String gameID
    • gamePackID

      @NotNull protected final @NotNull String gamePackID
    • appID

      @NotNull protected final @NotNull String appID
    • appSecret

      @NotNull protected final @NotNull String appSecret
    • dataFolder

      @NotNull protected final @NotNull Path dataFolder
    • gamePack

      @Nullable protected @Nullable GamePack gamePack
  • Constructor Details

    • CrowdControl

      public CrowdControl(@NotNull @NotNull String gameID, @NotNull @NotNull String gamePackID, @NotNull @NotNull String appID, @NotNull @NotNull String appSecret, @NotNull @NotNull Path dataFolder)
  • Method Details

    • getGameID

      @NotNull public @NotNull String getGameID()
      Gets the ID of this game's Crowd Control metadata.
      Returns:
      gameID
    • getGamePackID

      @NotNull public @NotNull String getGamePackID()
      Gets the ID of this game's Crowd Control pack.
      Returns:
      gamePackID
    • getAppID

      @NotNull public @NotNull String getAppID()
      Gets the ID of this game's Crowd Control third-party application.
      Returns:
      appID
    • getAppSecret

      @NotNull public @NotNull String getAppSecret()
      Gets the API secret of this game's Crowd Control third-party application.
      Returns:
      appSecret
    • getDataFolder

      @NotNull public @NotNull Path getDataFolder()
      Gets the folder in which players' Crowd Control tokens are stored.
      Returns:
      data folder
    • getEffectPool

      @NotNull public @NotNull ExecutorService getEffectPool()
      Gets the executor service on which effects are to be run.
      Returns:
      executor service
    • getTimedEffectPool

      @NotNull public @NotNull ScheduledExecutorService getTimedEffectPool()
      Gets the executor service on which timed effect updates are to be run.
      Returns:
      scheduled executor service
    • getEventPool

      @NotNull public @NotNull ExecutorService getEventPool()
      Gets the executor service on which events are to be run.
      Returns:
      executor service
    • getHttpUtil

      @NotNull public @NotNull HttpUtil getHttpUtil()
      Gets the utility for making requests to Crowd Control's HTTP servers.
      Returns:
      http util
    • getGamePack

      @Nullable public @Nullable GamePack getGamePack()
      Gets the data about this game pack. May be missing if the game IDs are invalid, or it hasn't finished loading yet.
      Returns:
      game pack
    • loadGamePack

      @NotNull public @NotNull CompletableFuture<@Nullable GamePack> loadGamePack()
      Re-fetches the game pack.
      Returns:
      future representing the loaded game pack
    • loadGamePack

      @NotNull public @NotNull CompletableFuture<@Nullable GamePack> loadGamePack(@Nullable @Nullable String token)
      Re-fetches the game pack.
      Returns:
      future representing the loaded game pack
    • getPlayer

      @Nullable public @Nullable CCPlayer getPlayer(@NotNull @NotNull UUID playerId)
      Gets a registered player by the provided unique ID.
      Parameters:
      playerId - unique player id
      Returns:
      registered player or null
    • addPlayer

      @NotNull public @NotNull CCPlayer addPlayer(@NotNull @NotNull UUID playerId)
      Registers a player by the provided unique ID.
      Parameters:
      playerId - unique player id
      Returns:
      crowd control player
    • removePlayer

      public boolean removePlayer(@NotNull @NotNull UUID playerId)
      Removes a registered player by the provided unique ID.
      Parameters:
      playerId - unique player id
      Returns:
      whether a player was removed
    • getPlayers

      @NotNull public @NotNull List<CCPlayer> getPlayers()
      Gets all the currently registered players. The returned collection is not a view; changes to it will not be reflected.
      Returns:
      players
    • getPlayerIds

      @NotNull public @NotNull Set<UUID> getPlayerIds(@NotNull @NotNull String ccUID)
      Gets the list of players logged in as the specified user ID.
      Parameters:
      ccUID - Crowd Control user IDs
      Returns:
      game player ids
    • addEffect

      public boolean addEffect(@NotNull @NotNull String effectID, @NotNull @NotNull CCEffect effect)
      Registers an effect which maintains one object across its lifetime.
      Parameters:
      effectID - ID of the effect
      effect - executor object
      Returns:
      whether the effect was added successfully
    • addEffect

      public boolean addEffect(@NotNull @NotNull String effectID, @NotNull @NotNull Supplier<@NotNull CCEffect> supplier)
      Registers an effect which is instantiated upon triggering.
      Parameters:
      effectID - ID of the effect
      supplier - executor supplier
      Returns:
      whether the effect was added successfully
    • executeEffect

      public void executeEffect(@NotNull @NotNull PublicEffectPayload payload, @NotNull @NotNull ConnectedPlayer source)
      Executes the provided effect.
      Parameters:
      payload - info about the effect
      source - player who spawned the effect
    • handleEffectResponse

      protected void handleEffectResponse(@NotNull @NotNull CCEffectResponse response, @NotNull @NotNull ConnectedPlayer source)
    • cancelByRequestId

      public void cancelByRequestId(@NotNull @NotNull UUID requestId)
      Cancels a request given its ID.
      Parameters:
      requestId - request id
    • cancelAll

      public void cancelAll()
    • pauseByRequestId

      public void pauseByRequestId(@NotNull @NotNull UUID requestId)
      Pauses a request given its ID.
      Parameters:
      requestId - request id
    • pauseAll

      public void pauseAll()
      Pauses all requests, and cancels all pending requests.
    • resumeByRequestId

      public void resumeByRequestId(@NotNull @NotNull UUID requestId)
      Resumes a request given its ID.
      Parameters:
      requestId - request id
    • resumeAll

      public void resumeAll()
      Resumes all requests.
    • isPlayerEffectActive

      public boolean isPlayerEffectActive(@NotNull @NotNull String effectId, @NotNull @NotNull UUID playerId)
      Returns whether a request by the given timed effect ID is active. Paused effects are considered active.
      Parameters:
      effectId - effect id
      playerId - player id
      Returns:
      is effect active
    • close

      public void close()