|
|
|
@ -6,6 +6,7 @@ import java.lang.reflect.Method;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Represents a single command.
|
|
|
|
@ -47,6 +48,11 @@ public abstract class Command implements ICommandExecutor
|
|
|
|
|
*/
|
|
|
|
|
private CommandScope commandScope;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Contains all options for this command.
|
|
|
|
|
*/
|
|
|
|
|
private Set<ICommandOption> commandOptions;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Basic constructor.
|
|
|
|
|
* @param name Name of the command
|
|
|
|
@ -56,8 +62,9 @@ public abstract class Command implements ICommandExecutor
|
|
|
|
|
* @param usage Command usage help
|
|
|
|
|
* @param defaultPermission Default permission, ie. when the permissions provider doesn't return anything.
|
|
|
|
|
* @param commandScope Tells where the command should run, ie. PM or guild chat, or both
|
|
|
|
|
* @param options Command options.
|
|
|
|
|
*/
|
|
|
|
|
public Command(String name, List<String> aliases, String description, boolean isEnabled, String usage, DefaultPermission defaultPermission, CommandScope commandScope)
|
|
|
|
|
public Command(String name, List<String> aliases, String description, boolean isEnabled, String usage, DefaultPermission defaultPermission, CommandScope commandScope, Set<ICommandOption> options)
|
|
|
|
|
{
|
|
|
|
|
this.name = name;
|
|
|
|
|
this.aliases = aliases;
|
|
|
|
@ -66,6 +73,7 @@ public abstract class Command implements ICommandExecutor
|
|
|
|
|
this.usage = usage;
|
|
|
|
|
this.defaultPermission = defaultPermission;
|
|
|
|
|
this.commandScope = commandScope;
|
|
|
|
|
this.commandOptions = options;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -79,6 +87,7 @@ public abstract class Command implements ICommandExecutor
|
|
|
|
|
public static final String USAGE = "No command usage provided.";
|
|
|
|
|
public static final DefaultPermission DEFAULT_PERMISSION = DefaultPermission.EVERYONE;
|
|
|
|
|
public static final CommandScope COMMAND_SCOPE = CommandScope.NOWHERE; // NOWHERE is enforced as a default value to force devs to specify a real scope.
|
|
|
|
|
public static final Set<ICommandOption> OPTIONS = Collections.emptySet();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -121,6 +130,11 @@ public abstract class Command implements ICommandExecutor
|
|
|
|
|
*/
|
|
|
|
|
private CommandScope commandScope = Defaults.COMMAND_SCOPE;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Command options
|
|
|
|
|
*/
|
|
|
|
|
private Set<ICommandOption> commandOptions = Defaults.OPTIONS;
|
|
|
|
|
|
|
|
|
|
public Builder(String name)
|
|
|
|
|
{
|
|
|
|
|
this.name = name;
|
|
|
|
@ -172,6 +186,12 @@ public abstract class Command implements ICommandExecutor
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Builder options(Set<ICommandOption> options)
|
|
|
|
|
{
|
|
|
|
|
commandOptions = options;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Build a new Command using a supplied executor.
|
|
|
|
|
* @param toExecute The body of the command.
|
|
|
|
@ -179,7 +199,7 @@ public abstract class Command implements ICommandExecutor
|
|
|
|
|
*/
|
|
|
|
|
public Command build(ICommandExecutor toExecute)
|
|
|
|
|
{
|
|
|
|
|
return new Command(name, aliases, description, isEnabled, usage, defaultPermission, commandScope)
|
|
|
|
|
return new Command(name, aliases, description, isEnabled, usage, defaultPermission, commandScope, commandOptions)
|
|
|
|
|
{
|
|
|
|
|
@Override
|
|
|
|
|
public void execute(MessageReceivedEvent event, List<String> arguments) throws Throwable
|
|
|
|
@ -197,7 +217,7 @@ public abstract class Command implements ICommandExecutor
|
|
|
|
|
*/
|
|
|
|
|
public Command build(Method target, Object invokable)
|
|
|
|
|
{
|
|
|
|
|
return new Command(name, aliases, description, isEnabled, usage, defaultPermission, commandScope)
|
|
|
|
|
return new Command(name, aliases, description, isEnabled, usage, defaultPermission, commandScope, commandOptions)
|
|
|
|
|
{
|
|
|
|
|
@Override
|
|
|
|
|
public void execute(MessageReceivedEvent event, List<String> arguments) throws Throwable
|
|
|
|
@ -270,6 +290,11 @@ public abstract class Command implements ICommandExecutor
|
|
|
|
|
return commandScope;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Set<ICommandOption> getCommandOptions()
|
|
|
|
|
{
|
|
|
|
|
return Collections.unmodifiableSet(commandOptions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setEnabled(boolean enabled)
|
|
|
|
|
{
|
|
|
|
|
isEnabled = enabled;
|
|
|
|
|