🎨 Show less useless info in MinecraftHelp

This commit is contained in:
jmp 2020-10-08 22:09:53 -07:00 • committed by Alexander Söderberg
parent decde5cc77
commit 70818bb4b2
2 changed files with 83 additions and 81 deletions

View file

@ -230,10 +230,8 @@ public final class MinecraftHelp<C> {
while (iterator.hasNext()) { while (iterator.hasNext()) {
final CommandHelpHandler.VerboseHelpEntry<C> entry = iterator.next(); final CommandHelpHandler.VerboseHelpEntry<C> entry = iterator.next();
final String description = entry.getDescription().isEmpty() ? this.messageProvider.apply( final String description = entry.getDescription().isEmpty()
sender, ? this.messageProvider.apply(sender, MESSAGE_CLICK_TO_SHOW_HELP)
MESSAGE_CLICK_TO_SHOW_HELP
)
: entry.getDescription(); : entry.getDescription();
Component message = Component.text(" ") Component message = Component.text(" ")
@ -291,54 +289,58 @@ public final class MinecraftHelp<C> {
)) ))
.append(this.highlight(Component.text("/" + command, this.colors.highlight))) .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( audience.sendMessage(
Component.text(" ") Component.text(" ")
.append(this.branch()) .append(hasArguments ? this.branch() : this.lastBranch())
.append(Component.text( .append(Component.text(
" " + this.messageProvider.apply(sender, MESSAGE_DESCRIPTION) + ": ", " " + this.messageProvider.apply(sender, MESSAGE_DESCRIPTION) + ": ",
this.colors.primary this.colors.primary
)) ))
.append(Component.text(helpTopic.getDescription(), this.colors.text)) .append(Component.text(topicDescription, this.colors.text))
);
audience.sendMessage(
Component.text(" ")
.append(this.lastBranch())
.append(Component.text(
" " + this.messageProvider.apply(sender, MESSAGE_ARGUMENTS) + ":",
this.colors.primary
))
); );
if (hasArguments) {
audience.sendMessage(
Component.text(" ")
.append(this.lastBranch())
.append(Component.text(
" " + this.messageProvider.apply(sender, MESSAGE_ARGUMENTS) + ":",
this.colors.primary
))
);
final Iterator<CommandArgument<C, ?>> iterator = helpTopic.getCommand().getArguments().iterator(); final Iterator<CommandArgument<C, ?>> iterator = helpTopic.getCommand().getArguments().iterator();
/* Skip the first one because it's the command literal */ /* Skip the first one because it's the command literal */
iterator.next(); iterator.next();
while (iterator.hasNext()) { while (iterator.hasNext()) {
final CommandArgument<C, ?> argument = iterator.next(); final CommandArgument<C, ?> argument = iterator.next();
String description = helpTopic.getCommand().getArgumentDescription(argument); String syntax = this.commandManager.getCommandSyntaxFormatter()
if (description.isEmpty()) { .apply(Collections.singletonList(argument), null);
description = this.messageProvider.apply(sender, MESSAGE_NO_DESCRIPTION);
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);
} }
} }

View file

@ -305,46 +305,46 @@ public final class ExamplePlugin extends JavaPlugin {
// //
// A command to change the color scheme for the help command // A command to change the color scheme for the help command
// //
manager.command( manager.command(builder
manager.commandBuilder("example") .meta("description", "Sets the color scheme for '/example help'")
.literal("helpcolors") .literal("helpcolors")
.argument( .argument(
manager.argumentBuilder(TextColor.class, "primary") manager.argumentBuilder(TextColor.class, "primary")
.withParser(textColorArgumentParser) .withParser(textColorArgumentParser)
.withSuggestionsProvider(textColorSuggestionsProvider), .withSuggestionsProvider(textColorSuggestionsProvider),
Description.of("The primary color for the color scheme") Description.of("The primary color for the color scheme")
) )
.argument( .argument(
manager.argumentBuilder(TextColor.class, "highlight") manager.argumentBuilder(TextColor.class, "highlight")
.withParser(textColorArgumentParser) .withParser(textColorArgumentParser)
.withSuggestionsProvider(textColorSuggestionsProvider), .withSuggestionsProvider(textColorSuggestionsProvider),
Description.of("The primary color used to highlight commands and queries") Description.of("The primary color used to highlight commands and queries")
) )
.argument( .argument(
manager.argumentBuilder(TextColor.class, "alternate_highlight") manager.argumentBuilder(TextColor.class, "alternate_highlight")
.withParser(textColorArgumentParser) .withParser(textColorArgumentParser)
.withSuggestionsProvider(textColorSuggestionsProvider), .withSuggestionsProvider(textColorSuggestionsProvider),
Description.of("The secondary color used to highlight commands and queries") Description.of("The secondary color used to highlight commands and queries")
) )
.argument( .argument(
manager.argumentBuilder(TextColor.class, "text") manager.argumentBuilder(TextColor.class, "text")
.withParser(textColorArgumentParser) .withParser(textColorArgumentParser)
.withSuggestionsProvider(textColorSuggestionsProvider), .withSuggestionsProvider(textColorSuggestionsProvider),
Description.of("The color used for description text") Description.of("The color used for description text")
) )
.argument( .argument(
manager.argumentBuilder(TextColor.class, "accent") manager.argumentBuilder(TextColor.class, "accent")
.withParser(textColorArgumentParser) .withParser(textColorArgumentParser)
.withSuggestionsProvider(textColorSuggestionsProvider), .withSuggestionsProvider(textColorSuggestionsProvider),
Description.of("The color used for accents and symbols") Description.of("The color used for accents and symbols")
) )
.handler(c -> minecraftHelp.setHelpColors(MinecraftHelp.HelpColors.of( .handler(c -> minecraftHelp.setHelpColors(MinecraftHelp.HelpColors.of(
c.get("primary"), c.get("primary"),
c.get("highlight"), c.get("highlight"),
c.get("alternate_highlight"), c.get("alternate_highlight"),
c.get("text"), c.get("text"),
c.get("accent") c.get("accent")
))) )))
); );
} }