Make the generated help menu a little prettier and add command insertions
This commit is contained in:
parent
78144c1c16
commit
146bbc2db3
3 changed files with 44 additions and 15 deletions
|
|
@ -98,6 +98,12 @@
|
||||||
<groupId>net.kyori</groupId>
|
<groupId>net.kyori</groupId>
|
||||||
<artifactId>adventure-platform-bukkit</artifactId>
|
<artifactId>adventure-platform-bukkit</artifactId>
|
||||||
<version>4.0.0-SNAPSHOT</version>
|
<version>4.0.0-SNAPSHOT</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>4.0.0-SNAPSHOT</groupId>
|
||||||
|
<artifactId>adventure-platform-viaversion</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,9 @@ public final class BukkitTest extends JavaPlugin {
|
||||||
);
|
);
|
||||||
|
|
||||||
final BukkitAudiences bukkitAudiences = BukkitAudiences.create(this);
|
final BukkitAudiences bukkitAudiences = BukkitAudiences.create(this);
|
||||||
final MinecraftHelp<CommandSender> minecraftHelp = new MinecraftHelp<>(bukkitAudiences::audience, mgr);
|
final MinecraftHelp<CommandSender> minecraftHelp = new MinecraftHelp<>("/cloud help",
|
||||||
|
bukkitAudiences::audience,
|
||||||
|
mgr);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
((PaperCommandManager<CommandSender>) mgr).registerBrigadier();
|
((PaperCommandManager<CommandSender>) mgr).registerBrigadier();
|
||||||
|
|
|
||||||
|
|
@ -64,15 +64,19 @@ public final class MinecraftHelp<C> {
|
||||||
|
|
||||||
private final AudienceProvider<C> audienceProvider;
|
private final AudienceProvider<C> audienceProvider;
|
||||||
private final CommandManager<C> commandManager;
|
private final CommandManager<C> commandManager;
|
||||||
|
private final String commandPrefix;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new Minecraft help instance
|
* Construct a new Minecraft help instance
|
||||||
*
|
*
|
||||||
|
* @param commandPrefix Command that was used to trigger the help menu. Used to help insertion generation
|
||||||
* @param audienceProvider Provider that maps the command sender type to {@link Audience}
|
* @param audienceProvider Provider that maps the command sender type to {@link Audience}
|
||||||
* @param commandManager Command manager instance
|
* @param commandManager Command manager instance
|
||||||
*/
|
*/
|
||||||
public MinecraftHelp(@Nonnull final AudienceProvider<C> audienceProvider,
|
public MinecraftHelp(@Nonnull final String commandPrefix,
|
||||||
|
@Nonnull final AudienceProvider<C> audienceProvider,
|
||||||
@Nonnull final CommandManager<C> commandManager) {
|
@Nonnull final CommandManager<C> commandManager) {
|
||||||
|
this.commandPrefix = commandPrefix;
|
||||||
this.audienceProvider = audienceProvider;
|
this.audienceProvider = audienceProvider;
|
||||||
this.commandManager = commandManager;
|
this.commandManager = commandManager;
|
||||||
/* Default messages */
|
/* Default messages */
|
||||||
|
|
@ -81,11 +85,13 @@ public final class MinecraftHelp<C> {
|
||||||
this.messageMap.put(MESSAGE_QUERY_QUERY, "<gray>Showing search results for query: \"<green>/<query></green>\"</gray>");
|
this.messageMap.put(MESSAGE_QUERY_QUERY, "<gray>Showing search results for query: \"<green>/<query></green>\"</gray>");
|
||||||
this.messageMap.put(MESSAGE_QUERY_AVAILABLE_COMMANDS, "<dark_gray>└─</dark_gray><gray> Available Commands:</gray>");
|
this.messageMap.put(MESSAGE_QUERY_AVAILABLE_COMMANDS, "<dark_gray>└─</dark_gray><gray> Available Commands:</gray>");
|
||||||
this.messageMap.put(MESSAGE_QUERY_COMMAND_SYNTAX, "<dark_gray> ├─</dark_gray> <green>"
|
this.messageMap.put(MESSAGE_QUERY_COMMAND_SYNTAX, "<dark_gray> ├─</dark_gray> <green>"
|
||||||
+ "<hover:show_text:\"<gray><description></gray>\">/<command></hover></green>");
|
+ "<click:run_command:cmdprefix><hover:show_text:\"<gray><description></gray>\">/<command></hover></click></green>");
|
||||||
this.messageMap.put(MESSAGE_QUERY_COMMAND_SYNTAX_LAST, "<dark_gray> └─</dark_gray> <green>"
|
this.messageMap.put(MESSAGE_QUERY_COMMAND_SYNTAX_LAST, "<dark_gray> └─</dark_gray> <green>"
|
||||||
+ "<hover:show_text:\"<gray><description></gray>\">/<command></hover></green>");
|
+ "<click:run_command:cmdprefix><hover:show_text:\"<gray><description></gray>\">/<command></hover></click></green>");
|
||||||
this.messageMap.put(MESSAGE_QUERY_LONGEST_PATH, "<dark_gray>└─</dark_gray> <green>/<command></green>");
|
this.messageMap.put(MESSAGE_QUERY_LONGEST_PATH, "<dark_gray>└─</dark_gray> <green>/<command></green>");
|
||||||
this.messageMap.put(MESSAGE_QUERY_SUGGESTION, "<dark_gray><indentation><prefix></dark_gray> <green><suggestion></green>");
|
this.messageMap.put(MESSAGE_QUERY_SUGGESTION, "<dark_gray><indentation><prefix></dark_gray> <green><click:run_command:"
|
||||||
|
+ "<cmdprefix>><hover:show_text:\"<gray>Click to show help for this command</gray>\">"
|
||||||
|
+ "<suggestion></hover></click></green>");
|
||||||
this.messageMap.put(MESSAGE_QUERY_VERBOSE_SYNTAX, "<dark_gray>└─</dark_gray> <gold>Command:"
|
this.messageMap.put(MESSAGE_QUERY_VERBOSE_SYNTAX, "<dark_gray>└─</dark_gray> <gold>Command:"
|
||||||
+ " </gold><green>/<command></green>");
|
+ " </gold><green>/<command></green>");
|
||||||
this.messageMap.put(MESSAGE_QUERY_VERBOSE_DESCRIPTION, "<dark_gray> ├─</dark_gray>"
|
this.messageMap.put(MESSAGE_QUERY_VERBOSE_DESCRIPTION, "<dark_gray> ├─</dark_gray>"
|
||||||
|
|
@ -175,15 +181,24 @@ public final class MinecraftHelp<C> {
|
||||||
final Iterator<CommandHelpHandler.VerboseHelpEntry<C>> iterator = helpTopic.getEntries().iterator();
|
final Iterator<CommandHelpHandler.VerboseHelpEntry<C>> iterator = helpTopic.getEntries().iterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
final CommandHelpHandler.VerboseHelpEntry<C> entry = iterator.next();
|
final CommandHelpHandler.VerboseHelpEntry<C> entry = iterator.next();
|
||||||
if (iterator.hasNext()) {
|
|
||||||
audience.sendMessage(this.miniMessage.parse(this.messageMap.get(MESSAGE_QUERY_COMMAND_SYNTAX),
|
final String description = entry.getDescription().isEmpty() ? "Click to show help for this command"
|
||||||
Template.of("command", entry.getSyntaxString()),
|
: entry.getDescription();
|
||||||
Template.of("description", entry.getDescription())));
|
|
||||||
} else {
|
String message = this.messageMap.get(iterator.hasNext() ? MESSAGE_QUERY_COMMAND_SYNTAX
|
||||||
audience.sendMessage(this.miniMessage.parse(this.messageMap.get(MESSAGE_QUERY_COMMAND_SYNTAX_LAST),
|
: MESSAGE_QUERY_COMMAND_SYNTAX_LAST);
|
||||||
Template.of("command", entry.getSyntaxString()),
|
|
||||||
Template.of("description", entry.getDescription())));
|
final String suggestedCommand = entry.getSyntaxString()
|
||||||
}
|
.replace("<", "")
|
||||||
|
.replace(">", "")
|
||||||
|
.replace("[", "")
|
||||||
|
.replace("]", "");
|
||||||
|
|
||||||
|
message = message.replace("<command>", entry.getSyntaxString())
|
||||||
|
.replace("<description>", description)
|
||||||
|
.replace("cmdprefix", this.commandPrefix + ' ' + suggestedCommand);
|
||||||
|
|
||||||
|
audience.sendMessage(this.miniMessage.parse(message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -208,10 +223,16 @@ public final class MinecraftHelp<C> {
|
||||||
prefix = "└─";
|
prefix = "└─";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final String suggestedCommand = suggestion.replace("<", "")
|
||||||
|
.replace(">", "")
|
||||||
|
.replace("[", "")
|
||||||
|
.replace("]", "");
|
||||||
|
|
||||||
audience.sendMessage(this.miniMessage.parse(this.messageMap.get(MESSAGE_QUERY_SUGGESTION),
|
audience.sendMessage(this.miniMessage.parse(this.messageMap.get(MESSAGE_QUERY_SUGGESTION),
|
||||||
Template.of("indentation", indentation.toString()),
|
Template.of("indentation", indentation.toString()),
|
||||||
Template.of("prefix", prefix),
|
Template.of("prefix", prefix),
|
||||||
Template.of("suggestion", suggestion)));
|
Template.of("suggestion", suggestion),
|
||||||
|
Template.of("cmdprefix", this.commandPrefix + ' ' + suggestedCommand)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue