Search in sources :

Example 1 with ArgConsumer

use of baritone.command.argument.ArgConsumer 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 2 with ArgConsumer

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

the class ExampleBaritoneControl method runCommand.

public boolean runCommand(String msg) {
    if (msg.trim().equalsIgnoreCase("damn")) {
        logDirect("daniel");
        return false;
    } else if (msg.trim().equalsIgnoreCase("orderpizza")) {
        try {
            ((IGuiScreen) mc.currentScreen).openLink(new URI("https://www.dominos.com/en/pages/order/"));
        } catch (NullPointerException | URISyntaxException ignored) {
        }
        return false;
    }
    if (msg.isEmpty()) {
        return this.runCommand("help");
    }
    Tuple<String, List<ICommandArgument>> pair = CommandManager.expand(msg);
    String command = pair.getFirst();
    String rest = msg.substring(pair.getFirst().length());
    ArgConsumer argc = new ArgConsumer(this.manager, pair.getSecond());
    if (!argc.hasAny()) {
        Settings.Setting setting = settings.byLowerName.get(command.toLowerCase(Locale.US));
        if (setting != null) {
            logRanCommand(command, rest);
            if (setting.getValueClass() == Boolean.class) {
                this.manager.execute(String.format("set toggle %s", setting.getName()));
            } else {
                this.manager.execute(String.format("set %s", setting.getName()));
            }
            return true;
        }
    } else if (argc.hasExactlyOne()) {
        for (Settings.Setting setting : settings.allSettings) {
            if (setting.getName().equals("logger")) {
                continue;
            }
            if (setting.getName().equalsIgnoreCase(pair.getFirst())) {
                logRanCommand(command, rest);
                try {
                    this.manager.execute(String.format("set %s %s", setting.getName(), argc.getString()));
                }// The operation is safe
                 catch (CommandNotEnoughArgumentsException ignored) {
                }
                return true;
            }
        }
    }
    // If the command exists, then handle echoing the input
    if (this.manager.getCommand(pair.getFirst()) != null) {
        logRanCommand(command, rest);
    }
    return this.manager.execute(pair);
}
Also used : List(java.util.List) TextComponentString(net.minecraft.util.text.TextComponentString) URI(java.net.URI) ArgConsumer(baritone.command.argument.ArgConsumer) Settings(baritone.api.Settings) CommandNotEnoughArgumentsException(baritone.api.command.exception.CommandNotEnoughArgumentsException)

Example 3 with ArgConsumer

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

the class CommandManager method from.

private ExecutionWrapper from(Tuple<String, List<ICommandArgument>> expanded) {
    String label = expanded.getFirst();
    ArgConsumer args = new ArgConsumer(this, expanded.getSecond());
    ICommand command = this.getCommand(label);
    return command == null ? null : new ExecutionWrapper(command, label, args);
}
Also used : ICommand(baritone.api.command.ICommand) ArgConsumer(baritone.command.argument.ArgConsumer)

Example 4 with ArgConsumer

use of baritone.command.argument.ArgConsumer 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 5 with ArgConsumer

use of baritone.command.argument.ArgConsumer in project baritone by cabaletta.

the class ExampleBaritoneControl method runCommand.

public boolean runCommand(String msg) {
    if (msg.trim().equalsIgnoreCase("damn")) {
        logDirect("daniel");
        return false;
    } else if (msg.trim().equalsIgnoreCase("orderpizza")) {
        try {
            ((IGuiScreen) mc.currentScreen).openLink(new URI("https://www.dominos.com/en/pages/order/"));
        } catch (NullPointerException | URISyntaxException ignored) {
        }
        return false;
    }
    if (msg.isEmpty()) {
        return this.runCommand("help");
    }
    Tuple<String, List<ICommandArgument>> pair = CommandManager.expand(msg);
    String command = pair.getFirst();
    String rest = msg.substring(pair.getFirst().length());
    ArgConsumer argc = new ArgConsumer(this.manager, pair.getSecond());
    if (!argc.hasAny()) {
        Settings.Setting setting = settings.byLowerName.get(command.toLowerCase(Locale.US));
        if (setting != null) {
            logRanCommand(command, rest);
            if (setting.getValueClass() == Boolean.class) {
                this.manager.execute(String.format("set toggle %s", setting.getName()));
            } else {
                this.manager.execute(String.format("set %s", setting.getName()));
            }
            return true;
        }
    } else if (argc.hasExactlyOne()) {
        for (Settings.Setting setting : settings.allSettings) {
            if (SettingsUtil.javaOnlySetting(setting)) {
                continue;
            }
            if (setting.getName().equalsIgnoreCase(pair.getFirst())) {
                logRanCommand(command, rest);
                try {
                    this.manager.execute(String.format("set %s %s", setting.getName(), argc.getString()));
                }// The operation is safe
                 catch (CommandNotEnoughArgumentsException ignored) {
                }
                return true;
            }
        }
    }
    // If the command exists, then handle echoing the input
    if (this.manager.getCommand(pair.getFirst()) != null) {
        logRanCommand(command, rest);
    }
    return this.manager.execute(pair);
}
Also used : List(java.util.List) TextComponentString(net.minecraft.util.text.TextComponentString) URI(java.net.URI) ArgConsumer(baritone.command.argument.ArgConsumer) Settings(baritone.api.Settings) CommandNotEnoughArgumentsException(baritone.api.command.exception.CommandNotEnoughArgumentsException)

Aggregations

ArgConsumer (baritone.command.argument.ArgConsumer)6 Settings (baritone.api.Settings)4 CommandNotEnoughArgumentsException (baritone.api.command.exception.CommandNotEnoughArgumentsException)4 ICommand (baritone.api.command.ICommand)2 ICommandArgument (baritone.api.command.argument.ICommandArgument)2 TabCompleteHelper (baritone.api.command.helpers.TabCompleteHelper)2 URI (java.net.URI)2 List (java.util.List)2 TextComponentString (net.minecraft.util.text.TextComponentString)2