Search in sources :

Example 6 with ICommandArgument

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

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 7 with ICommandArgument

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

the class ExampleBaritoneControl method onPreTabComplete.

@Override
public void onPreTabComplete(TabCompleteEvent event) {
    if (!settings.prefixControl.getValue()) {
        return;
    }
    String prefix = event.prefix;
    String commandPrefix = settings.prefix.getValue();
    if (!prefix.startsWith(commandPrefix)) {
        return;
    }
    String msg = prefix.substring(commandPrefix.length());
    List<ICommandArgument> args = CommandArguments.from(msg, true);
    Stream<String> stream = tabComplete(msg);
    if (args.size() == 1) {
        stream = stream.map(x -> commandPrefix + x);
    }
    event.completions = stream.toArray(String[]::new);
}
Also used : Helper(baritone.api.utils.Helper) CommandNotFoundException(baritone.api.command.exception.CommandNotFoundException) TabCompleteHelper(baritone.api.command.helpers.TabCompleteHelper) URISyntaxException(java.net.URISyntaxException) ClickEvent(net.minecraft.util.text.event.ClickEvent) CommandArguments(baritone.command.argument.CommandArguments) TabCompleteEvent(baritone.api.event.events.TabCompleteEvent) ITextComponent(net.minecraft.util.text.ITextComponent) IBaritone(baritone.api.IBaritone) ICommandArgument(baritone.api.command.argument.ICommandArgument) ChatEvent(baritone.api.event.events.ChatEvent) SettingsUtil(baritone.api.utils.SettingsUtil) Locale(java.util.Locale) CommandNotEnoughArgumentsException(baritone.api.command.exception.CommandNotEnoughArgumentsException) ArgConsumer(baritone.command.argument.ArgConsumer) Settings(baritone.api.Settings) URI(java.net.URI) BaritoneAPI(baritone.api.BaritoneAPI) AbstractGameEventListener(baritone.api.event.listener.AbstractGameEventListener) TextFormatting(net.minecraft.util.text.TextFormatting) IGuiScreen(baritone.utils.accessor.IGuiScreen) Tuple(net.minecraft.util.Tuple) ICommandManager(baritone.api.command.manager.ICommandManager) FORCE_COMMAND_PREFIX(baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX) TextComponentString(net.minecraft.util.text.TextComponentString) List(java.util.List) Stream(java.util.stream.Stream) CommandManager(baritone.command.manager.CommandManager) HoverEvent(net.minecraft.util.text.event.HoverEvent) ICommandArgument(baritone.api.command.argument.ICommandArgument) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 8 with ICommandArgument

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

the class ExampleBaritoneControl method onPreTabComplete.

@Override
public void onPreTabComplete(TabCompleteEvent event) {
    if (!settings.prefixControl.value) {
        return;
    }
    String prefix = event.prefix;
    String commandPrefix = settings.prefix.value;
    if (!prefix.startsWith(commandPrefix)) {
        return;
    }
    String msg = prefix.substring(commandPrefix.length());
    List<ICommandArgument> args = CommandArguments.from(msg, true);
    Stream<String> stream = tabComplete(msg);
    if (args.size() == 1) {
        stream = stream.map(x -> commandPrefix + x);
    }
    event.completions = stream.toArray(String[]::new);
}
Also used : Helper(baritone.api.utils.Helper) CommandNotFoundException(baritone.api.command.exception.CommandNotFoundException) TabCompleteHelper(baritone.api.command.helpers.TabCompleteHelper) URISyntaxException(java.net.URISyntaxException) ClickEvent(net.minecraft.util.text.event.ClickEvent) CommandArguments(baritone.command.argument.CommandArguments) TabCompleteEvent(baritone.api.event.events.TabCompleteEvent) ITextComponent(net.minecraft.util.text.ITextComponent) IBaritone(baritone.api.IBaritone) ICommandArgument(baritone.api.command.argument.ICommandArgument) ChatEvent(baritone.api.event.events.ChatEvent) SettingsUtil(baritone.api.utils.SettingsUtil) Locale(java.util.Locale) CommandNotEnoughArgumentsException(baritone.api.command.exception.CommandNotEnoughArgumentsException) ArgConsumer(baritone.command.argument.ArgConsumer) Settings(baritone.api.Settings) URI(java.net.URI) BaritoneAPI(baritone.api.BaritoneAPI) AbstractGameEventListener(baritone.api.event.listener.AbstractGameEventListener) TextFormatting(net.minecraft.util.text.TextFormatting) IGuiScreen(baritone.utils.accessor.IGuiScreen) Tuple(net.minecraft.util.Tuple) ICommandManager(baritone.api.command.manager.ICommandManager) FORCE_COMMAND_PREFIX(baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX) TextComponentString(net.minecraft.util.text.TextComponentString) List(java.util.List) Stream(java.util.stream.Stream) CommandManager(baritone.command.manager.CommandManager) HoverEvent(net.minecraft.util.text.event.HoverEvent) ICommandArgument(baritone.api.command.argument.ICommandArgument) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 9 with ICommandArgument

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

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 && !SettingsUtil.javaOnlySetting(setting)) {
                if (setting.getValueClass() == Boolean.class) {
                    TabCompleteHelper helper = new TabCompleteHelper();
                    if ((Boolean) setting.value) {
                        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 10 with ICommandArgument

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

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