Search in sources :

Example 1 with CommandException

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

the class ExploreFilterCommand method execute.

@Override
public void execute(String label, IArgConsumer args) throws CommandException {
    args.requireMax(2);
    File file = args.getDatatypePost(RelativeFile.INSTANCE, mc.gameDir.getAbsoluteFile().getParentFile());
    boolean invert = false;
    if (args.hasAny()) {
        if (args.getString().equalsIgnoreCase("invert")) {
            invert = true;
        } else {
            throw new CommandInvalidTypeException(args.consumed(), "either \"invert\" or nothing");
        }
    }
    try {
        baritone.getExploreProcess().applyJsonFilter(file.toPath().toAbsolutePath(), invert);
    } catch (NoSuchFileException e) {
        throw new CommandInvalidStateException("File not found");
    } catch (JsonSyntaxException e) {
        throw new CommandInvalidStateException("Invalid JSON syntax");
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
    logDirect(String.format("Explore filter applied. Inverted: %s", Boolean.toString(invert)));
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) CommandInvalidTypeException(baritone.api.command.exception.CommandInvalidTypeException) NoSuchFileException(java.nio.file.NoSuchFileException) CommandInvalidStateException(baritone.api.command.exception.CommandInvalidStateException) File(java.io.File) RelativeFile(baritone.api.command.datatypes.RelativeFile) NoSuchFileException(java.nio.file.NoSuchFileException) JsonSyntaxException(com.google.gson.JsonSyntaxException) CommandException(baritone.api.command.exception.CommandException) CommandInvalidTypeException(baritone.api.command.exception.CommandInvalidTypeException) CommandInvalidStateException(baritone.api.command.exception.CommandInvalidStateException)

Example 2 with CommandException

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

the class FindCommand method execute.

@Override
public void execute(String label, IArgConsumer args) throws CommandException {
    List<Block> toFind = new ArrayList<>();
    while (args.hasAny()) {
        toFind.add(args.getDatatypeFor(BlockById.INSTANCE));
    }
    BetterBlockPos origin = ctx.playerFeet();
    toFind.stream().flatMap(block -> ctx.worldData().getCachedWorld().getLocationsOf(Block.REGISTRY.getNameForObject(block).getPath(), Integer.MAX_VALUE, origin.x, origin.y, 4).stream()).map(BetterBlockPos::new).map(BetterBlockPos::toString).forEach(this::logDirect);
}
Also used : BetterBlockPos(baritone.api.utils.BetterBlockPos) IBaritone(baritone.api.IBaritone) Arrays(java.util.Arrays) List(java.util.List) BlockById(baritone.api.command.datatypes.BlockById) Stream(java.util.stream.Stream) Block(net.minecraft.block.Block) Command(baritone.api.command.Command) CommandException(baritone.api.command.exception.CommandException) IArgConsumer(baritone.api.command.argument.IArgConsumer) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) BetterBlockPos(baritone.api.utils.BetterBlockPos) Block(net.minecraft.block.Block)

Example 3 with CommandException

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

the class HelpCommand method execute.

@Override
public void execute(String label, IArgConsumer args) throws CommandException {
    args.requireMax(1);
    if (!args.hasAny() || args.is(Integer.class)) {
        Paginator.paginate(args, new Paginator<>(this.baritone.getCommandManager().getRegistry().descendingStream().filter(command -> !command.hiddenFromHelp()).collect(Collectors.toList())), () -> logDirect("All Baritone commands (clickable):"), command -> {
            String names = String.join("/", command.getNames());
            String name = command.getNames().get(0);
            ITextComponent shortDescComponent = new TextComponentString(" - " + command.getShortDesc());
            shortDescComponent.getStyle().setColor(TextFormatting.DARK_GRAY);
            ITextComponent namesComponent = new TextComponentString(names);
            namesComponent.getStyle().setColor(TextFormatting.WHITE);
            ITextComponent hoverComponent = new TextComponentString("");
            hoverComponent.getStyle().setColor(TextFormatting.GRAY);
            hoverComponent.appendSibling(namesComponent);
            hoverComponent.appendText("\n" + command.getShortDesc());
            hoverComponent.appendText("\n\nClick to view full help");
            String clickCommand = FORCE_COMMAND_PREFIX + String.format("%s %s", label, command.getNames().get(0));
            ITextComponent component = new TextComponentString(name);
            component.getStyle().setColor(TextFormatting.GRAY);
            component.appendSibling(shortDescComponent);
            component.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverComponent)).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, clickCommand));
            return component;
        }, FORCE_COMMAND_PREFIX + label);
    } else {
        String commandName = args.getString().toLowerCase();
        ICommand command = this.baritone.getCommandManager().getCommand(commandName);
        if (command == null) {
            throw new CommandNotFoundException(commandName);
        }
        logDirect(String.format("%s - %s", String.join(" / ", command.getNames()), command.getShortDesc()));
        logDirect("");
        command.getLongDesc().forEach(this::logDirect);
        logDirect("");
        ITextComponent returnComponent = new TextComponentString("Click to return to the help menu");
        returnComponent.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, FORCE_COMMAND_PREFIX + label));
        logDirect(returnComponent);
    }
}
Also used : Arrays(java.util.Arrays) CommandNotFoundException(baritone.api.command.exception.CommandNotFoundException) 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) 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) HoverEvent(net.minecraft.util.text.event.HoverEvent) ICommand(baritone.api.command.ICommand) HoverEvent(net.minecraft.util.text.event.HoverEvent) ICommand(baritone.api.command.ICommand) ClickEvent(net.minecraft.util.text.event.ClickEvent) ITextComponent(net.minecraft.util.text.ITextComponent) TextComponentString(net.minecraft.util.text.TextComponentString) CommandNotFoundException(baritone.api.command.exception.CommandNotFoundException) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 4 with CommandException

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

the class ExploreFilterCommand method execute.

@Override
public void execute(String label, IArgConsumer args) throws CommandException {
    args.requireMax(2);
    File file = args.getDatatypePost(RelativeFile.INSTANCE, mc.gameDir.getAbsoluteFile().getParentFile());
    boolean invert = false;
    if (args.hasAny()) {
        if (args.getString().equalsIgnoreCase("invert")) {
            invert = true;
        } else {
            throw new CommandInvalidTypeException(args.consumed(), "either \"invert\" or nothing");
        }
    }
    try {
        baritone.getExploreProcess().applyJsonFilter(file.toPath().toAbsolutePath(), invert);
    } catch (NoSuchFileException e) {
        throw new CommandInvalidStateException("File not found");
    } catch (JsonSyntaxException e) {
        throw new CommandInvalidStateException("Invalid JSON syntax");
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
    logDirect(String.format("Explore filter applied. Inverted: %s", Boolean.toString(invert)));
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) CommandInvalidTypeException(baritone.api.command.exception.CommandInvalidTypeException) NoSuchFileException(java.nio.file.NoSuchFileException) CommandInvalidStateException(baritone.api.command.exception.CommandInvalidStateException) File(java.io.File) RelativeFile(baritone.api.command.datatypes.RelativeFile) NoSuchFileException(java.nio.file.NoSuchFileException) JsonSyntaxException(com.google.gson.JsonSyntaxException) CommandException(baritone.api.command.exception.CommandException) CommandInvalidTypeException(baritone.api.command.exception.CommandInvalidTypeException) CommandInvalidStateException(baritone.api.command.exception.CommandInvalidStateException)

Example 5 with CommandException

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

the class HelpCommand method execute.

@Override
public void execute(String label, IArgConsumer args) throws CommandException {
    args.requireMax(1);
    if (!args.hasAny() || args.is(Integer.class)) {
        Paginator.paginate(args, new Paginator<>(this.baritone.getCommandManager().getRegistry().descendingStream().filter(command -> !command.hiddenFromHelp()).collect(Collectors.toList())), () -> logDirect("All Baritone commands (clickable):"), command -> {
            String names = String.join("/", command.getNames());
            String name = command.getNames().get(0);
            ITextComponent shortDescComponent = new TextComponentString(" - " + command.getShortDesc());
            shortDescComponent.getStyle().setColor(TextFormatting.DARK_GRAY);
            ITextComponent namesComponent = new TextComponentString(names);
            namesComponent.getStyle().setColor(TextFormatting.WHITE);
            ITextComponent hoverComponent = new TextComponentString("");
            hoverComponent.getStyle().setColor(TextFormatting.GRAY);
            hoverComponent.appendSibling(namesComponent);
            hoverComponent.appendText("\n" + command.getShortDesc());
            hoverComponent.appendText("\n\nClick to view full help");
            String clickCommand = FORCE_COMMAND_PREFIX + String.format("%s %s", label, command.getNames().get(0));
            ITextComponent component = new TextComponentString(name);
            component.getStyle().setColor(TextFormatting.GRAY);
            component.appendSibling(shortDescComponent);
            component.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverComponent)).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, clickCommand));
            return component;
        }, FORCE_COMMAND_PREFIX + label);
    } else {
        String commandName = args.getString().toLowerCase();
        ICommand command = this.baritone.getCommandManager().getCommand(commandName);
        if (command == null) {
            throw new CommandNotFoundException(commandName);
        }
        logDirect(String.format("%s - %s", String.join(" / ", command.getNames()), command.getShortDesc()));
        logDirect("");
        command.getLongDesc().forEach(this::logDirect);
        logDirect("");
        ITextComponent returnComponent = new TextComponentString("Click to return to the help menu");
        returnComponent.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, FORCE_COMMAND_PREFIX + label));
        logDirect(returnComponent);
    }
}
Also used : Arrays(java.util.Arrays) CommandNotFoundException(baritone.api.command.exception.CommandNotFoundException) 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) 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) HoverEvent(net.minecraft.util.text.event.HoverEvent) ICommand(baritone.api.command.ICommand) HoverEvent(net.minecraft.util.text.event.HoverEvent) ICommand(baritone.api.command.ICommand) ClickEvent(net.minecraft.util.text.event.ClickEvent) ITextComponent(net.minecraft.util.text.ITextComponent) TextComponentString(net.minecraft.util.text.TextComponentString) CommandNotFoundException(baritone.api.command.exception.CommandNotFoundException) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

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