Package com.mrivanplays.jdcf
Class CommandManager
- java.lang.Object
-
- com.mrivanplays.jdcf.CommandManager
-
- All Implemented Interfaces:
net.dv8tion.jda.api.hooks.EventListener
public final class CommandManager extends java.lang.Object implements net.dv8tion.jda.api.hooks.EventListener
Represents a command manager.
-
-
Constructor Summary
Constructors Constructor Description CommandManager(@NotNull net.dv8tion.jda.api.JDA jda)
CommandManager(@NotNull net.dv8tion.jda.api.JDA jda, @NotNull CommandSettings settings)
CommandManager(@NotNull net.dv8tion.jda.api.sharding.ShardManager shardManager)
CommandManager(@NotNull net.dv8tion.jda.api.sharding.ShardManager shardManager, @NotNull CommandSettings settings)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addMessageEventSubscription(@NotNull java.util.function.Consumer<MessageEventSubscriber> subscriber)
Adds aMessageEventSubscriber
, called if no commands occur while handling events.boolean
dispatchCommand(@NotNull net.dv8tion.jda.api.JDA jda, @NotNull net.dv8tion.jda.api.entities.Guild guild, @NotNull net.dv8tion.jda.api.entities.TextChannel channel, @NotNull net.dv8tion.jda.api.entities.Member member, @NotNull java.lang.String commandLine)
Deprecated.command dispatchers can't really be a thing, especially in JDA's ecosystem.@NotNull java.util.List<RegisteredCommand>
findCommand(@NotNull java.lang.String startsWith)
Finds the command(s) with the specified startsWith argument.java.util.Optional<RegisteredCommand>
getCommand(@NotNull java.lang.String alias)
Retrieves the first command found which has the specified alias as alias or the specified alias is the command's name.java.util.List<RegisteredCommand>
getRegisteredCommands()
Returns a unmodifiable list of the registered commands.@NotNull CommandSettings
getSettings()
Returns the settings for all inbuilt things, handlers and stuff.void
onEvent(net.dv8tion.jda.api.events.GenericEvent generic)
void
registerCommand(@NotNull Command command)
Registers the specified command into the manager.void
registerCommand(@NotNull RegisteredCommand registeredCommand)
Registers the specifiedRegisteredCommand
object into the manager.void
registerCommands(@NotNull Command... commands)
Registers the specified command array into the managervoid
registerCommands(@NotNull java.util.List<Command> commands)
Registers the specified command list into the managervoid
setSettings(@NotNull CommandSettings settings)
Sets a new settings
-
-
-
Constructor Detail
-
CommandManager
public CommandManager(@NotNull @NotNull net.dv8tion.jda.api.JDA jda)
-
CommandManager
public CommandManager(@NotNull @NotNull net.dv8tion.jda.api.JDA jda, @NotNull @NotNull CommandSettings settings)
-
CommandManager
public CommandManager(@NotNull @NotNull net.dv8tion.jda.api.sharding.ShardManager shardManager)
-
CommandManager
public CommandManager(@NotNull @NotNull net.dv8tion.jda.api.sharding.ShardManager shardManager, @NotNull @NotNull CommandSettings settings)
-
-
Method Detail
-
registerCommand
public void registerCommand(@NotNull @NotNull Command command)
Registers the specified command into the manager.- Parameters:
command
- the command you wish to register
-
registerCommands
public void registerCommands(@NotNull @NotNull Command... commands)
Registers the specified command array into the manager- Parameters:
commands
- the commands you want to register
-
registerCommands
public void registerCommands(@NotNull @NotNull java.util.List<Command> commands)
Registers the specified command list into the manager- Parameters:
commands
- the commands you want to register
-
registerCommand
public void registerCommand(@NotNull @NotNull RegisteredCommand registeredCommand)
Registers the specifiedRegisteredCommand
object into the manager.- Parameters:
registeredCommand
- the command you want to register
-
addMessageEventSubscription
public void addMessageEventSubscription(@NotNull @NotNull java.util.function.Consumer<MessageEventSubscriber> subscriber)
Adds aMessageEventSubscriber
, called if no commands occur while handling events.- Parameters:
subscriber
- subscriber
-
getSettings
@NotNull public @NotNull CommandSettings getSettings()
Returns the settings for all inbuilt things, handlers and stuff.- Returns:
- settings
-
setSettings
public void setSettings(@NotNull @NotNull CommandSettings settings)
Sets a new settings- Parameters:
settings
- the new settings you wish to set
-
getRegisteredCommands
public java.util.List<RegisteredCommand> getRegisteredCommands()
Returns a unmodifiable list of the registered commands.- Returns:
- registered commands
-
getCommand
public java.util.Optional<RegisteredCommand> getCommand(@NotNull @NotNull java.lang.String alias)
Retrieves the first command found which has the specified alias as alias or the specified alias is the command's name.- Parameters:
alias
- the command name/alias for the command you wish to get- Returns:
- optional of registered command if present, empty optional otherwise
-
findCommand
@NotNull public @NotNull java.util.List<RegisteredCommand> findCommand(@NotNull @NotNull java.lang.String startsWith)
Finds the command(s) with the specified startsWith argument.- Parameters:
startsWith
- string which starts with a command alias- Returns:
- list of commands found
-
dispatchCommand
@Deprecated public boolean dispatchCommand(@NotNull @NotNull net.dv8tion.jda.api.JDA jda, @NotNull @NotNull net.dv8tion.jda.api.entities.Guild guild, @NotNull @NotNull net.dv8tion.jda.api.entities.TextChannel channel, @NotNull @NotNull net.dv8tion.jda.api.entities.Member member, @NotNull @NotNull java.lang.String commandLine)
Deprecated.command dispatchers can't really be a thing, especially in JDA's ecosystem. If you want to dispatch commands manually, do it, but JDCF won't maintain such a breakable method.Executes the specified command line with the specified arguments. When dispatched, the author and member of the command are theJDA.getSelfUser()
andGuild.getSelfMember()
. DISCLAIMER: This method does not check for permissions, meaning that when you call it you mean "I want this command executed no matter what".- Parameters:
jda
- the jda instance from which the command should be executedguild
- the guild where the command should be executedchannel
- the channel, used for the command to reply with responsemember
- the member for which the command is going to watch parameterscommandLine
- the command line to execute- Returns:
- execution success state
-
onEvent
public void onEvent(@Nonnull net.dv8tion.jda.api.events.GenericEvent generic)
- Specified by:
onEvent
in interfacenet.dv8tion.jda.api.hooks.EventListener
-
-