From df52e99a8b17f6c60ba11c05ba0f5c3aaaa925e1 Mon Sep 17 00:00:00 2001 From: Irmo van den Berge Date: Mon, 21 Dec 2020 17:45:11 +0100 Subject: [PATCH] Show 'no results for query' in help when multi-help topic is empty Signed-off-by: Irmo van den Berge --- .../minecraft/extras/MinecraftHelp.java | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/cloud-minecraft/cloud-minecraft-extras/src/main/java/cloud/commandframework/minecraft/extras/MinecraftHelp.java b/cloud-minecraft/cloud-minecraft-extras/src/main/java/cloud/commandframework/minecraft/extras/MinecraftHelp.java index 46e35b49..73795d46 100644 --- a/cloud-minecraft/cloud-minecraft-extras/src/main/java/cloud/commandframework/minecraft/extras/MinecraftHelp.java +++ b/cloud-minecraft/cloud-minecraft-extras/src/main/java/cloud/commandframework/minecraft/extras/MinecraftHelp.java @@ -276,24 +276,33 @@ public final class MinecraftHelp { } } + private void printNoResults( + final @NonNull C sender, + final @NonNull String query + ) { + final Audience audience = this.getAudience(sender); + audience.sendMessage(Identity.nil(), this.basicHeader(sender)); + audience.sendMessage(Identity.nil(), Component.text( + this.messageProvider.apply(sender, MESSAGE_NO_RESULTS_FOR_QUERY) + ": \"", + this.colors.text + ) + .append(this.highlight(Component.text("/" + query, this.colors.highlight))) + .append(Component.text("\"", this.colors.text))); + audience.sendMessage(Identity.nil(), this.footer(sender)); + } + private void printIndexHelpTopic( final @NonNull C sender, final @NonNull String query, final int page, final CommandHelpHandler.@NonNull IndexHelpTopic helpTopic ) { - final Audience audience = this.getAudience(sender); if (helpTopic.isEmpty()) { - audience.sendMessage(Identity.nil(), this.basicHeader(sender)); - audience.sendMessage(Identity.nil(), Component.text( - this.messageProvider.apply(sender, MESSAGE_NO_RESULTS_FOR_QUERY) + ": \"", - this.colors.text - ) - .append(this.highlight(Component.text("/" + query, this.colors.highlight))) - .append(Component.text("\"", this.colors.text))); - audience.sendMessage(Identity.nil(), this.footer(sender)); + this.printNoResults(sender, query); return; } + + final Audience audience = this.getAudience(sender); new Pagination>( (currentPage, maxPages) -> { final List header = new ArrayList<>(); @@ -335,6 +344,11 @@ public final class MinecraftHelp { final int page, final CommandHelpHandler.@NonNull MultiHelpTopic helpTopic ) { + if (helpTopic.getChildSuggestions().isEmpty()) { + this.printNoResults(sender, query); + return; + } + final Audience audience = this.getAudience(sender); final int headerIndentation = helpTopic.getLongestPath().length(); new Pagination(