@Override public List<String> complete(CommandSource src, CommandArgs args, CommandContext context) { for (int i = 0; i < this.times; ++i) { CommandArgs.Snapshot startState = args.getSnapshot(); try { this.element.parse(src, args, context); } catch (ArgumentParseException e) { args.applySnapshot(startState); return this.element.complete(src, args, context); } } return Collections.emptyList(); }
@Override public void parse(CommandSource source, CommandArgs args, CommandContext context) throws ArgumentParseException { this.element.parse(source, args, context); if (context.getAll(this.element.getUntranslatedKey()).size() > 1) { Text key = this.element.getKey(); throw args.createError(t("Argument %s may have only one value!", key != null ? key : t("unknown"))); } }
@Override public Text getUsage(CommandSource src) { return this.element.getUsage(src); } }
/** * Attempt to extract a value for this element from the given arguments and * put it in the given context. This method normally delegates to * {@link #parseValue(CommandSource, CommandArgs)} for getting the values. * This method is expected to have no side-effects for the source, meaning * that executing it will not change the state of the {@link CommandSource} * in any way. * * @param source The source to parse for * @param args The args to extract from * @param context The context to supply to * @throws ArgumentParseException if unable to extract a value */ public void parse(CommandSource source, CommandArgs args, CommandContext context) throws ArgumentParseException { Object val = parseValue(source, args); String key = getUntranslatedKey(); if (key != null && val != null) { if (val instanceof Iterable<?>) { for (Object ent : ((Iterable<?>) val)) { context.putArg(key, ent); } } else { context.putArg(key, val); } } }
@Override public void parse(CommandSource source, CommandArgs args, CommandContext context) throws ArgumentParseException { for (CommandElement element : this.elements) { element.parse(source, args, context); } }
@Override public List<String> complete(CommandSource src, CommandArgs args, CommandContext context) { return this.element.complete(src, args, context); } }
@Nullable @Override protected Object parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException { return this.wrapped.parseValue(source, args); }
protected WithSuggestionsElement(CommandElement wrapped, Function<CommandSource, Iterable<String>> suggestions, boolean requireBegin) { super(wrapped.getKey()); this.wrapped = wrapped; this.suggestions = suggestions; this.requireBegin = requireBegin; }
@Override public void parse(CommandSource source, CommandArgs args, CommandContext context) throws ArgumentParseException { for (int i = 0; i < this.times; ++i) { this.element.parse(source, args, context); } }
@Override public List<String> complete(CommandSource src, CommandArgs args, CommandContext context) { return this.element.complete(src, args, context); }
@Nullable @Override protected Object parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException { return this.element.parseValue(source, args); }
protected OnlyOneCommandElement(CommandElement element) { super(element.getKey()); this.element = element; }
/** * Attempt to extract a value for this element from the given arguments and * put it in the given context. This method normally delegates to * {@link #parseValue(CommandSource, CommandArgs)} for getting the values. * This method is expected to have no side-effects for the source, meaning * that executing it will not change the state of the {@link CommandSource} * in any way. * * @param source The source to parse for * @param args The args to extract from * @param context The context to supply to * @throws ArgumentParseException if unable to extract a value */ public void parse(CommandSource source, CommandArgs args, CommandContext context) throws ArgumentParseException { Object val = parseValue(source, args); String key = getUntranslatedKey(); if (key != null && val != null) { if (val instanceof Iterable<?>) { for (Object ent : ((Iterable<?>) val)) { context.putArg(key, ent); } } else { context.putArg(key, val); } } }
@Override public List<String> complete(CommandSource src, CommandArgs args, CommandContext context) { while (args.hasNext()) { CommandArgs.Snapshot startState = args.getSnapshot(); try { this.element.parse(src, args, context); } catch (ArgumentParseException e) { args.applySnapshot(startState); return this.element.complete(src, args, context); } } return Collections.emptyList(); }
@Override public void parse(CommandSource source, CommandArgs args, CommandContext context) throws ArgumentParseException { while (args.hasNext()) { this.element.parse(source, args, context); } }
@Override public void parse(CommandSource source, CommandArgs args, CommandContext context) throws ArgumentParseException { if (!args.hasNext()) { Text key = this.element.getKey(); if (key != null && this.value != null) { context.putArg(key.toPlain(), this.value); } return; } CommandArgs.Snapshot startState = args.getSnapshot(); try { this.element.parse(source, args, context); } catch (ArgumentParseException ex) { if (this.considerInvalidFormatEmpty || args.hasNext()) { // If there are more args, suppress. Otherwise, throw the error args.applySnapshot(startState); if (this.element.getKey() != null && this.value != null) { context.putArg(this.element.getUntranslatedKey(), this.value); } } else { throw ex; } } }
/** * Return tab completion results using the existing parsed arguments and * context. Primarily useful when including a subcommand in an existing * specification. * * @param source The source to parse arguments for * @param args The arguments object * @param context The context object * @return possible completions, or an empty list if none */ public List<String> complete(CommandSource source, CommandArgs args, CommandContext context) { checkNotNull(source, "source"); List<String> ret = this.args.complete(source, args, context); return ret == null ? ImmutableList.<String>of() : ImmutableList.copyOf(ret); }
@Override public Text getUsage(CommandSource src) { return this.element.getUsage(src); }
@Nullable @Override protected Object parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException { return this.wrapped.parseValue(source, args); }
protected PermissionCommandElement(CommandElement element, String permission) { super(element.getKey()); this.element = element; this.permission = permission; }