for (String alias : cmd.aliases()) { map.put(alias, method); final String commandName = cmd.aliases()[0]; final String desc = cmd.desc(); final String usage = cmd.usage(); if (usage.isEmpty()) { descs.put(commandName, desc); String help = cmd.help(); if (help.isEmpty()) { help = desc; for (String alias : cmd.aliases()) { final String helpMessage = "/" + alias + " " + arguments + "\n\n" + help; final String key = alias.replaceAll("/", "");
@Command( aliases = { "cui" }, usage = "", desc = "Complete CUI handshake (internal usage)", min = 0, max = 0 ) public void cui(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { session.setCUISupport(true); session.dispatchCUISetup(player); }
char[] flags = cmd.flags().toCharArray(); Set<Character> newFlags = new HashSet<>(); for (int i = 0; i < flags.length; ++i) { if (context.argsLength() < cmd.min()) { throw new CommandUsageException("Too few arguments.", getUsage(args, level, cmd)); if (cmd.max() != -1 && context.argsLength() > cmd.max()) { throw new CommandUsageException("Too many arguments.", getUsage(args, level, cmd)); if (!cmd.anyFlags()) { for (char flag : context.getFlags()) { if (!newFlags.contains(flag)) {
protected CharSequence getArguments(Command cmd) { final String flags = cmd.flags(); final StringBuilder command2 = new StringBuilder(); if (!flags.isEmpty()) { String flagString = flags.replaceAll(".:", ""); if (!flagString.isEmpty()) { command2.append("[-"); for (int i = 0; i < flagString.length(); ++i) { command2.append(flagString.charAt(i)); } command2.append("] "); } } command2.append(cmd.usage()); return command2; }
@Override public void preInvoke(Object object, Method method, ParameterData[] parameters, Object[] args, CommandContext context) throws ParameterException { Command annotation = method.getAnnotation(Command.class); if (annotation != null) { if (context.argsLength() < annotation.min()) { throw new MissingParameterException(); } if (annotation.max() != -1 && context.argsLength() > annotation.max()) { throw new UnconsumedParameterException( context.getRemainingString(annotation.max())); } } }
@Override public void updateDescription(Object object, Method method, ParameterData[] parameters, SimpleDescription description) { Command annotation = method.getAnnotation(Command.class); // Handle the case for old commands where no usage is set and all of its // parameters are provider bindings, so its usage information would // be blank and would imply that there were no accepted parameters if (annotation != null && annotation.usage().isEmpty() && (annotation.min() > 0 || annotation.max() > 0)) { boolean hasUserParameters = false; for (ParameterData parameter : parameters) { if (parameter.getBinding().getBehavior(parameter) != BindingBehavior.PROVIDES) { hasUserParameters = true; break; } } if (!hasUserParameters) { description.overrideUsage("(unknown usage information)"); } } }
public boolean registerAll(List<Command> registered) { List<CommandInfo> toRegister = new ArrayList<>(); for (Command command : registered) { List<String> permissions = null; Method cmdMethod = commands.getMethods().get(null).get(command.aliases()[0]); Map<String, Method> childMethods = commands.getMethods().get(cmdMethod); if (cmdMethod != null && cmdMethod.isAnnotationPresent(CommandPermissions.class)) { permissions = Arrays.asList(cmdMethod.getAnnotation(CommandPermissions.class).value()); } else if (cmdMethod != null && childMethods != null && !childMethods.isEmpty()) { permissions = new ArrayList<>(); for (Method m : childMethods.values()) { if (m.isAnnotationPresent(CommandPermissions.class)) { permissions.addAll(Arrays.asList(m.getAnnotation(CommandPermissions.class).value())); } } } toRegister.add(new CommandInfo(command.usage(), command.desc(), command.aliases(), commands, permissions == null ? null : permissions.toArray(new String[permissions.size()]))); } return register(toRegister); }
anyFlags = definition.anyFlags(); legacyFlags.addAll(Chars.asList(definition.flags().toCharArray())); description.setDescription(!definition.desc().isEmpty() ? definition.desc() : null); description.setHelp(!definition.help().isEmpty() ? definition.help() : null); description.overrideUsage(!definition.usage().isEmpty() ? definition.usage() : null);
stream.print("| " + prefix + cmd.aliases()[0]); stream.print(" || "); if (cmd.aliases().length != 0) { for (String alias : cmd.aliases()) { if (!firstAlias) stream.print("<br />"); stream.print(prefix + alias); if (cmd.flags() != null && !cmd.flags().isEmpty()) { stream.print(cmd.flags()); if (cmd.desc() != null && !cmd.desc().isEmpty()) { stream.print(cmd.desc()); writePermissionsWikiTable(stream, Arrays.asList(nestedClasses), prefix + cmd.aliases()[0] + " ");
/** * Build a list of commands from methods specially annotated with {@link Command} * (and other relevant annotations) and register them all with the given * {@link Dispatcher}. * * @param dispatcher the dispatcher to register commands with * @param object the object contain the methods * @throws ParametricException thrown if the commands cannot be registered */ public void registerMethodsAsCommands(Dispatcher dispatcher, Object object) throws ParametricException { for (Method method : object.getClass().getDeclaredMethods()) { Command definition = method.getAnnotation(Command.class); if (definition != null) { CommandCallable callable = build(object, method, definition); dispatcher.registerCommand(callable, definition.aliases()); } } }
/** * Get the usage string for a command. * * @param args the arguments * @param level the depth of the command * @param cmd the command annotation * @return the usage string */ protected String getUsage(String[] args, int level, Command cmd) { final StringBuilder command = new StringBuilder(); command.append('/'); for (int i = 0; i <= level; ++i) { command.append(args[i]); command.append(' '); } command.append(getArguments(cmd)); final String help = cmd.help(); if (!help.isEmpty()) { command.append("\n\n"); command.append(help); } return command.toString(); }
public boolean registerAll(List<Command> registered) { List<CommandInfo> toRegister = new ArrayList<CommandInfo>(); for (Command command : registered) { String[] permissions = null; Method cmdMethod = commands.getMethods().get(null).get(command.aliases()[0]); if(cmdMethod != null) { if(cmdMethod.isAnnotationPresent(CommandPermissions.class)) { permissions = cmdMethod.getAnnotation(CommandPermissions.class).value(); } } toRegister.add(new CommandInfo(command.usage(), command.desc(), command.aliases(), commands, permissions)); } return register(toRegister); } }
Command childCmd = childMethod.getAnnotation(Command.class); allowedCommands.add(childCmd.aliases()[0]);
protected CharSequence getArguments(Command cmd) { final String flags = cmd.flags(); final StringBuilder command2 = new StringBuilder(); if (!flags.isEmpty()) { String flagString = flags.replaceAll(".:", ""); if (!flagString.isEmpty()) { command2.append("[-"); for (int i = 0; i < flagString.length(); ++i) { command2.append(flagString.charAt(i)); } command2.append("] "); } } command2.append(cmd.usage()); return command2; }
/** * Get the usage string for a command. * * @param args the arguments * @param level the depth of the command * @param cmd the command annotation * @return the usage string */ protected String getUsage(String[] args, int level, Command cmd) { final StringBuilder command = new StringBuilder(); command.append('/'); for (int i = 0; i <= level; ++i) { command.append(args[i]); command.append(' '); } command.append(getArguments(cmd)); final String help = cmd.help(); if (!help.isEmpty()) { command.append("\n\n"); command.append(help); } return command.toString(); }
@Command( aliases = { "help" }, usage = "[<command>]", desc = "Displays help for WorldEdit commands", min = 0, max = -1 ) @CommandPermissions("worldedit.help") public void help(Actor actor, CommandContext args) throws WorldEditException { UtilityCommands.help(args, we, actor); } }
for (String alias : cmd.aliases()) { map.put(alias, method); final String commandName = cmd.aliases()[0]; final String desc = cmd.desc(); final String usage = cmd.usage(); if (usage.isEmpty()) { descs.put(commandName, desc); String help = cmd.help(); if (help.isEmpty()) { help = desc; for (String alias : cmd.aliases()) { final String helpMessage = "/" + alias + " " + arguments + "\n\n" + help; final String key = alias.replaceAll("/", "");
char[] flags = cmd.flags().toCharArray(); Set<Character> newFlags = new HashSet<Character>(); for (int i = 0; i < flags.length; ++i) { if (context.argsLength() < cmd.min()) { throw new CommandUsageException("Too few arguments.", getUsage(args, level, cmd)); if (cmd.max() != -1 && context.argsLength() > cmd.max()) { throw new CommandUsageException("Too many arguments.", getUsage(args, level, cmd)); if (!cmd.anyFlags()) { for (char flag : context.getFlags()) { if (!newFlags.contains(flag)) {
@Command( aliases = { "/help" }, usage = "[<command>]", desc = "Displays help for WorldEdit commands", min = 0, max = -1 ) @CommandPermissions("worldedit.help") public void help(Actor actor, CommandContext args) throws WorldEditException { help(args, we, actor); }