Search in sources :

Example 11 with CommandArgs

use of org.spongepowered.api.command.args.CommandArgs in project Nucleus by NucleusPowered.

the class NicknameArgumentTests method testWhenTwoPlayersWithTheSameNameAreInTheUserDatabaseWithNoExactMatchReturnsOneReturnsIfOnlyOneMatches.

@Test
public void testWhenTwoPlayersWithTheSameNameAreInTheUserDatabaseWithNoExactMatchReturnsOneReturnsIfOnlyOneMatches() throws ArgumentParseException {
    List<?> list = getParser().accept("testt", mockSource(), new CommandArgs("", new ArrayList<>()));
    Assert.assertEquals(1, list.size());
    Assert.assertEquals("testtest", ((User) list.get(0)).getName());
}
Also used : CommandArgs(org.spongepowered.api.command.args.CommandArgs) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 12 with CommandArgs

use of org.spongepowered.api.command.args.CommandArgs in project Nucleus by NucleusPowered.

the class PlayerConsoleArgumentTest method testWhenTwoPlayersWithTheSameNameAreInTheUserDatabaseWithNoExactMatchReturnsOneReturnsIfOnlyOneMatches.

@Test
public void testWhenTwoPlayersWithTheSameNameAreInTheUserDatabaseWithNoExactMatchReturnsOneReturnsIfOnlyOneMatches() throws ArgumentParseException {
    List<?> list = getParser().parseInternal("testt", mockSource(), new CommandArgs("", new ArrayList<>()));
    Assert.assertEquals(1, list.size());
    Assert.assertEquals("testtest", ((User) list.get(0)).getName());
}
Also used : CommandArgs(org.spongepowered.api.command.args.CommandArgs) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 13 with CommandArgs

use of org.spongepowered.api.command.args.CommandArgs in project Nucleus by NucleusPowered.

the class PlayerConsoleArgumentTest method testWhenTwoPlayersWithTheSameNameAreInTheUserDatabaseOnlyAnExactMatchIsReturned.

@Test
public void testWhenTwoPlayersWithTheSameNameAreInTheUserDatabaseOnlyAnExactMatchIsReturned() throws ArgumentParseException {
    List<?> list = getParser().parseInternal("test", mockSource(), new CommandArgs("", new ArrayList<>()));
    Assert.assertEquals(1, list.size());
    Assert.assertEquals("test", ((User) list.get(0)).getName());
}
Also used : CommandArgs(org.spongepowered.api.command.args.CommandArgs) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 14 with CommandArgs

use of org.spongepowered.api.command.args.CommandArgs in project SpongeAPI by SpongePowered.

the class CommandSpec method process.

@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
    checkPermission(source);
    final CommandArgs args = new CommandArgs(arguments, getInputTokenizer().tokenize(arguments, false));
    final CommandContext context = new CommandContext();
    this.populateContext(source, args, context);
    return getExecutor().execute(source, context);
}
Also used : CommandArgs(org.spongepowered.api.command.args.CommandArgs) CommandContext(org.spongepowered.api.command.args.CommandContext)

Example 15 with CommandArgs

use of org.spongepowered.api.command.args.CommandArgs in project AdamantineShield by Karanum.

the class TimeStringArgument method parseValue.

@Override
protected Object parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
    CommandArgs oldState = args;
    String input = args.next();
    try {
        return TimeUtils.timeStringToLong(input);
    } catch (NumberFormatException e) {
        throw oldState.createError(Text.of(TextColors.RED, "Invalid time format: " + input));
    }
}
Also used : CommandArgs(org.spongepowered.api.command.args.CommandArgs)

Aggregations

CommandArgs (org.spongepowered.api.command.args.CommandArgs)21 CommandContext (org.spongepowered.api.command.args.CommandContext)12 ArrayList (java.util.ArrayList)10 CommandSource (org.spongepowered.api.command.CommandSource)10 CommandElement (org.spongepowered.api.command.args.CommandElement)8 List (java.util.List)7 Test (org.junit.Test)7 Nullable (javax.annotation.Nullable)6 ArgumentParseException (org.spongepowered.api.command.args.ArgumentParseException)6 StartsWithPredicate (org.spongepowered.api.util.StartsWithPredicate)6 Text (org.spongepowered.api.text.Text)5 TranslationHelper.t (org.lanternpowered.server.text.translation.TranslationHelper.t)4 CommandResult (org.spongepowered.api.command.CommandResult)4 GenericArguments (org.spongepowered.api.command.args.GenericArguments)4 CommandSpec (org.spongepowered.api.command.spec.CommandSpec)4 PluginContainer (org.spongepowered.api.plugin.PluginContainer)4 ImmutableList (com.google.common.collect.ImmutableList)3 Collectors (java.util.stream.Collectors)3 CommandException (org.spongepowered.api.command.CommandException)3 HashMap (java.util.HashMap)2