使用 HashMap (Bukkit) 组织命令

Organizing commands with HashMap (Bukkit)

我正在尝试制作一个包含很多命令的插件,我需要组织这些命令,所以我将每个命令放入不同的 classes 中。我只想制作一个将值和 class 放入 HashMap 中的 CommandExecutor,然后在我的主 class 中调用该执行器。有人可以举个例子吗?

我不想使用基本的 getCommand("command").setExecutor(new Commands()); 因为它在 20 命令后看起来很傻。我为此搜索了 3 天,但没有找到任何有用的示例。

我建议你这样做:

HashMap<String, CommandExecutor> commands = new HashMap<String, CommandExecutor>;

commands.put("firstcommand", new FirstCommand());
commands.put("secondcommand", new SecondCommand());

for (String name : commands.keySet()) {
    getCommand(name).setExecutor(commands.get(name));
}