Removed hardcoded ScopeOptions

keep-around/3c354c0f00ae6e9d0b7ccd747b995217fbd6c147
Pingex aka Raphaël 9 years ago
parent 0c9db2814d
commit e97cff9f68

@ -1,6 +1,5 @@
package net.pingex.dcf.commands;
import net.pingex.dcf.commands.options.ScopeOption;
import net.pingex.dcf.permissions.DefaultPermission;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@ -43,9 +42,4 @@ public @interface AnnotatedCommand
* Default permission, ie. when the permissions provider doesn't return anything.
*/
DefaultPermission defaultPermission() default DefaultPermission.EVERYONE;
/**
* Tells where the command should run, ie. PM or guild chat, or both
*/
ScopeOption.CommandScope scope() default ScopeOption.CommandScope.NOWHERE;
}

@ -1,7 +1,6 @@
package net.pingex.dcf.commands;
import net.pingex.dcf.commands.options.ICommandOption;
import net.pingex.dcf.commands.options.ScopeOption;
import net.pingex.dcf.permissions.DefaultPermission;
import sx.blah.discord.handle.impl.events.MessageReceivedEvent;
import java.lang.reflect.Method;
@ -45,11 +44,6 @@ public abstract class Command implements ICommandExecutor
*/
private DefaultPermission defaultPermission;
/**
* Tells where the command should run, ie. PM or guild chat, or both
*/
private ScopeOption.CommandScope commandScope;
/**
* Contains all options for this command.
*/
@ -63,10 +57,9 @@ public abstract class Command implements ICommandExecutor
* @param isEnabled Is the command enabled ?
* @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, ScopeOption.CommandScope commandScope, Set<ICommandOption> options)
public Command(String name, List<String> aliases, String description, boolean isEnabled, String usage, DefaultPermission defaultPermission, Set<ICommandOption> options)
{
this.name = name;
this.aliases = aliases;
@ -74,7 +67,6 @@ public abstract class Command implements ICommandExecutor
this.isEnabled = isEnabled;
this.usage = usage;
this.defaultPermission = defaultPermission;
this.commandScope = commandScope;
this.commandOptions = options;
}
@ -88,7 +80,6 @@ public abstract class Command implements ICommandExecutor
public static final boolean IS_ENABLED = true;
public static final String USAGE = "No command usage provided.";
public static final DefaultPermission DEFAULT_PERMISSION = DefaultPermission.EVERYONE;
public static final ScopeOption.CommandScope COMMAND_SCOPE = ScopeOption.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();
}
@ -127,11 +118,6 @@ public abstract class Command implements ICommandExecutor
*/
private DefaultPermission defaultPermission = Defaults.DEFAULT_PERMISSION;
/**
* Tells where the command should run, ie. PM or guild chat, or both
*/
private ScopeOption.CommandScope commandScope = Defaults.COMMAND_SCOPE;
/**
* Command options
*/
@ -182,12 +168,6 @@ public abstract class Command implements ICommandExecutor
return this;
}
public Builder commandScope(ScopeOption.CommandScope commandScope)
{
this.commandScope = commandScope;
return this;
}
public Builder options(Set<ICommandOption> options)
{
commandOptions = options;
@ -201,7 +181,7 @@ public abstract class Command implements ICommandExecutor
*/
public Command build(ICommandExecutor toExecute)
{
return new Command(name, aliases, description, isEnabled, usage, defaultPermission, commandScope, commandOptions)
return new Command(name, aliases, description, isEnabled, usage, defaultPermission, commandOptions)
{
@Override
public void execute(MessageReceivedEvent event, List<String> arguments) throws Throwable
@ -219,7 +199,7 @@ public abstract class Command implements ICommandExecutor
*/
public Command build(Method target, Object invokable)
{
return new Command(name, aliases, description, isEnabled, usage, defaultPermission, commandScope, commandOptions)
return new Command(name, aliases, description, isEnabled, usage, defaultPermission, commandOptions)
{
@Override
public void execute(MessageReceivedEvent event, List<String> arguments) throws Throwable
@ -253,7 +233,6 @@ public abstract class Command implements ICommandExecutor
.enabled(meta.isEnabled())
.usage(meta.usage())
.defaultPermission(meta.defaultPermission())
.commandScope(meta.scope())
.build(target, invokable);
}
@ -287,11 +266,6 @@ public abstract class Command implements ICommandExecutor
return defaultPermission;
}
public ScopeOption.CommandScope getScope()
{
return commandScope;
}
public Set<ICommandOption> getOptions()
{
return Collections.unmodifiableSet(commandOptions);

@ -34,8 +34,7 @@ public class InternalCommands implements IWithCommands
private static final boolean IS_ENABLED = true;
private static final String USAGE = "Page";
private static final DefaultPermission DEFAULT_PERMISSION = DefaultPermission.EVERYONE;
private static final ScopeOption.CommandScope COMMAND_SCOPE = ScopeOption.CommandScope.ANYWHERE;
private static final Set<ICommandOption> OPTIONS = Defaults.OPTIONS;
private static final Set<ICommandOption> OPTIONS = Collections.singleton(new ScopeOption(ScopeOption.CommandScope.ANYWHERE));
/**
* How many commands should be displayed on each page
@ -46,7 +45,7 @@ public class InternalCommands implements IWithCommands
private ListCommand()
{
super(NAME, ALIASES, DESCRIPTION, IS_ENABLED, USAGE, DEFAULT_PERMISSION, COMMAND_SCOPE, OPTIONS);
super(NAME, ALIASES, DESCRIPTION, IS_ENABLED, USAGE, DEFAULT_PERMISSION, OPTIONS);
}
@Override
@ -117,14 +116,13 @@ public class InternalCommands implements IWithCommands
private static final boolean IS_ENABLED = true;
private static final String USAGE = "Command";
private static final DefaultPermission DEFAULT_PERMISSION = DefaultPermission.EVERYONE;
private static final ScopeOption.CommandScope COMMAND_SCOPE = ScopeOption.CommandScope.ANYWHERE;
private static final Set<ICommandOption> OPTIONS = Defaults.OPTIONS;
private static final Set<ICommandOption> OPTIONS = Collections.singleton(new ScopeOption(ScopeOption.CommandScope.ANYWHERE));
static final UsageCommand INSTANCE = new UsageCommand();
private UsageCommand()
{
super(NAME, ALIASES, DESCRIPTION, IS_ENABLED, USAGE, DEFAULT_PERMISSION, COMMAND_SCOPE, OPTIONS);
super(NAME, ALIASES, DESCRIPTION, IS_ENABLED, USAGE, DEFAULT_PERMISSION, OPTIONS);
}
@Override