2017-04-22 47 views
0

我想制作一个插件,它有很多命令,我需要组织这些命令,以便将每个命令放到不同的类中。我只想让一个CommandExecutor将值和类放入一个HashMap中,然后在我的主类中调用该执行器。有人可以举个例子吗?使用HashMap(Bukkit)组织命令

我不想使用基本的getCommand("command").setExecutor(new Commands());,因为它在20命令后显得很愚蠢。我现在为此搜索了3天,并没有找到任何有用的例子。

回答

2

我建议你做这样的事情:

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)); 
}