/** * Create a new instance using the given context. * * @param context the context * @param arguments an argument string to be parsed * @param nonNullBoolean true to have {@link #nextBoolean()} return false instead of null */ public StringArgumentStack( CommandContext context, String arguments, boolean nonNullBoolean) { this.context = context; this.arguments = CommandContext.split(arguments); this.nonNullBoolean = nonNullBoolean; }
public CommandArgs parse(String arguments) throws CommandException { CommandContext context = new CommandContext(CommandContext.split("_ " + arguments), Collections.<Character>emptySet(), false, null, false); List<String> args = Lists.newArrayList(); for (int i = 0; i < context.argsLength(); i++) { args.add(context.getString(i)); } if (isUsingHangingArguments()) { if (arguments.isEmpty() || arguments.endsWith(" ")) { args.add(""); } } return new CommandArgs(args); } }
@Override public List<String> getSuggestions(String arguments, CommandLocals locals) throws CommandException { String[] split = CommandContext.split(arguments); if (split.length <= 1) { String prefix = split.length > 0 ? split[0] : ""; List<String> suggestions = new ArrayList<>(); for (CommandMapping mapping : getCommands()) { if (mapping.getCallable().testPermission(locals)) { for (String alias : mapping.getAllAliases()) { if (prefix.isEmpty() || alias.startsWith(arguments)) { suggestions.add(mapping.getPrimaryAlias()); break; } } } } return suggestions; } else { String subCommand = split[0]; CommandMapping mapping = get(subCommand); String passedArguments = Joiner.on(" ").join(Arrays.copyOfRange(split, 1, split.length)); if (mapping != null) { return mapping.getCallable().getSuggestions(passedArguments, locals); } else { return Collections.emptyList(); } } }
@Override public Object call(String arguments, CommandLocals locals, String[] parentCommands) throws CommandException { // We have permission for this command if we have permissions for subcommands if (parentCommands.length != 0 && !testPermission(locals)) { throw new CommandPermissionsException(); } String[] split = CommandContext.split(arguments); Set<String> aliases = getPrimaryAliases(); if (aliases.isEmpty()) { throw new InvalidUsageException("This command has no sub-commands.", this); } else if (split.length > 0) { String subCommand = split[0]; String subArguments = Joiner.on(" ").join(Arrays.copyOfRange(split, 1, split.length)); String[] subParents = Arrays.copyOf(parentCommands, parentCommands.length + 1); subParents[parentCommands.length] = subCommand; CommandMapping mapping = get(subCommand); if (mapping != null) { try { return mapping.getCallable().call(subArguments, locals, subParents); } catch (CommandException e) { e.prependStack(subCommand); throw e; } catch (Throwable t) { throw new WrappedCommandException(t); } } } throw new InvalidUsageException("Please choose a sub-command.", this, true); }
String[] split = CommandContext.split(calledCommand + " " + stringArguments); CommandContext context = new CommandContext(split, getValueFlags(), false, locals);