Class RestrictedCommand

java.lang.Object
xyz.dynxsty.dih4jda.interactions.commands.RestrictedCommand
Direct Known Subclasses:
ApplicationCommand

public abstract class RestrictedCommand extends Object
Represents a basic command.
Since:
v1.6
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Model class which represents a single command cooldown.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a default instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    applyCooldown(long userId, Instant nextUse)
    Manually applies a cooldown for the specified user id.
    Command Cooldowns DO NOT persist between sessions!
    Returns the Duration the user has to wait between command executions.
    The required guilds the command can be executed in.
    final net.dv8tion.jda.api.Permission[]
    The required Permission the User needs to execute the command.
    final Long[]
    The Roles that are required to execute the command.
    final Long[]
    The user ids from the User that are allowed to execute the command.
    boolean
    hasCooldown(long userId)
    Returns whether the command can be used by the specified user.
    Command Cooldowns DO NOT persist between sessions!
    retrieveCooldown(long userId)
    Gets the time the specified user can execute this command again.
    void
    setCommandCooldown(Duration commandCooldown)
    Allows to set a cooldown for this command.
    final void
    Allows to require a set of Guilds only in which the command can get executed.
    final void
    setRequiredPermissions(net.dv8tion.jda.api.Permission... permissions)
    Allows to require a set of Permissions which are needed to execute the corresponding command.
    final void
    Allows to require a set of Longs (role Ids) which are able to execute the corresponding command.
    final void
    Allows to require a set of Longs (user Ids) which are able to execute the corresponding command.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • RestrictedCommand

      public RestrictedCommand()
      Creates a default instance.
  • Method Details

    • setRequiredGuilds

      public final void setRequiredGuilds(@Nonnull Long... guilds)
      Allows to require a set of Guilds only in which the command can get executed.
      Parameters:
      guilds - A Long array, containting the guild ids.
    • getRequiredGuilds

      @Nonnull public Long[] getRequiredGuilds()
      The required guilds the command can be executed in.
      Returns:
      The Long array containing the guild ids.
    • getRequiredPermissions

      @Nonnull public final net.dv8tion.jda.api.Permission[] getRequiredPermissions()
      The required Permission the User needs to execute the command.
      Returns:
      the Permission.
    • setRequiredPermissions

      public final void setRequiredPermissions(@Nonnull net.dv8tion.jda.api.Permission... permissions)
      Allows to require a set of Permissions which are needed to execute the corresponding command.
      Parameters:
      permissions - The set of Permissions.
    • getRequiredUsers

      @Nonnull public final Long[] getRequiredUsers()
      The user ids from the User that are allowed to execute the command.
      Returns:
      The Long array containing the user ids.
    • setRequiredUsers

      public final void setRequiredUsers(@Nonnull Long... users)
      Allows to require a set of Longs (user Ids) which are able to execute the corresponding command.
      Parameters:
      users - The User ids as an Long array.
    • getRequiredRoles

      @Nonnull public final Long[] getRequiredRoles()
      The Roles that are required to execute the command.
      Returns:
      The Long array containing the role ids.
    • setRequiredRoles

      public final void setRequiredRoles(@Nonnull Long... roles)
      Allows to require a set of Longs (role Ids) which are able to execute the corresponding command.
      Parameters:
      roles - The Role ids as an Long array.
    • setCommandCooldown

      public void setCommandCooldown(@Nonnull Duration commandCooldown)
      Allows to set a cooldown for this command. The user has to wait the provided Duration until they can execute this command again. If the user executes the command while they're on cooldown, the CommandCooldownEvent is fired.
      Command Cooldowns DO NOT persist between sessions!
      Parameters:
      commandCooldown - The Duration the user has to wait between command executions.
    • getCommandCooldown

      @Nonnull public Duration getCommandCooldown()
      Returns the Duration the user has to wait between command executions.
      Returns:
      The Duration.
      See Also:
    • applyCooldown

      public void applyCooldown(long userId, @Nonnull Instant nextUse)
      Manually applies a cooldown for the specified user id.
      Command Cooldowns DO NOT persist between sessions!
      Parameters:
      userId - The targets' user id.
      nextUse - The Instant that marks the time the command can be used again.
    • retrieveCooldown

      @Nonnull public RestrictedCommand.Cooldown retrieveCooldown(long userId)
      Gets the time the specified user can execute this command again. If the user has not executed the command yet, this will return a RestrictedCommand.Cooldown with both the nextUse and the lastUse of Instant.EPOCH instead.
      Parameters:
      userId - The targets' user id.
      Returns:
      The Instant that marks the time the command can be used again.
    • hasCooldown

      public boolean hasCooldown(long userId)
      Returns whether the command can be used by the specified user.
      Command Cooldowns DO NOT persist between sessions!
      Parameters:
      userId - The targets' user id.
      Returns:
      Whether the command can be executed.