您如何访问服务器插件文件夹中的所有可用命令?
可能通过访问每个插件单独的plugin.yml并获取他们的命令。但我只是想知道一个人会怎么做。如果有不同的方式,我就会想到这一点。
答案 0 :(得分:2)
您可以循环遍历所有HelpTopic
,然后将其名称放在列表中:
// create the List to store command names into
List<String> commandNames = new ArrayList<String>();
// loop through all of the helpTopics, a list of all commands displayed
// in /help (therefore all of the commands)
for(HelpTopic cmd : plugin.getServer().getHelpMap().getHelpTopics()){
commandNames.add(cmd.getName());//add the name of the command to the Array
}
在执行此操作之前,您很可能希望等到所有其他插件都启用之后。
答案 1 :(得分:-2)
您可以使用PlayerCommandPreprocessEvent
和ServerCommandEvent
。
// PlayerCommandPreprocessEvent
if (event.getMessage().toLowerCase().startsWith("/help")) {
// Player issued: /help
}
// ServerCommandEvent
if (event.getCommand().toLowerCase().startsWith("help")) {
// Console issued: help
}