Enum Class Command.CooldownScope

java.lang.Object
java.lang.Enum<Command.CooldownScope>
com.jagrosh.jdautilities.command.Command.CooldownScope
All Implemented Interfaces:
Serializable, Comparable<Command.CooldownScope>, Constable
Enclosing class:
Command

public static enum Command.CooldownScope extends Enum<Command.CooldownScope>
A series of Enums used for defining the scope size for a Command's cooldown.

The purpose for these values is to allow easy, refined, and generally convenient keys for cooldown scopes, allowing a command to remain on cooldown for more than just the user calling it, with no unnecessary abstraction or developer input. Cooldown keys are generated via Command#getCooldownKey(CommandEvent) using 1-2 Snowflake ID's corresponding to the name (IE: USER_CHANNEL uses the ID's of the User and the Channel from the CommandEvent).

However, the issue with generalizing and generating like this is that the command may be called in a non-guild environment, causing errors internally.
To prevent this, all of the values that contain "GUILD" in their name default to their "CHANNEL" counterparts when commands using them are called outside of a Guild environment.

These are effective across a single instance of JDA, and not multiple ones, save when multiple shards run on a single JVM and under a ShardManager.
There is no shard magic, and no guarantees for a 100% "global" cooldown, unless all shards of the bot run under the same ShardManager, and/or via some external system unrelated to JDA-Utilities.
Since:
1.3
Author:
Kaidan Gustave
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from class java.lang.Enum

    Enum.EnumDesc<E extends Enum<E>>
  • Enum Constant Summary

    Enum Constants
    Enum Constant
    Description
    Applies the cooldown to the MessageChannel the command is called in.
    Applies this cooldown globally.
    Applies the cooldown to the Guild the command is called in.
    Applies the cooldown to the calling Shard the command is called on.
    Applies the cooldown to the calling User across all locations on this instance (IE: TextChannels, PrivateChannels, etc).
    Applies the cooldown to the calling User local to the MessageChannel the command is called in.
    Applies the cooldown to the calling User local to the Guild the command is called in.
    Applies the cooldown to the calling User on the Shard the command is called on.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the enum constant of this class with the specified name.
    Returns an array containing the constants of this enum class, in the order they are declared.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Enum Constant Details

    • USER

      public static final Command.CooldownScope USER
      Applies the cooldown to the calling User across all locations on this instance (IE: TextChannels, PrivateChannels, etc).

      The key for this is generated in the format:

      <command-name>|U:<userID>
    • CHANNEL

      public static final Command.CooldownScope CHANNEL
      Applies the cooldown to the MessageChannel the command is called in.

      The key for this is <command-name>|C:<channelID>

    • USER_CHANNEL

      public static final Command.CooldownScope USER_CHANNEL
      Applies the cooldown to the calling User local to the MessageChannel the command is called in.

      The key for this is <command-name>|U:<userID>|C:<channelID>

    • GUILD

      public static final Command.CooldownScope GUILD
      Applies the cooldown to the Guild the command is called in.

      The key for this is <command-name>|G:<guildID>

      NOTE: This will automatically default back to CooldownScope.CHANNEL when called in a private channel. This is done in order to prevent internal NullPointerExceptions from being thrown while generating cooldown keys!

    • USER_GUILD

      public static final Command.CooldownScope USER_GUILD
      Applies the cooldown to the calling User local to the Guild the command is called in.

      The key for this is <command-name>|U:<userID>|G:<guildID>

      NOTE: This will automatically default back to CooldownScope.CHANNEL when called in a private channel. This is done in order to prevent internal NullPointerExceptions from being thrown while generating cooldown keys!

    • SHARD

      public static final Command.CooldownScope SHARD
      Applies the cooldown to the calling Shard the command is called on.

      The key for this is <command-name>|S:<shardID>

      NOTE: This will automatically default back to CooldownScope.GLOBAL when JDA#getShardInfo() returns null. This is done in order to prevent internal NullPointerExceptions from being thrown while generating cooldown keys!

    • USER_SHARD

      public static final Command.CooldownScope USER_SHARD
      Applies the cooldown to the calling User on the Shard the command is called on.

      The key for this is <command-name>|U:<userID>|S:<shardID>

      NOTE: This will automatically default back to CooldownScope.USER when JDA#getShardInfo() returns null. This is done in order to prevent internal NullPointerExceptions from being thrown while generating cooldown keys!

    • GLOBAL

      public static final Command.CooldownScope GLOBAL
      Applies this cooldown globally.

      As this implies: the command will be unusable on the instance of JDA in all types of MessageChannels until the cooldown has ended.

      The key for this is <command-name>|globally

  • Method Details

    • values

      public static Command.CooldownScope[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static Command.CooldownScope valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null