use of org.spongepowered.api.command.args.parsing.SingleArg in project SpongeAPI by SpongePowered.
the class CommandArgs method insertArg.
/**
* Insert an arg as the next arg to be returned by {@link #next()}.
*
* @param value The argument to insert
*/
public void insertArg(String value) {
int index = this.index < 0 ? 0 : this.args.get(this.index).getEndIdx();
this.args.add(this.index + 1, new SingleArg(value, index, index));
}
use of org.spongepowered.api.command.args.parsing.SingleArg in project SpongeAPI by SpongePowered.
the class GenericArgumentsTest method testGettingSinglePlayer.
@Test
public void testGettingSinglePlayer() throws Exception {
CommandArgs args = new CommandArgs("test1", Lists.newArrayList(new SingleArg("test1", 0, 5)));
CommandContext context = new CommandContext();
CommandSource source = Mockito.mock(CommandSource.class);
getPlayerElement().parse(source, args, context);
assertEquals("test1", context.<Player>getOne(Text.of("player")).get().getName());
}
use of org.spongepowered.api.command.args.parsing.SingleArg in project SpongeAPI by SpongePowered.
the class GenericArgumentsTest method testGettingBothPlayers.
@Test
public void testGettingBothPlayers() throws Exception {
CommandArgs args = new CommandArgs("test", Lists.newArrayList(new SingleArg("test", 0, 5)));
CommandContext context = new CommandContext();
CommandSource source = Mockito.mock(CommandSource.class);
getPlayerElement().parse(source, args, context);
Collection<Player> cpl = context.getAll(Text.of("player"));
assertEquals(2, cpl.size());
Collection<String> s = cpl.stream().map(User::getName).collect(Collectors.toList());
assertTrue(s.contains("test1"));
assertTrue(s.contains("test2"));
}
use of org.spongepowered.api.command.args.parsing.SingleArg in project Nucleus by NucleusPowered.
the class AbstractCommand method getSuggestions.
@Override
public List<String> getSuggestions(CommandSource source, String arguments, @Nullable Location<World> targetPosition) throws CommandException {
List<SingleArg> singleArgs = Lists.newArrayList(tokeniser.tokenize(arguments, false));
// If we end with a space - then we add another argument.
if (arguments.isEmpty() || arguments.endsWith(" ")) {
singleArgs.add(new SingleArg("", arguments.length() - 1, arguments.length() - 1));
}
final CommandArgs args = new CommandArgs(arguments, singleArgs);
final List<String> options = Lists.newArrayList();
CommandContext context = new CommandContext();
// We don't care for the value.
context.putArg(COMPLETION_ARG, true);
// Subcommand
Object state = args.getState();
options.addAll(this.dispatcher.getSuggestions(source, arguments, targetPosition));
args.setState(state);
options.addAll(this.argumentParser.complete(source, args, context));
return options.stream().distinct().collect(Collectors.toList());
}
Aggregations