Search in sources :

Example 6 with CommandInvalidTypeException

use of baritone.api.command.exception.CommandInvalidTypeException in project Spark-Client by Spark-Client-Development.

the class SetCommand method execute.

@Override
public void execute(String label, IArgConsumer args) throws CommandException {
    String arg = args.hasAny() ? args.getString().toLowerCase(Locale.US) : "list";
    if (Arrays.asList("s", "save").contains(arg)) {
        SettingsUtil.save(Baritone.settings());
        logDirect("Settings saved");
        return;
    }
    boolean viewModified = Arrays.asList("m", "mod", "modified").contains(arg);
    boolean viewAll = Arrays.asList("all", "l", "list").contains(arg);
    boolean paginate = viewModified || viewAll;
    if (paginate) {
        String search = args.hasAny() && args.peekAsOrNull(Integer.class) == null ? args.getString() : "";
        args.requireMax(1);
        List<? extends Settings.Setting> toPaginate = (viewModified ? SettingsUtil.modifiedSettings(Baritone.settings()) : Baritone.settings().allSettings).stream().filter(s -> !s.getName().equals("logger")).filter(s -> s.getName().toLowerCase(Locale.US).contains(search.toLowerCase(Locale.US))).sorted((s1, s2) -> String.CASE_INSENSITIVE_ORDER.compare(s1.getName(), s2.getName())).collect(Collectors.toList());
        Paginator.paginate(args, new Paginator<>(toPaginate), () -> logDirect(!search.isEmpty() ? String.format("All %ssettings containing the string '%s':", viewModified ? "modified " : "", search) : String.format("All %ssettings:", viewModified ? "modified " : "")), setting -> {
            ITextComponent typeComponent = new TextComponentString(String.format(" (%s)", settingTypeToString(setting)));
            typeComponent.getStyle().setColor(TextFormatting.DARK_GRAY);
            ITextComponent hoverComponent = new TextComponentString("");
            hoverComponent.getStyle().setColor(TextFormatting.GRAY);
            hoverComponent.appendText(setting.getName());
            hoverComponent.appendText(String.format("\nType: %s", settingTypeToString(setting)));
            hoverComponent.appendText(String.format("\n\nValue:\n%s", settingValueToString(setting)));
            hoverComponent.appendText(String.format("\n\nDefault Value:\n%s", settingDefaultToString(setting)));
            String commandSuggestion = Baritone.settings().prefix.getValue() + String.format("set %s ", setting.getName());
            ITextComponent component = new TextComponentString(setting.getName());
            component.getStyle().setColor(TextFormatting.GRAY);
            component.appendSibling(typeComponent);
            component.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverComponent)).setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, commandSuggestion));
            return component;
        }, FORCE_COMMAND_PREFIX + "set " + arg + " " + search);
        return;
    }
    args.requireMax(1);
    boolean resetting = arg.equalsIgnoreCase("reset");
    boolean toggling = arg.equalsIgnoreCase("toggle");
    boolean doingSomething = resetting || toggling;
    if (resetting) {
        if (!args.hasAny()) {
            logDirect("Please specify 'all' as an argument to reset to confirm you'd really like to do this");
            logDirect("ALL settings will be reset. Use the 'set modified' or 'modified' commands to see what will be reset.");
            logDirect("Specify a setting name instead of 'all' to only reset one setting");
        } else if (args.peekString().equalsIgnoreCase("all")) {
            SettingsUtil.modifiedSettings(Baritone.settings()).forEach(Settings.Setting::reset);
            logDirect("All settings have been reset to their default values");
            SettingsUtil.save(Baritone.settings());
            return;
        }
    }
    if (toggling) {
        args.requireMin(1);
    }
    String settingName = doingSomething ? args.getString() : arg;
    Settings.Setting<?> setting = Baritone.settings().allSettings.stream().filter(s -> s.getName().equalsIgnoreCase(settingName)).findFirst().orElse(null);
    if (setting == null) {
        throw new CommandInvalidTypeException(args.consumed(), "a valid setting");
    }
    if (!doingSomething && !args.hasAny()) {
        logDirect(String.format("Value of setting %s:", setting.getName()));
        logDirect(settingValueToString(setting));
    } else {
        String oldValue = settingValueToString(setting);
        if (resetting) {
            setting.reset();
        } else if (toggling) {
            if (setting.getValueClass() != Boolean.class) {
                throw new CommandInvalidTypeException(args.consumed(), "a toggleable setting", "some other setting");
            }
            // noinspection unchecked
            setting.toggle();
            logDirect(String.format("Toggled setting %s to %s", setting.getName(), Boolean.toString((Boolean) setting.getValue())));
        } else {
            String newValue = args.getString();
            try {
                SettingsUtil.parseAndApply(Baritone.settings(), arg, newValue);
            } catch (Throwable t) {
                t.printStackTrace();
                throw new CommandInvalidTypeException(args.consumed(), "a valid value", t);
            }
        }
        if (!toggling) {
            logDirect(String.format("Successfully %s %s to %s", resetting ? "reset" : "set", setting.getName(), settingValueToString(setting)));
        }
        ITextComponent oldValueComponent = new TextComponentString(String.format("Old value: %s", oldValue));
        oldValueComponent.getStyle().setColor(TextFormatting.GRAY).setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("Click to set the setting back to this value"))).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, FORCE_COMMAND_PREFIX + String.format("set %s %s", setting.getName(), oldValue)));
        logDirect(oldValueComponent);
        if ((setting.getName().equals("chatControl") && !(Boolean) setting.getValue() && !Baritone.settings().chatControlAnyway.getValue()) || setting.getName().equals("chatControlAnyway") && !(Boolean) setting.getValue() && !Baritone.settings().chatControl.getValue()) {
            logDirect("Warning: Chat commands will no longer work. If you want to revert this change, use prefix control (if enabled) or click the old value listed above.", TextFormatting.RED);
        } else if (setting.getName().equals("prefixControl") && !(Boolean) setting.getValue()) {
            logDirect("Warning: Prefixed commands will no longer work. If you want to revert this change, use chat control (if enabled) or click the old value listed above.", TextFormatting.RED);
        }
    }
    SettingsUtil.save(Baritone.settings());
}
Also used : Arrays(java.util.Arrays) TabCompleteHelper(baritone.api.command.helpers.TabCompleteHelper) Command(baritone.api.command.Command) CommandException(baritone.api.command.exception.CommandException) TextFormatting(net.minecraft.util.text.TextFormatting) Paginator(baritone.api.command.helpers.Paginator) ClickEvent(net.minecraft.util.text.event.ClickEvent) IArgConsumer(baritone.api.command.argument.IArgConsumer) CommandInvalidTypeException(baritone.api.command.exception.CommandInvalidTypeException) Collectors(java.util.stream.Collectors) FORCE_COMMAND_PREFIX(baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX) ITextComponent(net.minecraft.util.text.ITextComponent) TextComponentString(net.minecraft.util.text.TextComponentString) IBaritone(baritone.api.IBaritone) List(java.util.List) Stream(java.util.stream.Stream) SettingsUtil(baritone.api.utils.SettingsUtil) HoverEvent(net.minecraft.util.text.event.HoverEvent) Locale(java.util.Locale) Baritone(baritone.Baritone) Settings(baritone.api.Settings) HoverEvent(net.minecraft.util.text.event.HoverEvent) CommandInvalidTypeException(baritone.api.command.exception.CommandInvalidTypeException) ClickEvent(net.minecraft.util.text.event.ClickEvent) ITextComponent(net.minecraft.util.text.ITextComponent) TextComponentString(net.minecraft.util.text.TextComponentString) TextComponentString(net.minecraft.util.text.TextComponentString) Settings(baritone.api.Settings)

Example 7 with CommandInvalidTypeException

use of baritone.api.command.exception.CommandInvalidTypeException in project baritone by cabaletta.

the class WaypointsCommand method execute.

@Override
public void execute(String label, IArgConsumer args) throws CommandException {
    Action action = args.hasAny() ? Action.getByName(args.getString()) : Action.LIST;
    if (action == null) {
        throw new CommandInvalidTypeException(args.consumed(), "an action");
    }
    BiFunction<IWaypoint, Action, ITextComponent> toComponent = (waypoint, _action) -> {
        ITextComponent component = new TextComponentString("");
        ITextComponent tagComponent = new TextComponentString(waypoint.getTag().name() + " ");
        tagComponent.getStyle().setColor(TextFormatting.GRAY);
        String name = waypoint.getName();
        ITextComponent nameComponent = new TextComponentString(!name.isEmpty() ? name : "<empty>");
        nameComponent.getStyle().setColor(!name.isEmpty() ? TextFormatting.GRAY : TextFormatting.DARK_GRAY);
        ITextComponent timestamp = new TextComponentString(" @ " + new Date(waypoint.getCreationTimestamp()));
        timestamp.getStyle().setColor(TextFormatting.DARK_GRAY);
        component.appendSibling(tagComponent);
        component.appendSibling(nameComponent);
        component.appendSibling(timestamp);
        component.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("Click to select"))).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("%s%s %s %s @ %d", FORCE_COMMAND_PREFIX, label, _action.names[0], waypoint.getTag().getName(), waypoint.getCreationTimestamp())));
        return component;
    };
    Function<IWaypoint, ITextComponent> transform = waypoint -> toComponent.apply(waypoint, action == Action.LIST ? Action.INFO : action);
    if (action == Action.LIST) {
        IWaypoint.Tag tag = args.hasAny() ? IWaypoint.Tag.getByName(args.peekString()) : null;
        if (tag != null) {
            args.get();
        }
        IWaypoint[] waypoints = tag != null ? ForWaypoints.getWaypointsByTag(this.baritone, tag) : ForWaypoints.getWaypoints(this.baritone);
        if (waypoints.length > 0) {
            args.requireMax(1);
            Paginator.paginate(args, waypoints, () -> logDirect(tag != null ? String.format("All waypoints by tag %s:", tag.name()) : "All waypoints:"), transform, String.format("%s%s %s%s", FORCE_COMMAND_PREFIX, label, action.names[0], tag != null ? " " + tag.getName() : ""));
        } else {
            args.requireMax(0);
            throw new CommandInvalidStateException(tag != null ? "No waypoints found by that tag" : "No waypoints found");
        }
    } else if (action == Action.SAVE) {
        IWaypoint.Tag tag = args.hasAny() ? IWaypoint.Tag.getByName(args.peekString()) : null;
        if (tag == null) {
            tag = IWaypoint.Tag.USER;
        } else {
            args.get();
        }
        String name = (args.hasExactlyOne() || args.hasExactly(4)) ? args.getString() : "";
        BetterBlockPos pos = args.hasAny() ? args.getDatatypePost(RelativeBlockPos.INSTANCE, ctx.playerFeet()) : ctx.playerFeet();
        args.requireMax(0);
        IWaypoint waypoint = new Waypoint(name, tag, pos);
        ForWaypoints.waypoints(this.baritone).addWaypoint(waypoint);
        ITextComponent component = new TextComponentString("Waypoint added: ");
        component.getStyle().setColor(TextFormatting.GRAY);
        component.appendSibling(toComponent.apply(waypoint, Action.INFO));
        logDirect(component);
    } else if (action == Action.CLEAR) {
        args.requireMax(1);
        IWaypoint.Tag tag = IWaypoint.Tag.getByName(args.getString());
        IWaypoint[] waypoints = ForWaypoints.getWaypointsByTag(this.baritone, tag);
        for (IWaypoint waypoint : waypoints) {
            ForWaypoints.waypoints(this.baritone).removeWaypoint(waypoint);
        }
        deletedWaypoints.computeIfAbsent(baritone.getWorldProvider().getCurrentWorld(), k -> new ArrayList<>()).addAll(Arrays.<IWaypoint>asList(waypoints));
        ITextComponent textComponent = new TextComponentString(String.format("Cleared %d waypoints, click to restore them", waypoints.length));
        textComponent.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("%s%s restore @ %s", FORCE_COMMAND_PREFIX, label, Stream.of(waypoints).map(wp -> Long.toString(wp.getCreationTimestamp())).collect(Collectors.joining(" ")))));
        logDirect(textComponent);
    } else if (action == Action.RESTORE) {
        List<IWaypoint> waypoints = new ArrayList<>();
        List<IWaypoint> deletedWaypoints = this.deletedWaypoints.getOrDefault(baritone.getWorldProvider().getCurrentWorld(), Collections.emptyList());
        if (args.peekString().equals("@")) {
            args.get();
            // no args.requireMin(1) because if the user clears an empty tag there is nothing to restore
            while (args.hasAny()) {
                long timestamp = args.getAs(Long.class);
                for (IWaypoint waypoint : deletedWaypoints) {
                    if (waypoint.getCreationTimestamp() == timestamp) {
                        waypoints.add(waypoint);
                        break;
                    }
                }
            }
        } else {
            args.requireExactly(1);
            int size = deletedWaypoints.size();
            int amount = Math.min(size, args.getAs(Integer.class));
            waypoints = new ArrayList<>(deletedWaypoints.subList(size - amount, size));
        }
        waypoints.forEach(ForWaypoints.waypoints(this.baritone)::addWaypoint);
        deletedWaypoints.removeIf(waypoints::contains);
        logDirect(String.format("Restored %d waypoints", waypoints.size()));
    } else {
        IWaypoint[] waypoints = args.getDatatypeFor(ForWaypoints.INSTANCE);
        IWaypoint waypoint = null;
        if (args.hasAny() && args.peekString().equals("@")) {
            args.requireExactly(2);
            args.get();
            long timestamp = args.getAs(Long.class);
            for (IWaypoint iWaypoint : waypoints) {
                if (iWaypoint.getCreationTimestamp() == timestamp) {
                    waypoint = iWaypoint;
                    break;
                }
            }
            if (waypoint == null) {
                throw new CommandInvalidStateException("Timestamp was specified but no waypoint was found");
            }
        } else {
            switch(waypoints.length) {
                case 0:
                    throw new CommandInvalidStateException("No waypoints found");
                case 1:
                    waypoint = waypoints[0];
                    break;
                default:
                    break;
            }
        }
        if (waypoint == null) {
            args.requireMax(1);
            Paginator.paginate(args, waypoints, () -> logDirect("Multiple waypoints were found:"), transform, String.format("%s%s %s %s", FORCE_COMMAND_PREFIX, label, action.names[0], args.consumedString()));
        } else {
            if (action == Action.INFO) {
                logDirect(transform.apply(waypoint));
                logDirect(String.format("Position: %s", waypoint.getLocation()));
                ITextComponent deleteComponent = new TextComponentString("Click to delete this waypoint");
                deleteComponent.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("%s%s delete %s @ %d", FORCE_COMMAND_PREFIX, label, waypoint.getTag().getName(), waypoint.getCreationTimestamp())));
                ITextComponent goalComponent = new TextComponentString("Click to set goal to this waypoint");
                goalComponent.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("%s%s goal %s @ %d", FORCE_COMMAND_PREFIX, label, waypoint.getTag().getName(), waypoint.getCreationTimestamp())));
                ITextComponent recreateComponent = new TextComponentString("Click to show a command to recreate this waypoint");
                recreateComponent.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, String.format("%s%s save %s %s %s %s %s", // This uses the normal prefix because it is run by the user.
                Baritone.settings().prefix.value, label, waypoint.getTag().getName(), waypoint.getName(), waypoint.getLocation().x, waypoint.getLocation().y, waypoint.getLocation().z)));
                ITextComponent backComponent = new TextComponentString("Click to return to the waypoints list");
                backComponent.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("%s%s list", FORCE_COMMAND_PREFIX, label)));
                logDirect(deleteComponent);
                logDirect(goalComponent);
                logDirect(recreateComponent);
                logDirect(backComponent);
            } else if (action == Action.DELETE) {
                ForWaypoints.waypoints(this.baritone).removeWaypoint(waypoint);
                deletedWaypoints.computeIfAbsent(baritone.getWorldProvider().getCurrentWorld(), k -> new ArrayList<>()).add(waypoint);
                ITextComponent textComponent = new TextComponentString("That waypoint has successfully been deleted, click to restore it");
                textComponent.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("%s%s restore @ %s", FORCE_COMMAND_PREFIX, label, waypoint.getCreationTimestamp())));
                logDirect(textComponent);
            } else if (action == Action.GOAL) {
                Goal goal = new GoalBlock(waypoint.getLocation());
                baritone.getCustomGoalProcess().setGoal(goal);
                logDirect(String.format("Goal: %s", goal));
            } else if (action == Action.GOTO) {
                Goal goal = new GoalBlock(waypoint.getLocation());
                baritone.getCustomGoalProcess().setGoalAndPath(goal);
                logDirect(String.format("Going to: %s", goal));
            }
        }
    }
}
Also used : java.util(java.util) TabCompleteHelper(baritone.api.command.helpers.TabCompleteHelper) IWorldData(baritone.api.cache.IWorldData) Command(baritone.api.command.Command) BiFunction(java.util.function.BiFunction) ClickEvent(net.minecraft.util.text.event.ClickEvent) Waypoint(baritone.api.cache.Waypoint) IArgConsumer(baritone.api.command.argument.IArgConsumer) Function(java.util.function.Function) ITextComponent(net.minecraft.util.text.ITextComponent) IBaritone(baritone.api.IBaritone) IWaypoint(baritone.api.cache.IWaypoint) CommandInvalidStateException(baritone.api.command.exception.CommandInvalidStateException) ForWaypoints(baritone.api.command.datatypes.ForWaypoints) CommandException(baritone.api.command.exception.CommandException) TextFormatting(net.minecraft.util.text.TextFormatting) Paginator(baritone.api.command.helpers.Paginator) GoalBlock(baritone.api.pathing.goals.GoalBlock) CommandInvalidTypeException(baritone.api.command.exception.CommandInvalidTypeException) Collectors(java.util.stream.Collectors) FORCE_COMMAND_PREFIX(baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX) Goal(baritone.api.pathing.goals.Goal) BetterBlockPos(baritone.api.utils.BetterBlockPos) TextComponentString(net.minecraft.util.text.TextComponentString) Stream(java.util.stream.Stream) HoverEvent(net.minecraft.util.text.event.HoverEvent) Baritone(baritone.Baritone) RelativeBlockPos(baritone.api.command.datatypes.RelativeBlockPos) HoverEvent(net.minecraft.util.text.event.HoverEvent) GoalBlock(baritone.api.pathing.goals.GoalBlock) CommandInvalidTypeException(baritone.api.command.exception.CommandInvalidTypeException) ClickEvent(net.minecraft.util.text.event.ClickEvent) ITextComponent(net.minecraft.util.text.ITextComponent) TextComponentString(net.minecraft.util.text.TextComponentString) TextComponentString(net.minecraft.util.text.TextComponentString) Goal(baritone.api.pathing.goals.Goal) IWaypoint(baritone.api.cache.IWaypoint) BetterBlockPos(baritone.api.utils.BetterBlockPos) Waypoint(baritone.api.cache.Waypoint) IWaypoint(baritone.api.cache.IWaypoint) CommandInvalidStateException(baritone.api.command.exception.CommandInvalidStateException)

Example 8 with CommandInvalidTypeException

use of baritone.api.command.exception.CommandInvalidTypeException in project baritone by cabaletta.

the class SetCommand method execute.

@Override
public void execute(String label, IArgConsumer args) throws CommandException {
    String arg = args.hasAny() ? args.getString().toLowerCase(Locale.US) : "list";
    if (Arrays.asList("s", "save").contains(arg)) {
        SettingsUtil.save(Baritone.settings());
        logDirect("Settings saved");
        return;
    }
    boolean viewModified = Arrays.asList("m", "mod", "modified").contains(arg);
    boolean viewAll = Arrays.asList("all", "l", "list").contains(arg);
    boolean paginate = viewModified || viewAll;
    if (paginate) {
        String search = args.hasAny() && args.peekAsOrNull(Integer.class) == null ? args.getString() : "";
        args.requireMax(1);
        List<? extends Settings.Setting> toPaginate = (viewModified ? SettingsUtil.modifiedSettings(Baritone.settings()) : Baritone.settings().allSettings).stream().filter(s -> !javaOnlySetting(s)).filter(s -> s.getName().toLowerCase(Locale.US).contains(search.toLowerCase(Locale.US))).sorted((s1, s2) -> String.CASE_INSENSITIVE_ORDER.compare(s1.getName(), s2.getName())).collect(Collectors.toList());
        Paginator.paginate(args, new Paginator<>(toPaginate), () -> logDirect(!search.isEmpty() ? String.format("All %ssettings containing the string '%s':", viewModified ? "modified " : "", search) : String.format("All %ssettings:", viewModified ? "modified " : "")), setting -> {
            ITextComponent typeComponent = new TextComponentString(String.format(" (%s)", settingTypeToString(setting)));
            typeComponent.getStyle().setColor(TextFormatting.DARK_GRAY);
            ITextComponent hoverComponent = new TextComponentString("");
            hoverComponent.getStyle().setColor(TextFormatting.GRAY);
            hoverComponent.appendText(setting.getName());
            hoverComponent.appendText(String.format("\nType: %s", settingTypeToString(setting)));
            hoverComponent.appendText(String.format("\n\nValue:\n%s", settingValueToString(setting)));
            hoverComponent.appendText(String.format("\n\nDefault Value:\n%s", settingDefaultToString(setting)));
            String commandSuggestion = Baritone.settings().prefix.value + String.format("set %s ", setting.getName());
            ITextComponent component = new TextComponentString(setting.getName());
            component.getStyle().setColor(TextFormatting.GRAY);
            component.appendSibling(typeComponent);
            component.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverComponent)).setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, commandSuggestion));
            return component;
        }, FORCE_COMMAND_PREFIX + "set " + arg + " " + search);
        return;
    }
    args.requireMax(1);
    boolean resetting = arg.equalsIgnoreCase("reset");
    boolean toggling = arg.equalsIgnoreCase("toggle");
    boolean doingSomething = resetting || toggling;
    if (resetting) {
        if (!args.hasAny()) {
            logDirect("Please specify 'all' as an argument to reset to confirm you'd really like to do this");
            logDirect("ALL settings will be reset. Use the 'set modified' or 'modified' commands to see what will be reset.");
            logDirect("Specify a setting name instead of 'all' to only reset one setting");
        } else if (args.peekString().equalsIgnoreCase("all")) {
            SettingsUtil.modifiedSettings(Baritone.settings()).forEach(Settings.Setting::reset);
            logDirect("All settings have been reset to their default values");
            SettingsUtil.save(Baritone.settings());
            return;
        }
    }
    if (toggling) {
        args.requireMin(1);
    }
    String settingName = doingSomething ? args.getString() : arg;
    Settings.Setting<?> setting = Baritone.settings().allSettings.stream().filter(s -> s.getName().equalsIgnoreCase(settingName)).findFirst().orElse(null);
    if (setting == null) {
        throw new CommandInvalidTypeException(args.consumed(), "a valid setting");
    }
    if (javaOnlySetting(setting)) {
        // so at some point we have to tell them or they will see it as a bug
        throw new CommandInvalidStateException(String.format("Setting %s can only be used via the api.", setting.getName()));
    }
    if (!doingSomething && !args.hasAny()) {
        logDirect(String.format("Value of setting %s:", setting.getName()));
        logDirect(settingValueToString(setting));
    } else {
        String oldValue = settingValueToString(setting);
        if (resetting) {
            setting.reset();
        } else if (toggling) {
            if (setting.getValueClass() != Boolean.class) {
                throw new CommandInvalidTypeException(args.consumed(), "a toggleable setting", "some other setting");
            }
            // noinspection unchecked
            ((Settings.Setting<Boolean>) setting).value ^= true;
            logDirect(String.format("Toggled setting %s to %s", setting.getName(), Boolean.toString((Boolean) setting.value)));
        } else {
            String newValue = args.getString();
            try {
                SettingsUtil.parseAndApply(Baritone.settings(), arg, newValue);
            } catch (Throwable t) {
                t.printStackTrace();
                throw new CommandInvalidTypeException(args.consumed(), "a valid value", t);
            }
        }
        if (!toggling) {
            logDirect(String.format("Successfully %s %s to %s", resetting ? "reset" : "set", setting.getName(), settingValueToString(setting)));
        }
        ITextComponent oldValueComponent = new TextComponentString(String.format("Old value: %s", oldValue));
        oldValueComponent.getStyle().setColor(TextFormatting.GRAY).setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("Click to set the setting back to this value"))).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, FORCE_COMMAND_PREFIX + String.format("set %s %s", setting.getName(), oldValue)));
        logDirect(oldValueComponent);
        if ((setting.getName().equals("chatControl") && !(Boolean) setting.value && !Baritone.settings().chatControlAnyway.value) || setting.getName().equals("chatControlAnyway") && !(Boolean) setting.value && !Baritone.settings().chatControl.value) {
            logDirect("Warning: Chat commands will no longer work. If you want to revert this change, use prefix control (if enabled) or click the old value listed above.", TextFormatting.RED);
        } else if (setting.getName().equals("prefixControl") && !(Boolean) setting.value) {
            logDirect("Warning: Prefixed commands will no longer work. If you want to revert this change, use chat control (if enabled) or click the old value listed above.", TextFormatting.RED);
        }
    }
    SettingsUtil.save(Baritone.settings());
}
Also used : Arrays(java.util.Arrays) TabCompleteHelper(baritone.api.command.helpers.TabCompleteHelper) Command(baritone.api.command.Command) CommandException(baritone.api.command.exception.CommandException) TextFormatting(net.minecraft.util.text.TextFormatting) Paginator(baritone.api.command.helpers.Paginator) ClickEvent(net.minecraft.util.text.event.ClickEvent) IArgConsumer(baritone.api.command.argument.IArgConsumer) CommandInvalidTypeException(baritone.api.command.exception.CommandInvalidTypeException) Collectors(java.util.stream.Collectors) FORCE_COMMAND_PREFIX(baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX) ITextComponent(net.minecraft.util.text.ITextComponent) TextComponentString(net.minecraft.util.text.TextComponentString) IBaritone(baritone.api.IBaritone) List(java.util.List) Stream(java.util.stream.Stream) SettingsUtil(baritone.api.utils.SettingsUtil) HoverEvent(net.minecraft.util.text.event.HoverEvent) Locale(java.util.Locale) Baritone(baritone.Baritone) Settings(baritone.api.Settings) CommandInvalidStateException(baritone.api.command.exception.CommandInvalidStateException) HoverEvent(net.minecraft.util.text.event.HoverEvent) CommandInvalidTypeException(baritone.api.command.exception.CommandInvalidTypeException) ClickEvent(net.minecraft.util.text.event.ClickEvent) ITextComponent(net.minecraft.util.text.ITextComponent) TextComponentString(net.minecraft.util.text.TextComponentString) TextComponentString(net.minecraft.util.text.TextComponentString) CommandInvalidStateException(baritone.api.command.exception.CommandInvalidStateException) Settings(baritone.api.Settings)

Aggregations

CommandInvalidTypeException (baritone.api.command.exception.CommandInvalidTypeException)8 CommandInvalidStateException (baritone.api.command.exception.CommandInvalidStateException)7 CommandException (baritone.api.command.exception.CommandException)6 IBaritone (baritone.api.IBaritone)4 Command (baritone.api.command.Command)4 FORCE_COMMAND_PREFIX (baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX)4 IArgConsumer (baritone.api.command.argument.IArgConsumer)4 RelativeBlockPos (baritone.api.command.datatypes.RelativeBlockPos)4 Paginator (baritone.api.command.helpers.Paginator)4 TabCompleteHelper (baritone.api.command.helpers.TabCompleteHelper)4 BetterBlockPos (baritone.api.utils.BetterBlockPos)4 List (java.util.List)4 Stream (java.util.stream.Stream)4 ITextComponent (net.minecraft.util.text.ITextComponent)4 TextComponentString (net.minecraft.util.text.TextComponentString)4 TextFormatting (net.minecraft.util.text.TextFormatting)4 ClickEvent (net.minecraft.util.text.event.ClickEvent)4 HoverEvent (net.minecraft.util.text.event.HoverEvent)4 Baritone (baritone.Baritone)3 Collectors (java.util.stream.Collectors)3