@SuppressWarnings("unchecked")
private void loadCommands() {
InputStream resource = getResource("META-INF/.pl.commands.yml");
if (resource == null)
return;
yamlParser.parse(resource, CommandsFile.class).blockingGet().getCommands().forEach((command, handler) -> {
PluginCommand bukkitCmd = getCommand(command);
if (bukkitCmd == null)
throw new IllegalStateException("could not find command '" + command + "' for plugin...");
Class<?> handlerType;
try {
handlerType = Class.forName(handler.handler);
} catch (ClassNotFoundException e) {
throw new IllegalStateException("could not find class " + handler + " for command " + command + "!", e);
}
if (!JCmd.class.isAssignableFrom(handlerType)) {
if (!CommandExecutor.class.isAssignableFrom(handlerType))
throw new IllegalStateException(handlerType.getName() + " is not a valid handler class, does not extend JCmd");
CommandExecutor instance = (CommandExecutor) injector.get().getInstance(handlerType);
bukkitCmd.setExecutor(instance);
if (instance instanceof TabCompleter)
bukkitCmd.setTabCompleter((TabCompleter) instance);
} else {
Class<? extends JCmd> commandType = (Class<? extends JCmd>) handlerType;
JCommandExecutor executor = new JCommandExecutor(commandType, injector);
bukkitCmd.setExecutor(executor);
bukkitCmd.setTabCompleter(executor);
}
getLogger().info("loaded command /" + command + " => " + handlerType.getSimpleName());
});
}
JPl.java 文件源码
java
阅读 28
收藏 0
点赞 0
评论 0
项目:pl
作者:
评论列表
文章目录