2019-08-30 18:55:25 +00:00
|
|
|
/*
|
|
|
|
* This file is part of Baritone.
|
|
|
|
*
|
|
|
|
* Baritone is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Baritone is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2019-09-04 18:17:36 +00:00
|
|
|
package baritone.utils.command.defaults;
|
2019-08-30 18:55:25 +00:00
|
|
|
|
|
|
|
import baritone.api.Settings;
|
|
|
|
import baritone.api.utils.command.Command;
|
|
|
|
import baritone.api.utils.command.exception.CommandNotFoundException;
|
|
|
|
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
|
|
|
import baritone.api.utils.command.helpers.pagination.Paginator;
|
|
|
|
import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper;
|
|
|
|
import baritone.api.utils.command.manager.CommandManager;
|
2019-09-06 10:59:10 +00:00
|
|
|
import net.minecraft.util.text.ITextComponent;
|
2019-08-30 18:55:25 +00:00
|
|
|
import net.minecraft.util.text.TextComponentString;
|
|
|
|
import net.minecraft.util.text.TextFormatting;
|
|
|
|
import net.minecraft.util.text.event.ClickEvent;
|
|
|
|
import net.minecraft.util.text.event.HoverEvent;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
|
|
import static baritone.api.utils.command.BaritoneChatControl.FORCE_COMMAND_PREFIX;
|
|
|
|
import static baritone.api.utils.command.manager.CommandManager.getCommand;
|
|
|
|
import static java.util.Arrays.asList;
|
|
|
|
import static java.util.Objects.isNull;
|
|
|
|
|
|
|
|
public class HelpCommand extends Command {
|
|
|
|
public HelpCommand() {
|
2019-09-06 10:59:10 +00:00
|
|
|
super(asList("help", "?"));
|
2019-08-30 18:55:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void executed(String label, ArgConsumer args, Settings settings) {
|
|
|
|
args.requireMax(1);
|
|
|
|
|
|
|
|
if (!args.has() || args.is(Integer.class)) {
|
|
|
|
Paginator.paginate(
|
2019-09-19 19:53:15 +00:00
|
|
|
args, new Paginator<>(
|
|
|
|
CommandManager.REGISTRY.descendingStream()
|
|
|
|
.filter(command -> !command.hiddenFromHelp())
|
|
|
|
.collect(Collectors.toList())
|
|
|
|
),
|
|
|
|
() -> logDirect("All Baritone commands (clickable):"),
|
|
|
|
command -> {
|
|
|
|
String names = String.join("/", command.names);
|
|
|
|
String name = command.names.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.names.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
|
2019-08-30 18:55:25 +00:00
|
|
|
);
|
|
|
|
} else {
|
2019-08-30 19:25:59 +00:00
|
|
|
String commandName = args.getString().toLowerCase();
|
2019-08-30 18:55:25 +00:00
|
|
|
Command command = getCommand(commandName);
|
|
|
|
|
|
|
|
if (isNull(command)) {
|
|
|
|
throw new CommandNotFoundException(commandName);
|
|
|
|
}
|
|
|
|
|
2019-09-06 10:59:10 +00:00
|
|
|
logDirect(String.format("%s - %s", String.join(" / ", command.names), command.getShortDesc()));
|
2019-08-30 18:55:25 +00:00
|
|
|
logDirect("");
|
|
|
|
command.getLongDesc().forEach(this::logDirect);
|
|
|
|
logDirect("");
|
2019-09-06 10:59:10 +00:00
|
|
|
|
|
|
|
ITextComponent returnComponent = new TextComponentString("Click to return to the help menu");
|
|
|
|
returnComponent.getStyle().setClickEvent(new ClickEvent(
|
2019-09-19 19:53:15 +00:00
|
|
|
ClickEvent.Action.RUN_COMMAND,
|
|
|
|
FORCE_COMMAND_PREFIX + label
|
2019-09-06 10:59:10 +00:00
|
|
|
));
|
|
|
|
|
|
|
|
logDirect(returnComponent);
|
2019-08-30 18:55:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) {
|
|
|
|
if (args.hasExactlyOne()) {
|
2019-08-30 19:25:59 +00:00
|
|
|
return new TabCompleteHelper().addCommands().filterPrefix(args.getString()).stream();
|
2019-08-30 18:55:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Stream.empty();
|
|
|
|
}
|
|
|
|
|
2019-09-06 10:59:10 +00:00
|
|
|
@Override
|
|
|
|
public String getShortDesc() {
|
|
|
|
return "View all commands or help on specific ones";
|
|
|
|
}
|
|
|
|
|
2019-08-30 18:55:25 +00:00
|
|
|
@Override
|
|
|
|
public List<String> getLongDesc() {
|
|
|
|
return asList(
|
2019-09-19 19:53:15 +00:00
|
|
|
"Using this command, you can view detailed help information on how to use certain commands of Baritone.",
|
|
|
|
"",
|
|
|
|
"Usage:",
|
|
|
|
"> help - Lists all commands and their short descriptions.",
|
|
|
|
"> help <command> - Displays help information on a specific command."
|
2019-08-30 18:55:25 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|