Search in sources :

Example 1 with ICommandArgument

use of baritone.api.command.argument.ICommandArgument in project baritone by cabaletta.

the class ArgConsumer method get.

@Override
public ICommandArgument get() throws CommandNotEnoughArgumentsException {
    requireMin(1);
    ICommandArgument arg = args.removeFirst();
    consumed.add(arg);
    return arg;
}
Also used : ICommandArgument(baritone.api.command.argument.ICommandArgument)

Example 2 with ICommandArgument

use of baritone.api.command.argument.ICommandArgument in project baritone by cabaletta.

the class CommandManager method tabComplete.

@Override
public Stream<String> tabComplete(String prefix) {
    Tuple<String, List<ICommandArgument>> pair = expand(prefix, true);
    String label = pair.getFirst();
    List<ICommandArgument> args = pair.getSecond();
    if (args.isEmpty()) {
        return new TabCompleteHelper().addCommands(this.baritone.getCommandManager()).filterPrefix(label).stream();
    } else {
        return tabComplete(pair);
    }
}
Also used : ICommandArgument(baritone.api.command.argument.ICommandArgument) List(java.util.List) TabCompleteHelper(baritone.api.command.helpers.TabCompleteHelper)

Example 3 with ICommandArgument

use of baritone.api.command.argument.ICommandArgument in project Spark-Client by Spark-Client-Development.

the class ExampleBaritoneControl method tabComplete.

public Stream<String> tabComplete(String msg) {
    try {
        List<ICommandArgument> args = CommandArguments.from(msg, true);
        ArgConsumer argc = new ArgConsumer(this.manager, args);
        if (argc.hasAtMost(2)) {
            if (argc.hasExactly(1)) {
                return new TabCompleteHelper().addCommands(this.manager).addSettings().filterPrefix(argc.getString()).stream();
            }
            Settings.Setting setting = settings.byLowerName.get(argc.getString().toLowerCase(Locale.US));
            if (setting != null) {
                if (setting.getValueClass() == Boolean.class) {
                    TabCompleteHelper helper = new TabCompleteHelper();
                    if ((Boolean) setting.getValue()) {
                        helper.append("true", "false");
                    } else {
                        helper.append("false", "true");
                    }
                    return helper.filterPrefix(argc.getString()).stream();
                } else {
                    return Stream.of(SettingsUtil.settingValueToString(setting));
                }
            }
        }
        return this.manager.tabComplete(msg);
    } catch (CommandNotEnoughArgumentsException ignored) {
        // Shouldn't happen, the operation is safe
        return Stream.empty();
    }
}
Also used : ICommandArgument(baritone.api.command.argument.ICommandArgument) TabCompleteHelper(baritone.api.command.helpers.TabCompleteHelper) ArgConsumer(baritone.command.argument.ArgConsumer) Settings(baritone.api.Settings) CommandNotEnoughArgumentsException(baritone.api.command.exception.CommandNotEnoughArgumentsException)

Example 4 with ICommandArgument

use of baritone.api.command.argument.ICommandArgument in project Spark-Client by Spark-Client-Development.

the class ArgConsumer method get.

@Override
public ICommandArgument get() throws CommandNotEnoughArgumentsException {
    requireMin(1);
    ICommandArgument arg = args.removeFirst();
    consumed.add(arg);
    return arg;
}
Also used : ICommandArgument(baritone.api.command.argument.ICommandArgument)

Example 5 with ICommandArgument

use of baritone.api.command.argument.ICommandArgument in project Spark-Client by Spark-Client-Development.

the class CommandArguments method from.

/**
 * Turn a string into a list of {@link ICommandArgument}s. This is needed because of {@link ICommandArgument#getRawRest()}
 *
 * @param string            The string to convert
 * @param preserveEmptyLast If the string ends with whitespace, add an empty {@link ICommandArgument} to the end This
 *                          is useful for tab completion
 * @return A list of {@link ICommandArgument}s
 */
public static List<ICommandArgument> from(String string, boolean preserveEmptyLast) {
    List<ICommandArgument> args = new ArrayList<>();
    Matcher argMatcher = ARG_PATTERN.matcher(string);
    int lastEnd = -1;
    while (argMatcher.find()) {
        args.add(new CommandArgument(args.size(), argMatcher.group(), string.substring(argMatcher.start())));
        lastEnd = argMatcher.end();
    }
    if (preserveEmptyLast && lastEnd < string.length()) {
        args.add(new CommandArgument(args.size(), "", ""));
    }
    return args;
}
Also used : Matcher(java.util.regex.Matcher) ICommandArgument(baritone.api.command.argument.ICommandArgument) ICommandArgument(baritone.api.command.argument.ICommandArgument) ArrayList(java.util.ArrayList)

Aggregations

ICommandArgument (baritone.api.command.argument.ICommandArgument)10 TabCompleteHelper (baritone.api.command.helpers.TabCompleteHelper)6 Settings (baritone.api.Settings)4 CommandNotEnoughArgumentsException (baritone.api.command.exception.CommandNotEnoughArgumentsException)4 ArgConsumer (baritone.command.argument.ArgConsumer)4 List (java.util.List)4 BaritoneAPI (baritone.api.BaritoneAPI)2 IBaritone (baritone.api.IBaritone)2 FORCE_COMMAND_PREFIX (baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX)2 CommandNotFoundException (baritone.api.command.exception.CommandNotFoundException)2 ICommandManager (baritone.api.command.manager.ICommandManager)2 ChatEvent (baritone.api.event.events.ChatEvent)2 TabCompleteEvent (baritone.api.event.events.TabCompleteEvent)2 AbstractGameEventListener (baritone.api.event.listener.AbstractGameEventListener)2 Helper (baritone.api.utils.Helper)2 SettingsUtil (baritone.api.utils.SettingsUtil)2 CommandArguments (baritone.command.argument.CommandArguments)2 CommandManager (baritone.command.manager.CommandManager)2 IGuiScreen (baritone.utils.accessor.IGuiScreen)2 URI (java.net.URI)2