* When you want your commands to become active, use activate()
+ *
* @author Johnny_JayJay
* @version 3.2_01
* @since 1.1
@@ -34,12 +35,14 @@ public class CommandSettings {
/**
* A regex that only matches valid prefixes. Can be used to check user input.
+ *
* @deprecated Not needed anymore. Anything is a valid prefix now.
*/
@Deprecated
public static final String VALID_PREFIX = "[^\\\\+*^|$?]+";
/**
* A regex that only matches valid labels. Can be used to check user input.
+ *
* @deprecated Use {@link Util#VALID_LABEL} instead
*/
@Deprecated
@@ -58,6 +61,7 @@ public class CommandSettings {
private final boolean labelIgnoreCase; // case doesnt matter
private boolean useShardManager; // effectively final
+ private String globalPrefix; // Global Prefix
private Message unknownCommandMessage; // message sent if on cooldown
private Message cooldownMessage; // message sent if command unknown
private String defaultPrefix; // default prefix
@@ -89,10 +93,11 @@ public class CommandSettings {
/**
* This is the optional constructor in case you are sharding your bot.
* The parameters are validated automatically. In case of any problems (if the prefix is empty), this will throw a CommandSetException.
- * @param shardManager Put your active ShardManager here. This is important for the activation of the CommandListener.
- * @param defaultPrefix The String you will have to put before every command in order to get your command execution registered. This can later be changed.
+ *
+ * @param shardManager Put your active ShardManager here. This is important for the activation of the CommandListener.
+ * @param defaultPrefix The String you will have to put before every command in order to get your command execution registered. This can later be changed.
* @param labelIgnoreCase Set this to true, if you want deactivate case sensitivity for the recognition of labels. E.g.: there will be no difference between the labels "foo",
- * "FOO", "FoO" and so on.
+ * "FOO", "FoO" and so on.
*/
public CommandSettings(@Nonnull String defaultPrefix, @Nonnull ShardManager shardManager, boolean labelIgnoreCase) {
this(defaultPrefix, labelIgnoreCase);
@@ -103,8 +108,9 @@ public CommandSettings(@Nonnull String defaultPrefix, @Nonnull ShardManager shar
/**
* This is the constructor.
* The parameters are validated automatically. In case of any problems (if the prefix is empty), this will throw a CommandSetException.
- * @param jda Put your active JDA here. This is important for the activation of the CommandListener.
- * @param defaultPrefix The String you will have to put before every command in order to get your command execution registered. This can later be changed.
+ *
+ * @param jda Put your active JDA here. This is important for the activation of the CommandListener.
+ * @param defaultPrefix The String you will have to put before every command in order to get your command execution registered. This can later be changed.
* @param labelIgnoreCase Set this to true, if you want deactivate case sensitivity for the recognition of labels. E.g.: there will be no difference between the labels "foo",
* "FOO", "FoO" and so on.
*/
@@ -116,7 +122,7 @@ public CommandSettings(@Nonnull String defaultPrefix, @Nonnull JDA jda, boolean
private CommandSettings(@Nonnull String defaultPrefix, boolean labelIgnoreCase) {
this.commands = new HashMap<>();
- this.listener = new CommandListener(this);
+ this.listener = new CommandListener(this, globalPrefix);
this.activated = false;
this.cooldown = 0;
this.helpColor = null;
@@ -128,8 +134,10 @@ private CommandSettings(@Nonnull String defaultPrefix, boolean labelIgnoreCase)
this.blacklistedChannels = new HashSet<>();
this.prefixMap = new HashMap<>();
this.check = (e) -> true;
- this.unknownCommandHandler = (e) -> {};
- this.exceptionHandler = (e, t) -> {};
+ this.unknownCommandHandler = (e) -> {
+ };
+ this.exceptionHandler = (e, t) -> {
+ };
this.executorService = null;
this.unknownCommandMessage = null;
this.cooldownMessage = null;
@@ -138,12 +146,13 @@ private CommandSettings(@Nonnull String defaultPrefix, boolean labelIgnoreCase)
/**
* Method to add one help label.
+ *
* @param label The label to add.
* @return The current object. This is to use fluent interface.
* @throws CommandSetException if the given label is invalid (contains spaces)
+ * @see DefaultHelpCommand
* @deprecated This method is deprecated and thus not supported anymore. Help Commands are now registered like any other command,
* i.e. using CommandSettings#put. To use the default implementation of the help command, register an instance of DefaultHelpCommand.
- * @see DefaultHelpCommand
*/
@Deprecated
public CommandSettings addHelpLabel(String label) {
@@ -157,11 +166,12 @@ public CommandSettings addHelpLabel(String label) {
/**
* Use this method to add help labels. This will only work if you instantiated this class with the parameter useHelpCommand as true.
+ *
* @param labels One or more labels which may later be called by members to list all commands or to show info about one specific command.
* @return The current object. This is to use fluent interface.
+ * @see DefaultHelpCommand
* @deprecated This method is deprecated and thus not supported anymore. Help Commands are now registered like any other command,
* i.e. using CommandSettings#put. To use the default implementation of the help command, register an instance of DefaultHelpCommand.
- * @see DefaultHelpCommand
*/
@Deprecated
public CommandSettings addHelpLabels(@Nonnull String... labels) {
@@ -172,12 +182,13 @@ public CommandSettings addHelpLabels(@Nonnull String... labels) {
/**
* Adds multiple labels from a String Set.
+ *
* @param labels A Set which contains the labels you want to add.
* @return The current object. This is to use fluent interface.
* @throws CommandSetException if one of the labels is not a valid label.
- * @deprecated This method is deprecated and thus not supported anymore. Help Commands are now registered like any other command,
- * i.e. using CommandSettings#put. To use the default implementation of the help command, register an instance of DefaultHelpCommand.
* @see DefaultHelpCommand
+ * @deprecated This method is deprecated and thus not supported anymore. Help Commands are now registered like any other command,
+ * i.e. using CommandSettings#put. To use the default implementation of the help command, register an instance of DefaultHelpCommand.
*/
@Deprecated
public CommandSettings addHelpLabels(@Nonnull Collection
* The two parameters will be put in a HashMap which is used by the API to notice commands.
- * @param label The label which describes your command, i.e. the string after the prefix [prefix][label].
+ *
+ * @param label The label which describes your command, i.e. the string after the prefix [prefix][label].
* @param executor An instance of your command class which implements ICommand.
* @return The current object. This is to use fluent interface.
* @throws CommandSetException If the label is empty or consists of multiple words.
@@ -352,8 +388,9 @@ public CommandSettings put(@Nonnull ICommand executor, @Nonnull String label) {
/**
* Use this method to add commands with aliases.
* Works like put(ICommand, String) but adds multiple labels to the same command.
+ *
* @param executor An instance of your command class which implements ICommand.
- * @param labels One or more labels. This will throw a CommandSetException, if the label is empty or contains spaces.
+ * @param labels One or more labels. This will throw a CommandSetException, if the label is empty or contains spaces.
* @return The current object. This is to use fluent interface.
* @throws CommandSetException If one label is empty or consists of multiple words
*/
@@ -365,8 +402,9 @@ public CommandSettings put(@Nonnull ICommand executor, @Nonnull String... labels
/**
* Use this method to add commands with aliases from a Set. This is not much different from the put-method with Varargs.
+ *
* @param executor An instance of your command class which implements ICommand.
- * @param labels One or more labels. This will throw a CommandSetException, if the label is empty or contains spaces.
+ * @param labels One or more labels. This will throw a CommandSetException, if the label is empty or contains spaces.
* @return The current object. This is to use fluent interface.
* @throws CommandSetException if one label is empty or contains spaces.
*/
@@ -377,6 +415,7 @@ public CommandSettings put(@Nonnull ICommand executor, @Nonnull Collection
+ *
* @param labels One or more labels to remove
* @return true, if every label was successfully removed. false, if one of the given labels does not exist and thus was not removed.
*/
@@ -400,6 +440,7 @@ public boolean remove(@Nonnull String... labels) {
/**
* Removes every label that is in the given Collection.
+ *
* @param labels The labels to remove.
* @return true, if every label was successfully removed. False, if not (e.g. the label didn't exist)
*/
@@ -409,6 +450,7 @@ public boolean remove(@Nonnull Collection
@@ -542,6 +595,7 @@ public CommandSettings setResetCooldown(boolean resetCooldown) {
/**
* Specifies whether uncaught Exceptions that occur in command execution should be logged. You might want to disable this
* if you handle Exceptions manually or in the onException-listener. By default, this is true.
+ *
* @param logExceptions true, if uncaught Exceptions should be logged. False, if not.
* @return The current object. This is to use fluent interface.
* @see this#onException(BiConsumer)
@@ -554,6 +608,7 @@ public CommandSettings setLogExceptions(boolean logExceptions) {
/**
* Sets a Consumer that will accept any command execution attempt in which the command label is unknown.
+ *
* @param action a Consumer that takes the event.
* @return The current object. This is to use fluent interface.
*/
@@ -564,6 +619,7 @@ public CommandSettings onUnknownCommand(@Nonnull Consumer
* Note that activating multiple CommandSettings may cause problems. You can do this to use multiple prefixes, but it is not recommended.
* This method is important to call because otherwise no command will be registered by the internal command listener.
+ *
* @throws CommandSetException if you already activated this instance.
*/
public void activate() {
if (!this.activated) {
if (useShardManager)
- ((ShardManager)jda).addEventListener(listener);
+ ((ShardManager) jda).addEventListener(listener);
else
- ((JDA)jda).addEventListener(listener);
+ ((JDA) jda).addEventListener(listener);
this.activated = true;
LOGGER.info("CommandSettings were activated");
} else
@@ -631,14 +691,15 @@ public void activate() {
/**
* Deactivates the current CommandSettings by removing the command listener from jda.
* The CommandSettings can be activated again by using activate().
+ *
* @throws CommandSetException if you either did not activate this instance or already deactivated it.
*/
public void deactivate() {
if (this.activated) {
if (useShardManager)
- ((ShardManager)jda).removeEventListener(listener);
+ ((ShardManager) jda).removeEventListener(listener);
else
- ((JDA)jda).removeEventListener(listener);
+ ((JDA) jda).removeEventListener(listener);
this.activated = false;
LOGGER.info("CommandSettings were deactivated");
} else
@@ -647,6 +708,7 @@ public void deactivate() {
/**
* Use this method to get the prefix for a specific guild.
+ *
* @param guildId The id of the guild to check.
* @return the default prefix, if there is no custom prefix set for the given guild id. Otherwise, it returns the custom prefix.
*/
@@ -657,6 +719,7 @@ public String getPrefix(long guildId) {
/**
* Use this method to get the default prefix.
+ *
* @return default prefix set in the constructor or the method setDefaultPrefix(String).
*/
public String getPrefix() {
@@ -665,6 +728,7 @@ public String getPrefix() {
/**
* Use this to get the blacklisted channels.
+ *
* @return an unmodifiable Set with all blacklisted channels.
*/
public Set
* Values that were assigned in the constructor will keep their current value.
+ *
* @return The current object. This is to use fluent interface.
*/
public CommandSettings clear() {
@@ -432,8 +475,10 @@ public CommandSettings clear() {
this.resetCooldown = false;
this.logExceptions = true;
this.check = (e) -> true;
- this.exceptionHandler = (e, t) -> {};
- this.unknownCommandHandler = (e) -> {};
+ this.exceptionHandler = (e, t) -> {
+ };
+ this.unknownCommandHandler = (e) -> {
+ };
if (this.activated)
this.deactivate();
return this;
@@ -442,6 +487,7 @@ public CommandSettings clear() {
/**
* Sets a Predicate that tests every CommandEvent before executing it. This may be useful für own cooldown implementations and such.
* By default, this Predicate always returns true.
+ *
* @param check The Predicate to use as a check.
* @return The current object. This is to use fluent interface.
*/
@@ -452,6 +498,7 @@ public CommandSettings setCheck(@Nonnull Predicate