From 70818bb4b263dec46c30d693919363774a1c76d3 Mon Sep 17 00:00:00 2001 From: jmp Date: Thu, 8 Oct 2020 22:09:53 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Show=20less=20useless=20info=20i?= =?UTF-8?q?n=20MinecraftHelp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cloud/commandframework/MinecraftHelp.java | 84 ++++++++++--------- .../examples/bukkit/ExamplePlugin.java | 80 +++++++++--------- 2 files changed, 83 insertions(+), 81 deletions(-) diff --git a/cloud-minecraft/cloud-minecraft-extras/src/main/java/cloud/commandframework/MinecraftHelp.java b/cloud-minecraft/cloud-minecraft-extras/src/main/java/cloud/commandframework/MinecraftHelp.java index af130058..d9ebc83d 100644 --- a/cloud-minecraft/cloud-minecraft-extras/src/main/java/cloud/commandframework/MinecraftHelp.java +++ b/cloud-minecraft/cloud-minecraft-extras/src/main/java/cloud/commandframework/MinecraftHelp.java @@ -230,10 +230,8 @@ public final class MinecraftHelp { while (iterator.hasNext()) { final CommandHelpHandler.VerboseHelpEntry entry = iterator.next(); - final String description = entry.getDescription().isEmpty() ? this.messageProvider.apply( - sender, - MESSAGE_CLICK_TO_SHOW_HELP - ) + final String description = entry.getDescription().isEmpty() + ? this.messageProvider.apply(sender, MESSAGE_CLICK_TO_SHOW_HELP) : entry.getDescription(); Component message = Component.text(" ") @@ -291,54 +289,58 @@ public final class MinecraftHelp { )) .append(this.highlight(Component.text("/" + command, this.colors.highlight))) ); + final String topicDescription = helpTopic.getDescription().isEmpty() + ? this.messageProvider.apply(sender, MESSAGE_NO_DESCRIPTION) + : helpTopic.getDescription(); + final boolean hasArguments = helpTopic.getCommand().getArguments().size() > 1; audience.sendMessage( Component.text(" ") - .append(this.branch()) + .append(hasArguments ? this.branch() : this.lastBranch()) .append(Component.text( " " + this.messageProvider.apply(sender, MESSAGE_DESCRIPTION) + ": ", this.colors.primary )) - .append(Component.text(helpTopic.getDescription(), this.colors.text)) - ); - audience.sendMessage( - Component.text(" ") - .append(this.lastBranch()) - .append(Component.text( - " " + this.messageProvider.apply(sender, MESSAGE_ARGUMENTS) + ":", - this.colors.primary - )) + .append(Component.text(topicDescription, this.colors.text)) ); + if (hasArguments) { + audience.sendMessage( + Component.text(" ") + .append(this.lastBranch()) + .append(Component.text( + " " + this.messageProvider.apply(sender, MESSAGE_ARGUMENTS) + ":", + this.colors.primary + )) + ); - final Iterator> iterator = helpTopic.getCommand().getArguments().iterator(); - /* Skip the first one because it's the command literal */ - iterator.next(); + final Iterator> iterator = helpTopic.getCommand().getArguments().iterator(); + /* Skip the first one because it's the command literal */ + iterator.next(); - while (iterator.hasNext()) { - final CommandArgument argument = iterator.next(); + while (iterator.hasNext()) { + final CommandArgument argument = iterator.next(); - String description = helpTopic.getCommand().getArgumentDescription(argument); - if (description.isEmpty()) { - description = this.messageProvider.apply(sender, MESSAGE_NO_DESCRIPTION); + String syntax = this.commandManager.getCommandSyntaxFormatter() + .apply(Collections.singletonList(argument), null); + + final TextComponent.Builder component = Component.text() + .append(Component.text(" ")) + .append(iterator.hasNext() ? this.branch() : this.lastBranch()) + .append(this.highlight(Component.text(" " + syntax, this.colors.highlight))); + if (!argument.isRequired()) { + component.append(Component.text( + " (" + this.messageProvider.apply(sender, MESSAGE_OPTIONAL) + ")", + this.colors.alternateHighlight + )); + } + final String description = helpTopic.getCommand().getArgumentDescription(argument); + if (!description.isEmpty()) { + component + .append(Component.text(" - ", this.colors.accent)) + .append(Component.text(description, this.colors.text)); + } + + audience.sendMessage(component); } - - String syntax = this.commandManager.getCommandSyntaxFormatter() - .apply(Collections.singletonList(argument), null); - - final TextComponent.Builder component = Component.text() - .append(Component.text(" ")) - .append(iterator.hasNext() ? this.branch() : this.lastBranch()) - .append(this.highlight(Component.text(" " + syntax, this.colors.highlight))); - if (!argument.isRequired()) { - component.append(Component.text( - " (" + this.messageProvider.apply(sender, MESSAGE_OPTIONAL) + ")", - this.colors.alternateHighlight - )); - } - component - .append(Component.text(" - ", this.colors.accent)) - .append(Component.text(description, this.colors.text)); - - audience.sendMessage(component); } } diff --git a/examples/example-bukkit/src/main/java/cloud/commandframework/examples/bukkit/ExamplePlugin.java b/examples/example-bukkit/src/main/java/cloud/commandframework/examples/bukkit/ExamplePlugin.java index f5a11bf4..3c91475b 100644 --- a/examples/example-bukkit/src/main/java/cloud/commandframework/examples/bukkit/ExamplePlugin.java +++ b/examples/example-bukkit/src/main/java/cloud/commandframework/examples/bukkit/ExamplePlugin.java @@ -305,46 +305,46 @@ public final class ExamplePlugin extends JavaPlugin { // // A command to change the color scheme for the help command // - manager.command( - manager.commandBuilder("example") - .literal("helpcolors") - .argument( - manager.argumentBuilder(TextColor.class, "primary") - .withParser(textColorArgumentParser) - .withSuggestionsProvider(textColorSuggestionsProvider), - Description.of("The primary color for the color scheme") - ) - .argument( - manager.argumentBuilder(TextColor.class, "highlight") - .withParser(textColorArgumentParser) - .withSuggestionsProvider(textColorSuggestionsProvider), - Description.of("The primary color used to highlight commands and queries") - ) - .argument( - manager.argumentBuilder(TextColor.class, "alternate_highlight") - .withParser(textColorArgumentParser) - .withSuggestionsProvider(textColorSuggestionsProvider), - Description.of("The secondary color used to highlight commands and queries") - ) - .argument( - manager.argumentBuilder(TextColor.class, "text") - .withParser(textColorArgumentParser) - .withSuggestionsProvider(textColorSuggestionsProvider), - Description.of("The color used for description text") - ) - .argument( - manager.argumentBuilder(TextColor.class, "accent") - .withParser(textColorArgumentParser) - .withSuggestionsProvider(textColorSuggestionsProvider), - Description.of("The color used for accents and symbols") - ) - .handler(c -> minecraftHelp.setHelpColors(MinecraftHelp.HelpColors.of( - c.get("primary"), - c.get("highlight"), - c.get("alternate_highlight"), - c.get("text"), - c.get("accent") - ))) + manager.command(builder + .meta("description", "Sets the color scheme for '/example help'") + .literal("helpcolors") + .argument( + manager.argumentBuilder(TextColor.class, "primary") + .withParser(textColorArgumentParser) + .withSuggestionsProvider(textColorSuggestionsProvider), + Description.of("The primary color for the color scheme") + ) + .argument( + manager.argumentBuilder(TextColor.class, "highlight") + .withParser(textColorArgumentParser) + .withSuggestionsProvider(textColorSuggestionsProvider), + Description.of("The primary color used to highlight commands and queries") + ) + .argument( + manager.argumentBuilder(TextColor.class, "alternate_highlight") + .withParser(textColorArgumentParser) + .withSuggestionsProvider(textColorSuggestionsProvider), + Description.of("The secondary color used to highlight commands and queries") + ) + .argument( + manager.argumentBuilder(TextColor.class, "text") + .withParser(textColorArgumentParser) + .withSuggestionsProvider(textColorSuggestionsProvider), + Description.of("The color used for description text") + ) + .argument( + manager.argumentBuilder(TextColor.class, "accent") + .withParser(textColorArgumentParser) + .withSuggestionsProvider(textColorSuggestionsProvider), + Description.of("The color used for accents and symbols") + ) + .handler(c -> minecraftHelp.setHelpColors(MinecraftHelp.HelpColors.of( + c.get("primary"), + c.get("highlight"), + c.get("alternate_highlight"), + c.get("text"), + c.get("accent") + ))) ); }