Add /su commandinfo command

This command will output information about the specified command, like which plugin it belongs to, which usages, aliases, names, description and permissions it has. Permission to use the command is `serverutils.commandinfo`.
This commit is contained in:
Frank van der Heijden 2020-06-09 20:51:01 +02:00
parent 4c035fdc59
commit 04f3314e8a
No known key found for this signature in database
GPG key ID: 26DA56488D314D11
4 changed files with 76 additions and 9 deletions

View file

@ -197,4 +197,46 @@ public class CommandServerUtils extends BaseCommand {
builder.sendTo(sender);
Messenger.sendMessage(sender, "serverutils.plugininfo.footer");
}
@Subcommand("commandinfo")
@CommandCompletion("@commands")
@CommandPermission("serverutils.commandinfo")
@Description("Shows information about the specified command.")
public void onCommandInfo(CommandSender sender, String command) {
Command cmd = PluginManager.getCommand(command);
if (cmd == null) {
Messenger.sendMessage(sender, "serverutils.commandinfo.not_exists");
return;
}
String format = Messenger.getMessage("serverutils.commandinfo.format");
String listFormatString = Messenger.getMessage("serverutils.commandinfo.list_format");
String seperator = Messenger.getMessage("serverutils.commandinfo.seperator");
String lastSeperator = Messenger.getMessage("serverutils.commandinfo.last_seperator");
ListFormat<String> listFormat = str -> listFormatString.replace("%value%", str);
Messenger.sendMessage(sender, "serverutils.commandinfo.header");
FormatBuilder builder = FormatBuilder.create(format)
.orderedKeys("%key%", "%value%")
.add("Name", cmd.getName());
if (cmd instanceof PluginIdentifiableCommand) {
PluginIdentifiableCommand pc = (PluginIdentifiableCommand) cmd;
builder.add("Plugin", pc.getPlugin().getName());
}
builder.add("Usage", cmd.getUsage())
.add("Description", cmd.getDescription())
.add("Aliases", ListBuilder.create(cmd.getAliases())
.format(listFormat)
.seperator(seperator)
.lastSeperator(lastSeperator)
.toString())
.add("Label", cmd.getLabel())
.add("Timings Name", cmd.getTimingName())
.add("Permission", cmd.getPermission())
.add("Permission Message", cmd.getPermissionMessage());
builder.sendTo(sender);
Messenger.sendMessage(sender, "serverutils.commandinfo.footer");
}
}