Class CommandBuilder

java.lang.Object
com.jagrosh.jdautilities.command.CommandBuilder

public class CommandBuilder extends Object
A chain-setter based builder for Commands.

This is more useful for creation of commands "mid-runtime".
A good usage would be to create a Command via eval and register it via CommandClient#addCommand(Command).

While useful during runtime, this is completely inferior to extending Command as a superclass before compilation, and shouldn't be used in place of the ladder.

Since:
1.6
Author:
Kaidan Gustave
  • Constructor Details

    • CommandBuilder

      public CommandBuilder()
  • Method Details

    • setName

      public CommandBuilder setName(String name)
      Sets the name of the Command built from this CommandBuilder.
      Parameters:
      name - The name of the Command to be built.
      Returns:
      This CommandBuilder
    • setHelp

      public CommandBuilder setHelp(String help)
      Sets the help snippet of the Command built from this CommandBuilder.
      Parameters:
      help - The help snippet of the Command to be built.
      Returns:
      This CommandBuilder
    • setCategory

      public CommandBuilder setCategory(Command.Category category)
      Sets the category of the Command built from this CommandBuilder.
      Parameters:
      category - The category of the Command to be built.
      Returns:
      This CommandBuilder
    • setArguments

      public CommandBuilder setArguments(String arguments)
      Sets the arguments of the Command built from this CommandBuilder.
      Parameters:
      arguments - The arguments of the Command to be built.
      Returns:
      This CommandBuilder
    • setGuildOnly

      public CommandBuilder setGuildOnly(boolean guildOnly)
      Sets the Command built to be guild only.
      Parameters:
      guildOnly - true if the Command built is guild only, false if it is not.
      Returns:
      This CommandBuilder
    • setRequiredRole

      public CommandBuilder setRequiredRole(String requiredRole)
      Sets the name of a required role to use the Command built from this CommandBuilder.
      Parameters:
      requiredRole - The name of a role required to use the Command to be built.
      Returns:
      This CommandBuilder
    • setOwnerCommand

      public CommandBuilder setOwnerCommand(boolean ownerCommand)
      Sets the Command built to be owner only.
      Parameters:
      ownerCommand - true if the Command built is owner only, false if it is not.
      Returns:
      This CommandBuilder
    • setCooldown

      public CommandBuilder setCooldown(int cooldown)
      Sets the cooldown of the Command built from this CommandBuilder.
      Parameters:
      cooldown - The number of seconds the built Command will be on cooldown.
      Returns:
      This CommandBuilder
    • setUserPermissions

      public CommandBuilder setUserPermissions(net.dv8tion.jda.api.Permission... userPermissions)
      Sets the required user permissions of the Command built from this CommandBuilder.
      Parameters:
      userPermissions - The required Permissions a User must have when using the Command to be built.
      Returns:
      This CommandBuilder
    • setUserPermissions

      public CommandBuilder setUserPermissions(Collection<net.dv8tion.jda.api.Permission> userPermissions)
      Sets the required user permissions of the Command built from this CommandBuilder.
      Parameters:
      userPermissions - The required Permissions a User must have when using the Command to be built.
      Returns:
      This CommandBuilder
    • setBotPermissions

      public CommandBuilder setBotPermissions(net.dv8tion.jda.api.Permission... botPermissions)
      Sets the required bot permissions of the Command built from this CommandBuilder.
      Parameters:
      botPermissions - The required Permissions the bot must have when using the Command to be built.
      Returns:
      This CommandBuilder
    • setBotPermissions

      public CommandBuilder setBotPermissions(Collection<net.dv8tion.jda.api.Permission> botPermissions)
      Sets the required bot permissions of the Command built from this CommandBuilder.
      Parameters:
      botPermissions - The required Permissions the bot must have when using the Command to be built.
      Returns:
      This CommandBuilder
    • addAlias

      public CommandBuilder addAlias(String alias)
      Adds a alias for the Command built from this CommandBuilder.
      Parameters:
      alias - The Command alias to add.
      Returns:
      This CommandBuilder.
    • addAliases

      public CommandBuilder addAliases(String... aliases)
      Adds aliases for the Command built from this CommandBuilder.
      Parameters:
      aliases - The Command aliases to add.
      Returns:
      This CommandBuilder.
    • setAliases

      public CommandBuilder setAliases(String... aliases)
      Sets the aliases of the Command built from this CommandBuilder.
      Parameters:
      aliases - The aliases of the Command to be built.
      Returns:
      This CommandBuilder
    • setAliases

      public CommandBuilder setAliases(Collection<String> aliases)
      Sets the aliases of the Command built from this CommandBuilder.
      Parameters:
      aliases - The aliases of the Command to be built.
      Returns:
      This CommandBuilder
    • addChild

      public CommandBuilder addChild(Command child)
      Adds a child Command to the Command built from this CommandBuilder.
      Parameters:
      child - The child Command to add.
      Returns:
      This CommandBuilder.
    • addChildren

      public CommandBuilder addChildren(Command... children)
      Adds child Commands to the Command built from this CommandBuilder.
      Parameters:
      children - The child Commands to add.
      Returns:
      This CommandBuilder.
    • setChildren

      public CommandBuilder setChildren(Command... children)
      Sets the children of the Command built from this CommandBuilder.
      Parameters:
      children - The children of the Command to be built.
      Returns:
      This CommandBuilder
    • setChildren

      public CommandBuilder setChildren(Collection<Command> children)
      Sets the children of the Command built from this CommandBuilder.
      Parameters:
      children - The children of the Command to be built.
      Returns:
      This CommandBuilder
    • setHelpBiConsumer

      public CommandBuilder setHelpBiConsumer(BiConsumer<CommandEvent,Command> helpBiConsumer)
      Sets the help BiConsumer of the Command built from this CommandBuilder.
      Parameters:
      helpBiConsumer - The help BiConsumer of the Command to be built.
      Returns:
      This CommandBuilder
    • setUsesTopicTags

      public CommandBuilder setUsesTopicTags(boolean usesTopicTags)
      Sets the Command built to use TopicTags.
      Parameters:
      usesTopicTags - true if the Command built is uses topic tags, false if it does not.
      Returns:
      This CommandBuilder
    • setCooldownScope

      public CommandBuilder setCooldownScope(CooldownScope cooldownScope)
      Sets the cooldown scope of the Command built from this CommandBuilder.
      Parameters:
      cooldownScope - The CooldownScope of the Command to be built.
      Returns:
      This CommandBuilder
    • setHidden

      public CommandBuilder setHidden(boolean hidden)
      Sets the Command built to be hidden from the help builder.
      Parameters:
      hidden - true if this will be hidden from the help builder, false otherwise.
      Returns:
      This CommandBuilder
    • build

      public Command build(Consumer<CommandEvent> execution)
      Builds the Command using the previously provided information.

      This uses the only the CommandEvent parameter that would be provided during #execute(CommandEvent), and no information about the Command can be retrieved using this.

      An alternate method build(java.util.function.BiConsumer) exists if you wish to retrieve information about the Command built during execution.

      Parameters:
      execution - The Consumer that runs on Command#execute(CommandEvent).
      Returns:
      The Command built
    • build

      public Command build(BiConsumer<Command,CommandEvent> execution)
      Builds the Command using the previously provided information.

      This uses the both the CommandEvent parameter that would be provided during #execute(CommandEvent), and the Command built when, allowing info on the Command to be retrieved during execution.

      Parameters:
      execution - The BiConsumer that runs on Command.execute(CommandEvent).
      Returns:
      The Command built