[FEATURE] Описание категорий комманд

This commit is contained in:
Gravit 2019-04-13 05:33:35 +07:00
parent 6d03a3bcaf
commit 8192cc50d8
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
2 changed files with 20 additions and 14 deletions

View file

@ -4,6 +4,7 @@
import ru.gravit.utils.command.Command;
import ru.gravit.utils.command.CommandCategory;
import ru.gravit.utils.command.CommandException;
import ru.gravit.utils.command.CommandHandler;
import ru.gravit.utils.helper.LogHelper;
import java.util.Map;
@ -15,9 +16,10 @@ private static void printCommand(String name, Command command) {
LogHelper.subInfo("%s %s - %s", name, args == null ? "[nothing]" : args, command.getUsageDescription());
}
private static void printCategory(String name)
private static void printCategory(String name, String description)
{
LogHelper.info("Category: %s", name);
if(description != null) LogHelper.info("Category: %s - %s", name, description);
else LogHelper.info("Category: %s", name);
}
public HelpCommand(LaunchServer server) {
@ -50,13 +52,13 @@ private void printCommand(String name) throws CommandException {
}
private void printCommands() {
for(Map.Entry<String, CommandCategory> category : server.commandHandler.getCategories().entrySet())
for(CommandHandler.Category category : server.commandHandler.getCategories())
{
printCategory(category.getKey());
for (Entry<String, Command> entry : category.getValue().commandsMap().entrySet())
printCategory(category.name, category.description);
for (Entry<String, Command> entry : category.category.commandsMap().entrySet())
printCommand(entry.getKey(), entry.getValue());
}
printCategory("Base");
printCategory("Base", null);
for (Entry<String, Command> entry : server.commandHandler.getBaseCategory().commandsMap().entrySet())
printCommand(entry.getKey(), entry.getValue());

View file

@ -5,16 +5,20 @@
import ru.gravit.utils.helper.VerifyHelper;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
public abstract class CommandHandler implements Runnable {
private final Map<String, CommandCategory> categories = new ConcurrentHashMap<>(8);
private final List<Category> categories = new ArrayList<>();
private final CommandCategory baseCategory = new BaseCommandCategory();
public class Category
{
public CommandCategory category;
public String name;
public String description;
}
public void eval(String line, boolean bell) {
LogHelper.info("Command '%s'", line);
@ -67,9 +71,9 @@ public Command findCommand(String name)
Command cmd = baseCategory.findCommand(name);
if(cmd == null)
{
for(Map.Entry<String, CommandCategory> entry : categories.entrySet())
for(Category entry : categories)
{
cmd = entry.getValue().findCommand(name);
cmd = entry.category.findCommand(name);
if(cmd != null) return cmd;
}
}
@ -106,7 +110,7 @@ public CommandCategory getBaseCategory() {
return baseCategory;
}
public Map<String, CommandCategory> getCategories() {
public List<Category> getCategories() {
return categories;
}