Search in sources :

Example 1 with CommandNotFoundException

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

the class ExampleBaritoneControl method onSendChatMessage.

@Override
public void onSendChatMessage(ChatEvent event) {
    String msg = event.getMessage();
    String prefix = settings.prefix.value;
    boolean forceRun = msg.startsWith(FORCE_COMMAND_PREFIX);
    if ((settings.prefixControl.value && msg.startsWith(prefix)) || forceRun) {
        event.cancel();
        String commandStr = msg.substring(forceRun ? FORCE_COMMAND_PREFIX.length() : prefix.length());
        if (!runCommand(commandStr) && !commandStr.trim().isEmpty()) {
            new CommandNotFoundException(CommandManager.expand(commandStr).getFirst()).handle(null, null);
        }
    } else if ((settings.chatControl.value || settings.chatControlAnyway.value) && runCommand(msg)) {
        event.cancel();
    }
}
Also used : TextComponentString(net.minecraft.util.text.TextComponentString) CommandNotFoundException(baritone.api.command.exception.CommandNotFoundException)

Example 2 with CommandNotFoundException

use of baritone.api.command.exception.CommandNotFoundException 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 3 with CommandNotFoundException

use of baritone.api.command.exception.CommandNotFoundException 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)

Example 4 with CommandNotFoundException

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

the class ExampleBaritoneControl method onSendChatMessage.

@Override
public void onSendChatMessage(ChatEvent event) {
    String msg = event.getMessage();
    String prefix = settings.prefix.getValue();
    boolean forceRun = msg.startsWith(FORCE_COMMAND_PREFIX);
    if ((settings.prefixControl.getValue() && msg.startsWith(prefix)) || forceRun) {
        event.cancel();
        String commandStr = msg.substring(forceRun ? FORCE_COMMAND_PREFIX.length() : prefix.length());
        if (!runCommand(commandStr) && !commandStr.trim().isEmpty()) {
            new CommandNotFoundException(CommandManager.expand(commandStr).getFirst()).handle(null, null);
        }
    } else if ((settings.chatControl.getValue() || settings.chatControlAnyway.getValue()) && runCommand(msg)) {
        event.cancel();
    }
}
Also used : TextComponentString(net.minecraft.util.text.TextComponentString) CommandNotFoundException(baritone.api.command.exception.CommandNotFoundException)

Aggregations

CommandNotFoundException (baritone.api.command.exception.CommandNotFoundException)4 TextComponentString (net.minecraft.util.text.TextComponentString)4 IBaritone (baritone.api.IBaritone)2 Command (baritone.api.command.Command)2 FORCE_COMMAND_PREFIX (baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX)2 ICommand (baritone.api.command.ICommand)2 IArgConsumer (baritone.api.command.argument.IArgConsumer)2 CommandException (baritone.api.command.exception.CommandException)2 Paginator (baritone.api.command.helpers.Paginator)2 TabCompleteHelper (baritone.api.command.helpers.TabCompleteHelper)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 ITextComponent (net.minecraft.util.text.ITextComponent)2 TextFormatting (net.minecraft.util.text.TextFormatting)2 ClickEvent (net.minecraft.util.text.event.ClickEvent)2 HoverEvent (net.minecraft.util.text.event.HoverEvent)2