use of baritone.api.command.argument.ICommandArgument in project Spark-Client by Spark-Client-Development.
the class CommandManager method tabComplete.
@Override
public Stream<String> tabComplete(String prefix) {
Tuple<String, List<ICommandArgument>> pair = expand(prefix, true);
String label = pair.getFirst();
List<ICommandArgument> args = pair.getSecond();
if (args.isEmpty()) {
return new TabCompleteHelper().addCommands(this.baritone.getCommandManager()).filterPrefix(label).stream();
} else {
return tabComplete(pair);
}
}
use of baritone.api.command.argument.ICommandArgument 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);
}
use of baritone.api.command.argument.ICommandArgument 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);
}
use of baritone.api.command.argument.ICommandArgument 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();
}
}
use of baritone.api.command.argument.ICommandArgument in project baritone by cabaletta.
the class CommandArguments method from.
/**
* Turn a string into a list of {@link ICommandArgument}s. This is needed because of {@link ICommandArgument#getRawRest()}
*
* @param string The string to convert
* @param preserveEmptyLast If the string ends with whitespace, add an empty {@link ICommandArgument} to the end This
* is useful for tab completion
* @return A list of {@link ICommandArgument}s
*/
public static List<ICommandArgument> from(String string, boolean preserveEmptyLast) {
List<ICommandArgument> args = new ArrayList<>();
Matcher argMatcher = ARG_PATTERN.matcher(string);
int lastEnd = -1;
while (argMatcher.find()) {
args.add(new CommandArgument(args.size(), argMatcher.group(), string.substring(argMatcher.start())));
lastEnd = argMatcher.end();
}
if (preserveEmptyLast && lastEnd < string.length()) {
args.add(new CommandArgument(args.size(), "", ""));
}
return args;
}
Aggregations