From 2486388e18432a4235e2da292adb28e61dda0683 Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Thu, 25 Apr 2019 23:02:23 -0700 Subject: [PATCH] Fix help command suggestion --- .../worldedit/command/util/PrintCommandHelp.java | 14 ++++++++++---- .../util/formatting/component/CommandListBox.java | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/PrintCommandHelp.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/PrintCommandHelp.java index 48f835a61..57337b322 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/PrintCommandHelp.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/PrintCommandHelp.java @@ -20,6 +20,7 @@ package com.sk89q.worldedit.command.util; import com.google.common.base.Joiner; +import com.google.common.collect.ImmutableList; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; @@ -35,6 +36,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.stream.Collectors; import java.util.stream.Stream; import static com.sk89q.worldedit.util.command.CommandUtil.byCleanName; @@ -77,7 +79,7 @@ public class PrintCommandHelp { final int perPage = actor instanceof Player ? 8 : 20; // More pages for console if (commandPath.isEmpty()) { - printAllCommands(page, perPage, manager.getAllCommands(), actor, true); + printAllCommands(page, perPage, manager.getAllCommands(), actor, ImmutableList.of()); return; } @@ -117,11 +119,12 @@ public class PrintCommandHelp { CommandUsageBox box = new CommandUsageBox(currentCommand, String.join(" ", visited)); actor.print(box.create()); } else { - printAllCommands(page, perPage, subCommands.values().stream(), actor, false); + printAllCommands(page, perPage, subCommands.values().stream(), actor, visited); } } - private static void printAllCommands(int page, int perPage, Stream commandStream, Actor actor, boolean isRootLevel) { + private static void printAllCommands(int page, int perPage, Stream commandStream, Actor actor, + List commandList) { // Get a list of aliases List commands = commandStream .sorted(byCleanName()) @@ -147,7 +150,10 @@ public class PrintCommandHelp { // Add each command for (Command mapping : list) { - box.appendCommand((isRootLevel ? "/" : "") + mapping.getName(), mapping.getDescription()); + String alias = (commandList.isEmpty() ? "/" : "") + mapping.getName(); + String command = Stream.concat(commandList.stream(), Stream.of(mapping.getName())) + .collect(Collectors.joining(" ", "/", "")); + box.appendCommand(alias, mapping.getDescription(), command); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandListBox.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandListBox.java index c049006b6..f39a74656 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandListBox.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandListBox.java @@ -53,7 +53,7 @@ public class CommandListBox extends MessageBox { TextComponent commandName = TextComponent.of(alias, TextColor.GOLD); if (insertion != null) { commandName = commandName - .clickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, insertion)) + .clickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, insertion)) .hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to select"))); } getContents().append(commandName.append(TextComponent.of(": ")));