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; package net.pingex.dcf.commands;
import net.pingex.dcf.commands.options.ScopeOption;
import net.pingex.dcf.permissions.DefaultPermission; import net.pingex.dcf.permissions.DefaultPermission;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
@ -43,9 +42,4 @@ public @interface AnnotatedCommand
* Default permission, ie. when the permissions provider doesn't return anything. * Default permission, ie. when the permissions provider doesn't return anything.
*/ */
DefaultPermission defaultPermission() default DefaultPermission.EVERYONE; 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; package net.pingex.dcf.commands;
import net.pingex.dcf.commands.options.ICommandOption; import net.pingex.dcf.commands.options.ICommandOption;
import net.pingex.dcf.commands.options.ScopeOption;
import net.pingex.dcf.permissions.DefaultPermission; import net.pingex.dcf.permissions.DefaultPermission;
import sx.blah.discord.handle.impl.events.MessageReceivedEvent; import sx.blah.discord.handle.impl.events.MessageReceivedEvent;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -45,11 +44,6 @@ public abstract class Command implements ICommandExecutor
*/ */
private DefaultPermission defaultPermission; 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. * Contains all options for this command.
*/ */
@ -63,10 +57,9 @@ public abstract class Command implements ICommandExecutor
* @param isEnabled Is the command enabled ? * @param isEnabled Is the command enabled ?
* @param usage Command usage help * @param usage Command usage help
* @param defaultPermission Default permission, ie. when the permissions provider doesn't return anything. * @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. * @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.name = name;
this.aliases = aliases; this.aliases = aliases;
@ -74,7 +67,6 @@ public abstract class Command implements ICommandExecutor
this.isEnabled = isEnabled; this.isEnabled = isEnabled;
this.usage = usage; this.usage = usage;
this.defaultPermission = defaultPermission; this.defaultPermission = defaultPermission;
this.commandScope = commandScope;
this.commandOptions = options; this.commandOptions = options;
} }
@ -88,7 +80,6 @@ public abstract class Command implements ICommandExecutor
public static final boolean IS_ENABLED = true; public static final boolean IS_ENABLED = true;
public static final String USAGE = "No command usage provided."; public static final String USAGE = "No command usage provided.";
public static final DefaultPermission DEFAULT_PERMISSION = DefaultPermission.EVERYONE; 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(); public static final Set<ICommandOption> OPTIONS = Collections.emptySet();
} }
@ -127,11 +118,6 @@ public abstract class Command implements ICommandExecutor
*/ */
private DefaultPermission defaultPermission = Defaults.DEFAULT_PERMISSION; 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 * Command options
*/ */
@ -182,12 +168,6 @@ public abstract class Command implements ICommandExecutor
return this; return this;
} }
public Builder commandScope(ScopeOption.CommandScope commandScope)
{
this.commandScope = commandScope;
return this;
}
public Builder options(Set<ICommandOption> options) public Builder options(Set<ICommandOption> options)
{ {
commandOptions = options; commandOptions = options;
@ -201,7 +181,7 @@ public abstract class Command implements ICommandExecutor
*/ */
public Command build(ICommandExecutor toExecute) 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 @Override
public void execute(MessageReceivedEvent event, List<String> arguments) throws Throwable 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) 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 @Override
public void execute(MessageReceivedEvent event, List<String> arguments) throws Throwable public void execute(MessageReceivedEvent event, List<String> arguments) throws Throwable
@ -253,7 +233,6 @@ public abstract class Command implements ICommandExecutor
.enabled(meta.isEnabled()) .enabled(meta.isEnabled())
.usage(meta.usage()) .usage(meta.usage())
.defaultPermission(meta.defaultPermission()) .defaultPermission(meta.defaultPermission())
.commandScope(meta.scope())
.build(target, invokable); .build(target, invokable);
} }
@ -287,11 +266,6 @@ public abstract class Command implements ICommandExecutor
return defaultPermission; return defaultPermission;
} }
public ScopeOption.CommandScope getScope()
{
return commandScope;
}
public Set<ICommandOption> getOptions() public Set<ICommandOption> getOptions()
{ {
return Collections.unmodifiableSet(commandOptions); return Collections.unmodifiableSet(commandOptions);

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