mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-02-22 15:31:39 +01:00
Improve help command with better formatting.
This commit is contained in:
parent
114400e77b
commit
44cbdc3baf
@ -8,7 +8,11 @@
|
||||
package com.onarandombox.MultiverseCore.commandTools;
|
||||
|
||||
import co.aikar.commands.BukkitCommandCompletionContext;
|
||||
import co.aikar.commands.BukkitCommandExecutionContext;
|
||||
import co.aikar.commands.CommandIssuer;
|
||||
import co.aikar.commands.PaperCommandCompletions;
|
||||
import co.aikar.commands.RegisteredCommand;
|
||||
import co.aikar.commands.RootCommand;
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MVWorld;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
@ -31,6 +35,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -51,6 +56,7 @@ public class MVCommandCompletions extends PaperCommandCompletions {
|
||||
this.plugin = plugin;
|
||||
this.worldManager = plugin.getMVWorldManager();
|
||||
|
||||
registerAsyncCompletion("subCommands", this::suggestSubCommands);
|
||||
registerAsyncCompletion("MVWorlds", this::suggestMVWorlds);
|
||||
registerAsyncCompletion("unloadedWorlds", this::suggestUnloadedWorlds);
|
||||
registerAsyncCompletion("potentialWorlds", this::suggestPotentialWorlds);
|
||||
@ -67,6 +73,37 @@ public class MVCommandCompletions extends PaperCommandCompletions {
|
||||
registerStaticCompletion("toggles", this::suggestToggles);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Collection<String> suggestSubCommands(@NotNull BukkitCommandCompletionContext context) {
|
||||
String rootCmdName = context.getConfig();
|
||||
if (rootCmdName == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
RootCommand rootCommand = this.plugin.getMVCommandManager().getRegisteredRootCommands().stream()
|
||||
.unordered()
|
||||
.filter(c -> c.getCommandName().equals(rootCmdName))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
if (rootCommand == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return rootCommand.getSubCommands().entries().stream()
|
||||
.unordered()
|
||||
.filter(entry -> checkPerms(context.getIssuer(), entry.getValue()))
|
||||
.map(Map.Entry::getKey)
|
||||
.filter(cmdName -> !cmdName.startsWith("__"))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private boolean checkPerms(@NotNull CommandIssuer issuer,
|
||||
@NotNull RegisteredCommand<?> cmd) {
|
||||
|
||||
return this.plugin.getMVCommandManager().hasPermission(issuer, cmd.getRequiredPermissions());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Collection<String> suggestToggles() {
|
||||
return Arrays.asList("on", "off");
|
||||
@ -139,6 +176,7 @@ public class MVCommandCompletions extends PaperCommandCompletions {
|
||||
return Arrays.asList("~", df.format(coordValue));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Collection<String> suggestDestinations(@NotNull BukkitCommandCompletionContext context) {
|
||||
return this.plugin.getDestFactory().getIdentifiers().parallelStream()
|
||||
.unordered()
|
||||
@ -147,6 +185,7 @@ public class MVCommandCompletions extends PaperCommandCompletions {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Collection<String> suggestAnchors(@NotNull BukkitCommandCompletionContext context) {
|
||||
return this.plugin.getAnchorManager().getAnchors(context.getPlayer());
|
||||
}
|
||||
|
@ -11,7 +11,9 @@ import co.aikar.commands.BukkitCommandCompletionContext;
|
||||
import co.aikar.commands.BukkitCommandExecutionContext;
|
||||
import co.aikar.commands.CommandCompletions;
|
||||
import co.aikar.commands.CommandContexts;
|
||||
import co.aikar.commands.CommandHelp;
|
||||
import co.aikar.commands.CommandIssuer;
|
||||
import co.aikar.commands.HelpEntry;
|
||||
import co.aikar.commands.PaperCommandManager;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.commands.AnchorCommand;
|
||||
@ -52,6 +54,7 @@ import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ -69,6 +72,7 @@ public class MVCommandManager extends PaperCommandManager {
|
||||
new MVCommandConditions(plugin, getCommandConditions());
|
||||
|
||||
enableUnstableAPI("help");
|
||||
setDefaultHelpPerPage(6);
|
||||
|
||||
registerCommand(new UsageCommand(this.plugin));
|
||||
registerCommand(new CreateCommand(this.plugin));
|
||||
@ -163,6 +167,17 @@ public class MVCommandManager extends PaperCommandManager {
|
||||
return commandQueueManager;
|
||||
}
|
||||
|
||||
public void showUsage(@NotNull CommandHelp help) {
|
||||
List<HelpEntry> entries = help.getHelpEntries();
|
||||
|
||||
if (entries.size() == 1) {
|
||||
this.plugin.getMVCommandManager().getHelpFormatter().showDetailedHelp(help, entries.get(0));
|
||||
return;
|
||||
}
|
||||
|
||||
help.showHelp();
|
||||
}
|
||||
|
||||
public void showPluginInfo(@NotNull CommandSender sender,
|
||||
@NotNull PluginDescriptionFile description,
|
||||
@NotNull ColourAlternator colour,
|
||||
|
@ -8,7 +8,13 @@
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import co.aikar.commands.CommandHelp;
|
||||
import co.aikar.commands.annotation.*;
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.HelpCommand;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -20,16 +26,15 @@ public class UsageCommand extends MultiverseCommand {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Subcommand("help")
|
||||
@HelpCommand
|
||||
@Subcommand("help")
|
||||
@CommandPermission("multiverse.core.help")
|
||||
@Syntax("[filter] [page]")
|
||||
@Description("Show Multiverse Command usage.")
|
||||
@CommandCompletion("@subCommands:mv")
|
||||
@Description("Show Multiverse-Core Command usage.")
|
||||
public void onUsageCommand(@NotNull CommandSender sender,
|
||||
@NotNull CommandHelp help) {
|
||||
|
||||
//TODO ACF: Proper formatting and paging.
|
||||
help.setPerPage(6);
|
||||
help.showHelp();
|
||||
this.plugin.getMVCommandManager().showUsage(help);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user