From e97cff9f68423e61d6cd0e3a1f54e59b4a87a846 Mon Sep 17 00:00:00 2001 From: Pingex Date: Tue, 27 Dec 2016 23:04:38 +0100 Subject: [PATCH] Removed hardcoded ScopeOptions --- .../pingex/dcf/commands/AnnotatedCommand.java | 6 ---- .../java/net/pingex/dcf/commands/Command.java | 32 ++----------------- .../pingex/dcf/commands/InternalCommands.java | 10 +++--- 3 files changed, 7 insertions(+), 41 deletions(-) diff --git a/src/main/java/net/pingex/dcf/commands/AnnotatedCommand.java b/src/main/java/net/pingex/dcf/commands/AnnotatedCommand.java index 5ed3cf4..1191cd5 100644 --- a/src/main/java/net/pingex/dcf/commands/AnnotatedCommand.java +++ b/src/main/java/net/pingex/dcf/commands/AnnotatedCommand.java @@ -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; } diff --git a/src/main/java/net/pingex/dcf/commands/Command.java b/src/main/java/net/pingex/dcf/commands/Command.java index 5829c98..5c6b80d 100644 --- a/src/main/java/net/pingex/dcf/commands/Command.java +++ b/src/main/java/net/pingex/dcf/commands/Command.java @@ -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 aliases, String description, boolean isEnabled, String usage, DefaultPermission defaultPermission, ScopeOption.CommandScope commandScope, Set options) + public Command(String name, List aliases, String description, boolean isEnabled, String usage, DefaultPermission defaultPermission, Set 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 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 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 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 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 getOptions() { return Collections.unmodifiableSet(commandOptions); diff --git a/src/main/java/net/pingex/dcf/commands/InternalCommands.java b/src/main/java/net/pingex/dcf/commands/InternalCommands.java index 4afec9e..70fe68b 100644 --- a/src/main/java/net/pingex/dcf/commands/InternalCommands.java +++ b/src/main/java/net/pingex/dcf/commands/InternalCommands.java @@ -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 OPTIONS = Defaults.OPTIONS; + private static final Set 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 OPTIONS = Defaults.OPTIONS; + private static final Set 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