From 1e85b9bf42ac86a747e05850deb1fb678fb2f604 Mon Sep 17 00:00:00 2001 From: Aikar Date: Wed, 22 Nov 2017 22:41:16 -0500 Subject: [PATCH] update javadocs --- .../commands/BukkitRegisteredCommand.html | 2 +- .../commands/BungeeRegisteredCommand.html | 2 +- .../co/aikar/commands/RegisteredCommand.html | 70 ++- docs/acf-core/deprecated-list.html | 11 +- docs/acf-core/index-all.html | 6 + .../co/aikar/commands/RegisteredCommand.html | 486 +++++++++--------- .../commands/SpongeRegisteredCommand.html | 2 +- 7 files changed, 322 insertions(+), 257 deletions(-) diff --git a/docs/acf-bukkit/co/aikar/commands/BukkitRegisteredCommand.html b/docs/acf-bukkit/co/aikar/commands/BukkitRegisteredCommand.html index 13b8ef67..57e54e39 100644 --- a/docs/acf-bukkit/co/aikar/commands/BukkitRegisteredCommand.html +++ b/docs/acf-bukkit/co/aikar/commands/BukkitRegisteredCommand.html @@ -148,7 +148,7 @@ extends co.aikar.commands.RegisteredCommand<
  • diff --git a/docs/acf-bungee/co/aikar/commands/BungeeRegisteredCommand.html b/docs/acf-bungee/co/aikar/commands/BungeeRegisteredCommand.html index 13455c30..cfb6650e 100644 --- a/docs/acf-bungee/co/aikar/commands/BungeeRegisteredCommand.html +++ b/docs/acf-bungee/co/aikar/commands/BungeeRegisteredCommand.html @@ -148,7 +148,7 @@ extends co.aikar.commands.RegisteredCommand<
  • diff --git a/docs/acf-core/co/aikar/commands/RegisteredCommand.html b/docs/acf-core/co/aikar/commands/RegisteredCommand.html index 1b44eebf..0e64d790 100644 --- a/docs/acf-core/co/aikar/commands/RegisteredCommand.html +++ b/docs/acf-core/co/aikar/commands/RegisteredCommand.html @@ -18,8 +18,8 @@ catch(err) { } //--> -var methods = {"i0":10,"i1":10,"i2":10,"i3":10,"i4":10,"i5":10,"i6":10,"i7":10}; -var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"]}; +var methods = {"i0":10,"i1":10,"i2":10,"i3":42,"i4":10,"i5":10,"i6":10,"i7":10,"i8":10,"i9":10}; +var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"],32:["t6","Deprecated Methods"]}; var altColor = "altColor"; var rowColor = "rowColor"; var tableTab = "tableTab"; @@ -109,7 +109,7 @@ var activeTableTab = "activeTableTab";


  • -
    public class RegisteredCommand<R extends CommandExecutionContext<? extends CommandExecutionContext,? extends CommandIssuer>>
    +
    public class RegisteredCommand<R extends CommandExecutionContext<? extends CommandExecutionContext,? extends CommandIssuer>>
     extends Object
  • @@ -124,7 +124,7 @@ extends -All Methods Instance Methods Concrete Methods  +All Methods Instance Methods Concrete Methods Deprecated Methods  Modifier and Type Method and Description @@ -143,24 +143,34 @@ extends String -getPermission()  +getPermission() +
    Deprecated.  
    + -String -getPrefSubCommand()  +Set<String> +getPermissions()  String -getSyntaxText()  +getPrefSubCommand()  -void -postCommand()  +String +getSyntaxText()  void +postCommand()  + + +void preCommand()  + +boolean +requiresPermission(String permission)  + @@ -198,7 +208,7 @@ extends
  • postCommand

    -
    public void postCommand()
    +
    public void postCommand()
  • @@ -207,7 +217,31 @@ extends
  • getPermission

    -
    public String getPermission()
    +
    @Deprecated
    +public String getPermission()
    +
    Deprecated. 
    +
    +
    See Also:
    +
    getPermissions()
    +
    +
  • + + + + + + + + + @@ -216,7 +250,7 @@ extends
  • getPrefSubCommand

    -
    public String getPrefSubCommand()
    +
    public String getPrefSubCommand()
  • @@ -225,7 +259,7 @@ extends
  • getSyntaxText

    -
    public String getSyntaxText()
    +
    public String getSyntaxText()
  • @@ -234,7 +268,7 @@ extends
  • getCommand

    -
    public String getCommand()
    +
    public String getCommand()
  • @@ -243,7 +277,7 @@ extends
  • addSubcommand

    -
    public void addSubcommand(String cmd)
    +
    public void addSubcommand(String cmd)
  • @@ -252,7 +286,7 @@ extends
  • addSubcommands

    -
    public void addSubcommands(Collection<String> cmd)
    +
    public void addSubcommands(Collection<String> cmd)
  • diff --git a/docs/acf-core/deprecated-list.html b/docs/acf-core/deprecated-list.html index 83b0897a..a63b32a5 100644 --- a/docs/acf-core/deprecated-list.html +++ b/docs/acf-core/deprecated-list.html @@ -165,25 +165,28 @@ -co.aikar.commands.ACFUtil.random(Class<? extends T>) +co.aikar.commands.RegisteredCommand.getPermission()  +co.aikar.commands.ACFUtil.random(Class<? extends T>) + + co.aikar.commands.CommandContexts.registerSenderAwareContext(Class<T>, IssuerAwareContextResolver<T, R>)
    Please switch to CommandContexts.registerIssuerAwareContext(Class, IssuerAwareContextResolver) as the core wants to use the platform agnostic term of "Issuer" instead of Sender
    - + co.aikar.commands.CommandIssuer.sendMessageInternal(String)
    Do not call this, for internal use. Not considered part of the API and may break.
    - + co.aikar.commands.CommandManager.setDefaultHelpPerPage(int)
    Unstable API
    - + co.aikar.commands.BaseCommand.showCommandHelp()
    Unstable API
    diff --git a/docs/acf-core/index-all.html b/docs/acf-core/index-all.html index 37dd2de4..7b646f96 100644 --- a/docs/acf-core/index-all.html +++ b/docs/acf-core/index-all.html @@ -577,6 +577,10 @@
    getPassedArgs() - Method in class co.aikar.commands.CommandExecutionContext
     
    getPermission() - Method in class co.aikar.commands.RegisteredCommand
    +
    +
    Deprecated. 
    +
    +
    getPermissions() - Method in class co.aikar.commands.RegisteredCommand
     
    getPrefSubCommand() - Method in class co.aikar.commands.RegisteredCommand
     
    @@ -1211,6 +1215,8 @@
     
    replaceStrings(String, String...) - Static method in class co.aikar.commands.ACFUtil
     
    +
    requiresPermission(String) - Method in class co.aikar.commands.RegisteredCommand
    +
     
    ROMANIAN - Static variable in class co.aikar.commands.Locales
     
    rootCommands - Variable in class co.aikar.commands.CommandManager
    diff --git a/docs/acf-core/src-html/co/aikar/commands/RegisteredCommand.html b/docs/acf-core/src-html/co/aikar/commands/RegisteredCommand.html index 4095bf33..4842a9ae 100644 --- a/docs/acf-core/src-html/co/aikar/commands/RegisteredCommand.html +++ b/docs/acf-core/src-html/co/aikar/commands/RegisteredCommand.html @@ -36,238 +36,260 @@ 028import co.aikar.commands.contexts.IssuerAwareContextResolver; 029import co.aikar.commands.contexts.IssuerOnlyContextResolver; 030import co.aikar.commands.contexts.OptionalContextResolver; -031import com.google.common.collect.Lists; -032import com.google.common.collect.Maps; -033import com.google.common.collect.Sets; -034import org.jetbrains.annotations.Nullable; -035 -036import java.lang.reflect.InvocationTargetException; -037import java.lang.reflect.Method; -038import java.lang.reflect.Parameter; -039import java.util.ArrayList; -040import java.util.Collection; -041import java.util.List; -042import java.util.Map; -043import java.util.Set; -044import java.util.stream.Collectors; -045 -046public class RegisteredCommand <R extends CommandExecutionContext<? extends CommandExecutionContext, ? extends CommandIssuer>> { -047 final BaseCommand scope; -048 final String command; -049 final Method method; -050 final String prefSubCommand; -051 final Parameter[] parameters; -052 final ContextResolver<?, R>[] resolvers; -053 final String syntaxText; -054 final String helpText; -055 -056 private final String permission; -057 final String complete; -058 final int requiredResolvers; -059 final int optionalResolvers; -060 final List<String> registeredSubcommands = new ArrayList<>(); -061 -062 RegisteredCommand(BaseCommand scope, String command, Method method, String prefSubCommand) { -063 this.scope = scope; -064 if ("__unknown".equals(prefSubCommand) || "__default".equals(prefSubCommand)) { -065 prefSubCommand = ""; -066 } -067 this.command = command + (method.getAnnotation(CommandAlias.class) == null && !prefSubCommand.isEmpty() ? prefSubCommand : ""); -068 this.method = method; -069 this.prefSubCommand = prefSubCommand; -070 CommandPermission permissionAnno = method.getAnnotation(CommandPermission.class); -071 this.permission = permissionAnno != null ? scope.manager.getCommandReplacements().replace(permissionAnno.value()) : null; -072 CommandCompletion completionAnno = method.getAnnotation(CommandCompletion.class); -073 this.complete = completionAnno != null ? scope.manager.getCommandReplacements().replace(completionAnno.value()) : null; -074 this.parameters = method.getParameters(); -075 -076 Description descriptionAnno = method.getAnnotation(Description.class); -077 this.helpText = descriptionAnno != null ? descriptionAnno.value() : ""; -078 //noinspection unchecked -079 this.resolvers = new ContextResolver[this.parameters.length]; -080 final Syntax syntaxStr = method.getAnnotation(Syntax.class); -081 final CommandManager manager = scope.manager; -082 final CommandContexts commandContexts = manager.getCommandContexts(); -083 -084 int requiredResolvers = 0; -085 int optionalResolvers = 0; -086 StringBuilder syntaxB = new StringBuilder(64); -087 -088 for (int i = 0; i < parameters.length; i++) { -089 final Parameter parameter = parameters[i]; -090 final Class<?> type = parameter.getType(); -091 -092 //noinspection unchecked -093 final ContextResolver<?, R> resolver = commandContexts.getResolver(type); -094 if (resolver != null) { -095 resolvers[i] = resolver; -096 -097 if (!scope.manager.isCommandIssuer(type)) { -098 String name = parameter.getName(); -099 if (isOptionalResolver(resolver, parameter)) { -100 optionalResolvers++; -101 if (!(resolver instanceof IssuerOnlyContextResolver)) { -102 syntaxB.append('[').append(name).append("] "); -103 } -104 } else { -105 requiredResolvers++; -106 syntaxB.append('<').append(name).append("> "); -107 } -108 } -109 } else { -110 ACFUtil.sneaky(new InvalidCommandContextException( -111 "Parameter " + type.getSimpleName() + " of " + this.command + " has no applicable context resolver" -112 )); -113 } -114 } -115 String syntaxText = syntaxB.toString(); -116 this.syntaxText = manager.getCommandReplacements().replace(syntaxStr != null ? -117 ACFUtil.replace(syntaxStr.value(), "@syntax", syntaxText) : syntaxText); -118 this.requiredResolvers = requiredResolvers; -119 this.optionalResolvers = optionalResolvers; -120 } -121 -122 private boolean isOptionalResolver(ContextResolver<?, R> resolver, Parameter parameter) { -123 return isOptionalResolver(resolver) -124 || parameter.getAnnotation(Optional.class) != null -125 || parameter.getAnnotation(Default.class) != null; -126 } -127 -128 private boolean isOptionalResolver(ContextResolver<?, R> resolver) { -129 return resolver instanceof IssuerAwareContextResolver || resolver instanceof IssuerOnlyContextResolver -130 || resolver instanceof OptionalContextResolver; -131 } -132 -133 void invoke(CommandIssuer sender, List<String> args) { -134 if (!scope.canExecute(sender, this)) { -135 return; -136 } -137 preCommand(); -138 try { -139 Map<String, Object> passedArgs = resolveContexts(sender, args); -140 if (passedArgs == null) return; -141 -142 method.invoke(scope, passedArgs.values().toArray()); -143 } catch (Exception e) { -144 handleException(sender, args, e); -145 } -146 postCommand(); -147 } -148 public void preCommand() {} -149 public void postCommand() {} -150 -151 void handleException(CommandIssuer sender, List<String> args, Exception e) { -152 if (e instanceof InvocationTargetException && e.getCause() instanceof InvalidCommandArgument) { -153 e = (Exception) e.getCause(); -154 } -155 if (e instanceof InvalidCommandArgument) { -156 InvalidCommandArgument ica = (InvalidCommandArgument) e; -157 if (ica.key != null) { -158 sender.sendMessage(MessageType.ERROR, ica.key, ica.replacements); -159 } else if (e.getMessage() != null && !e.getMessage().isEmpty()) { -160 sender.sendMessage(MessageType.ERROR, MessageKeys.ERROR_PREFIX, "{message}", e.getMessage()); -161 } -162 if (ica.showSyntax) { -163 scope.showSyntax(sender, this); -164 } -165 } else { -166 boolean handeled = this.scope.manager.handleUncaughtException(scope, this, sender, args, e); -167 if(!handeled){ -168 sender.sendMessage(MessageType.ERROR, MessageKeys.ERROR_PERFORMING_COMMAND); -169 } -170 this.scope.manager.log(LogLevel.ERROR, "Exception in command: " + command + " " + ACFUtil.join(args), e); -171 } -172 } -173 -174 @Nullable -175 Map<String, Object> resolveContexts(CommandIssuer sender, List<String> args) throws InvalidCommandArgument { -176 return resolveContexts(sender, args, parameters.length); -177 } -178 @Nullable -179 Map<String, Object> resolveContexts(CommandIssuer sender, List<String> args, int argLimit) throws InvalidCommandArgument { -180 args = Lists.newArrayList(args); -181 String[] origArgs = args.toArray(new String[args.size()]); -182 Map<String, Object> passedArgs = Maps.newLinkedHashMap(); -183 int remainingRequired = requiredResolvers; -184 for (int i = 0; i < parameters.length && i < argLimit; i++) { -185 boolean isLast = i == parameters.length - 1; -186 boolean allowOptional = remainingRequired == 0; -187 final Parameter parameter = parameters[i]; -188 final String parameterName = parameter.getName(); -189 final Class<?> type = parameter.getType(); -190 //noinspection unchecked -191 final ContextResolver<?, R> resolver = resolvers[i]; -192 R context = this.scope.manager.createCommandContext(this, parameter, sender, args, i, passedArgs); -193 boolean isOptionalResolver = isOptionalResolver(resolver, parameter); -194 if (!isOptionalResolver) { -195 remainingRequired--; -196 } -197 if (args.isEmpty() && !(isLast && type == String[].class)) { -198 Default def = parameter.getAnnotation(Default.class); -199 Optional opt = parameter.getAnnotation(Optional.class); -200 if (allowOptional && def != null) { -201 args.add(scope.manager.getCommandReplacements().replace(def.value())); -202 } else if (allowOptional && opt != null) { -203 passedArgs.put(parameterName, isOptionalResolver(resolver) ? resolver.getContext(context) : null); -204 //noinspection UnnecessaryContinue -205 continue; -206 } else if (!isOptionalResolver) { -207 scope.showSyntax(sender, this); -208 return null; -209 } -210 } -211 final Values values = parameter.getAnnotation(Values.class); -212 if (values != null) { -213 String arg = !args.isEmpty() ? args.get(0) : ""; -214 -215 final String[] split = ACFPatterns.PIPE.split(scope.manager.getCommandReplacements().replace(values.value())); -216 Set<String> possible = Sets.newHashSet(); -217 for (String s : split) { -218 List<String> check = this.scope.manager.getCommandCompletions().getCompletionValues(this, sender, s, origArgs); -219 if (!check.isEmpty()) { -220 possible.addAll(check.stream().map(String::toLowerCase).collect(Collectors.toList())); -221 } else { -222 possible.add(s.toLowerCase()); -223 } -224 } -225 -226 if (!possible.contains(arg.toLowerCase())) { -227 throw new InvalidCommandArgument(MessageKeys.PLEASE_SPECIFY_ONE_OF, -228 "{valid}", ACFUtil.join(possible, ", ")); -229 } -230 } -231 passedArgs.put(parameterName, resolver.getContext(context)); -232 } -233 return passedArgs; -234 } -235 -236 boolean hasPermission(CommandIssuer issuer) { -237 return (permission == null || permission.isEmpty() || scope.manager.hasPermission(issuer, permission)) && scope.hasPermission(issuer); -238 } -239 -240 public String getPermission() { -241 return permission; -242 } -243 -244 public String getPrefSubCommand() { -245 return prefSubCommand; -246 } -247 -248 public String getSyntaxText() { -249 return syntaxText; -250 } -251 -252 public String getCommand() { -253 return command; -254 } -255 -256 public void addSubcommand(String cmd) { -257 this.registeredSubcommands.add(cmd); -258 } -259 public void addSubcommands(Collection<String> cmd) { -260 this.registeredSubcommands.addAll(cmd); -261 } -262} +031import com.google.common.collect.ImmutableSet; +032import com.google.common.collect.Lists; +033import com.google.common.collect.Maps; +034import com.google.common.collect.Sets; +035import org.jetbrains.annotations.Nullable; +036 +037import java.lang.reflect.InvocationTargetException; +038import java.lang.reflect.Method; +039import java.lang.reflect.Parameter; +040import java.util.ArrayList; +041import java.util.Collection; +042import java.util.List; +043import java.util.Map; +044import java.util.Set; +045import java.util.stream.Collectors; +046 +047@SuppressWarnings("WeakerAccess") +048public class RegisteredCommand <R extends CommandExecutionContext<? extends CommandExecutionContext, ? extends CommandIssuer>> { +049 final BaseCommand scope; +050 final String command; +051 final Method method; +052 final String prefSubCommand; +053 final Parameter[] parameters; +054 final ContextResolver<?, R>[] resolvers; +055 final String syntaxText; +056 final String helpText; +057 +058 private final String permission; +059 final String complete; +060 final int requiredResolvers; +061 final int optionalResolvers; +062 final List<String> registeredSubcommands = new ArrayList<>(); +063 +064 RegisteredCommand(BaseCommand scope, String command, Method method, String prefSubCommand) { +065 this.scope = scope; +066 if ("__unknown".equals(prefSubCommand) || "__default".equals(prefSubCommand)) { +067 prefSubCommand = ""; +068 } +069 this.command = command + (method.getAnnotation(CommandAlias.class) == null && !prefSubCommand.isEmpty() ? prefSubCommand : ""); +070 this.method = method; +071 this.prefSubCommand = prefSubCommand; +072 CommandPermission permissionAnno = method.getAnnotation(CommandPermission.class); +073 this.permission = permissionAnno != null ? scope.manager.getCommandReplacements().replace(permissionAnno.value()) : null; +074 CommandCompletion completionAnno = method.getAnnotation(CommandCompletion.class); +075 this.complete = completionAnno != null ? scope.manager.getCommandReplacements().replace(completionAnno.value()) : null; +076 this.parameters = method.getParameters(); +077 +078 Description descriptionAnno = method.getAnnotation(Description.class); +079 this.helpText = descriptionAnno != null ? descriptionAnno.value() : ""; +080 //noinspection unchecked +081 this.resolvers = new ContextResolver[this.parameters.length]; +082 final Syntax syntaxStr = method.getAnnotation(Syntax.class); +083 final CommandManager manager = scope.manager; +084 final CommandContexts commandContexts = manager.getCommandContexts(); +085 +086 int requiredResolvers = 0; +087 int optionalResolvers = 0; +088 StringBuilder syntaxB = new StringBuilder(64); +089 +090 for (int i = 0; i < parameters.length; i++) { +091 final Parameter parameter = parameters[i]; +092 final Class<?> type = parameter.getType(); +093 +094 //noinspection unchecked +095 final ContextResolver<?, R> resolver = commandContexts.getResolver(type); +096 if (resolver != null) { +097 resolvers[i] = resolver; +098 +099 if (!scope.manager.isCommandIssuer(type)) { +100 String name = parameter.getName(); +101 if (isOptionalResolver(resolver, parameter)) { +102 optionalResolvers++; +103 if (!(resolver instanceof IssuerOnlyContextResolver)) { +104 syntaxB.append('[').append(name).append("] "); +105 } +106 } else { +107 requiredResolvers++; +108 syntaxB.append('<').append(name).append("> "); +109 } +110 } +111 } else { +112 ACFUtil.sneaky(new InvalidCommandContextException( +113 "Parameter " + type.getSimpleName() + " of " + this.command + " has no applicable context resolver" +114 )); +115 } +116 } +117 String syntaxText = syntaxB.toString(); +118 this.syntaxText = manager.getCommandReplacements().replace(syntaxStr != null ? +119 ACFUtil.replace(syntaxStr.value(), "@syntax", syntaxText) : syntaxText); +120 this.requiredResolvers = requiredResolvers; +121 this.optionalResolvers = optionalResolvers; +122 } +123 +124 private boolean isOptionalResolver(ContextResolver<?, R> resolver, Parameter parameter) { +125 return isOptionalResolver(resolver) +126 || parameter.getAnnotation(Optional.class) != null +127 || parameter.getAnnotation(Default.class) != null; +128 } +129 +130 private boolean isOptionalResolver(ContextResolver<?, R> resolver) { +131 return resolver instanceof IssuerAwareContextResolver || resolver instanceof IssuerOnlyContextResolver +132 || resolver instanceof OptionalContextResolver; +133 } +134 +135 void invoke(CommandIssuer sender, List<String> args) { +136 if (!scope.canExecute(sender, this)) { +137 return; +138 } +139 preCommand(); +140 try { +141 Map<String, Object> passedArgs = resolveContexts(sender, args); +142 if (passedArgs == null) return; +143 +144 method.invoke(scope, passedArgs.values().toArray()); +145 } catch (Exception e) { +146 handleException(sender, args, e); +147 } +148 postCommand(); +149 } +150 public void preCommand() {} +151 public void postCommand() {} +152 +153 void handleException(CommandIssuer sender, List<String> args, Exception e) { +154 if (e instanceof InvocationTargetException && e.getCause() instanceof InvalidCommandArgument) { +155 e = (Exception) e.getCause(); +156 } +157 if (e instanceof InvalidCommandArgument) { +158 InvalidCommandArgument ica = (InvalidCommandArgument) e; +159 if (ica.key != null) { +160 sender.sendMessage(MessageType.ERROR, ica.key, ica.replacements); +161 } else if (e.getMessage() != null && !e.getMessage().isEmpty()) { +162 sender.sendMessage(MessageType.ERROR, MessageKeys.ERROR_PREFIX, "{message}", e.getMessage()); +163 } +164 if (ica.showSyntax) { +165 scope.showSyntax(sender, this); +166 } +167 } else { +168 boolean handeled = this.scope.manager.handleUncaughtException(scope, this, sender, args, e); +169 if(!handeled){ +170 sender.sendMessage(MessageType.ERROR, MessageKeys.ERROR_PERFORMING_COMMAND); +171 } +172 this.scope.manager.log(LogLevel.ERROR, "Exception in command: " + command + " " + ACFUtil.join(args), e); +173 } +174 } +175 +176 @Nullable +177 Map<String, Object> resolveContexts(CommandIssuer sender, List<String> args) throws InvalidCommandArgument { +178 return resolveContexts(sender, args, parameters.length); +179 } +180 @Nullable +181 Map<String, Object> resolveContexts(CommandIssuer sender, List<String> args, int argLimit) throws InvalidCommandArgument { +182 args = Lists.newArrayList(args); +183 String[] origArgs = args.toArray(new String[args.size()]); +184 Map<String, Object> passedArgs = Maps.newLinkedHashMap(); +185 int remainingRequired = requiredResolvers; +186 for (int i = 0; i < parameters.length && i < argLimit; i++) { +187 boolean isLast = i == parameters.length - 1; +188 boolean allowOptional = remainingRequired == 0; +189 final Parameter parameter = parameters[i]; +190 final String parameterName = parameter.getName(); +191 final Class<?> type = parameter.getType(); +192 //noinspection unchecked +193 final ContextResolver<?, R> resolver = resolvers[i]; +194 R context = this.scope.manager.createCommandContext(this, parameter, sender, args, i, passedArgs); +195 boolean isOptionalResolver = isOptionalResolver(resolver, parameter); +196 if (!isOptionalResolver) { +197 remainingRequired--; +198 } +199 if (args.isEmpty() && !(isLast && type == String[].class)) { +200 Default def = parameter.getAnnotation(Default.class); +201 Optional opt = parameter.getAnnotation(Optional.class); +202 if (allowOptional && def != null) { +203 args.add(scope.manager.getCommandReplacements().replace(def.value())); +204 } else if (allowOptional && opt != null) { +205 passedArgs.put(parameterName, isOptionalResolver(resolver) ? resolver.getContext(context) : null); +206 //noinspection UnnecessaryContinue +207 continue; +208 } else if (!isOptionalResolver) { +209 scope.showSyntax(sender, this); +210 return null; +211 } +212 } +213 final Values values = parameter.getAnnotation(Values.class); +214 if (values != null) { +215 String arg = !args.isEmpty() ? args.get(0) : ""; +216 +217 final String[] split = ACFPatterns.PIPE.split(scope.manager.getCommandReplacements().replace(values.value())); +218 Set<String> possible = Sets.newHashSet(); +219 for (String s : split) { +220 List<String> check = this.scope.manager.getCommandCompletions().getCompletionValues(this, sender, s, origArgs); +221 if (!check.isEmpty()) { +222 possible.addAll(check.stream().map(String::toLowerCase).collect(Collectors.toList())); +223 } else { +224 possible.add(s.toLowerCase()); +225 } +226 } +227 +228 if (!possible.contains(arg.toLowerCase())) { +229 throw new InvalidCommandArgument(MessageKeys.PLEASE_SPECIFY_ONE_OF, +230 "{valid}", ACFUtil.join(possible, ", ")); +231 } +232 } +233 passedArgs.put(parameterName, resolver.getContext(context)); +234 } +235 return passedArgs; +236 } +237 +238 boolean hasPermission(CommandIssuer issuer) { +239 return (permission == null || permission.isEmpty() || scope.manager.hasPermission(issuer, permission)) && scope.hasPermission(issuer); +240 } +241 +242 +243 /** +244 * @see #getPermissions() +245 * @deprecated +246 */ +247 @Deprecated +248 public String getPermission() { +249 if (this.permission == null || this.permission.isEmpty()) { +250 return null; +251 } +252 return ACFPatterns.COMMA.split(this.permission)[0]; +253 } +254 +255 public Set<String> getPermissions() { +256 if (this.permission == null || this.permission.isEmpty()) { +257 return ImmutableSet.of(); +258 } +259 return Sets.newHashSet(ACFPatterns.COMMA.split(this.permission)); +260 } +261 +262 public boolean requiresPermission(String permission) { +263 return getPermissions().contains(permission); +264 } +265 +266 public String getPrefSubCommand() { +267 return prefSubCommand; +268 } +269 +270 public String getSyntaxText() { +271 return syntaxText; +272 } +273 +274 public String getCommand() { +275 return command; +276 } +277 +278 public void addSubcommand(String cmd) { +279 this.registeredSubcommands.add(cmd); +280 } +281 public void addSubcommands(Collection<String> cmd) { +282 this.registeredSubcommands.addAll(cmd); +283 } +284} diff --git a/docs/acf-sponge/co/aikar/commands/SpongeRegisteredCommand.html b/docs/acf-sponge/co/aikar/commands/SpongeRegisteredCommand.html index d2b0af05..4ed20eda 100644 --- a/docs/acf-sponge/co/aikar/commands/SpongeRegisteredCommand.html +++ b/docs/acf-sponge/co/aikar/commands/SpongeRegisteredCommand.html @@ -148,7 +148,7 @@ extends co.aikar.commands.RegisteredCommand<