Search in sources :

Example 1 with TabCompleteEvent

use of baritone.api.event.events.TabCompleteEvent in project Spark-Client by Spark-Client-Development.

the class MixinTabCompleter method onRequestCompletions.

@Inject(method = "requestCompletions", at = @At("HEAD"), cancellable = true)
private void onRequestCompletions(String prefix, CallbackInfo ci) {
    if (!((Object) this instanceof GuiChat.ChatTabCompleter)) {
        return;
    }
    IBaritone baritone = BaritoneAPI.getProvider().getPrimaryBaritone();
    TabCompleteEvent event = new TabCompleteEvent(prefix);
    baritone.getGameEventHandler().onPreTabComplete(event);
    if (event.isCancelled()) {
        ci.cancel();
        return;
    }
    if (event.completions != null) {
        ci.cancel();
        this.dontComplete = true;
        try {
            this.requestedCompletions = true;
            setCompletions(event.completions);
        } finally {
            this.dontComplete = false;
        }
    }
}
Also used : TabCompleteEvent(baritone.api.event.events.TabCompleteEvent) IBaritone(baritone.api.IBaritone) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 2 with TabCompleteEvent

use of baritone.api.event.events.TabCompleteEvent 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 3 with TabCompleteEvent

use of baritone.api.event.events.TabCompleteEvent 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 4 with TabCompleteEvent

use of baritone.api.event.events.TabCompleteEvent in project baritone by cabaletta.

the class MixinTabCompleter method onRequestCompletions.

@Inject(method = "requestCompletions", at = @At("HEAD"), cancellable = true)
private void onRequestCompletions(String prefix, CallbackInfo ci) {
    if (!((Object) this instanceof GuiChat.ChatTabCompleter)) {
        return;
    }
    IBaritone baritone = BaritoneAPI.getProvider().getPrimaryBaritone();
    TabCompleteEvent event = new TabCompleteEvent(prefix);
    baritone.getGameEventHandler().onPreTabComplete(event);
    if (event.isCancelled()) {
        ci.cancel();
        return;
    }
    if (event.completions != null) {
        ci.cancel();
        this.dontComplete = true;
        try {
            this.requestedCompletions = true;
            setCompletions(event.completions);
        } finally {
            this.dontComplete = false;
        }
    }
}
Also used : TabCompleteEvent(baritone.api.event.events.TabCompleteEvent) IBaritone(baritone.api.IBaritone) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

IBaritone (baritone.api.IBaritone)4 TabCompleteEvent (baritone.api.event.events.TabCompleteEvent)4 BaritoneAPI (baritone.api.BaritoneAPI)2 Settings (baritone.api.Settings)2 FORCE_COMMAND_PREFIX (baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX)2 ICommandArgument (baritone.api.command.argument.ICommandArgument)2 CommandNotEnoughArgumentsException (baritone.api.command.exception.CommandNotEnoughArgumentsException)2 CommandNotFoundException (baritone.api.command.exception.CommandNotFoundException)2 TabCompleteHelper (baritone.api.command.helpers.TabCompleteHelper)2 ICommandManager (baritone.api.command.manager.ICommandManager)2 ChatEvent (baritone.api.event.events.ChatEvent)2 AbstractGameEventListener (baritone.api.event.listener.AbstractGameEventListener)2 Helper (baritone.api.utils.Helper)2 SettingsUtil (baritone.api.utils.SettingsUtil)2 ArgConsumer (baritone.command.argument.ArgConsumer)2 CommandArguments (baritone.command.argument.CommandArguments)2 CommandManager (baritone.command.manager.CommandManager)2 IGuiScreen (baritone.utils.accessor.IGuiScreen)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2