use of com.archyx.aureliumskills.menu.templates.ConfigurableTemplate in project AureliumSkills by Archy-X.
the class MenuLoader method load.
public void load() throws IllegalAccessException, InstantiationException, InvocationTargetException {
File file = new File(plugin.getDataFolder(), "menus.yml");
if (!file.exists()) {
plugin.saveResource("menus.yml", false);
}
FileConfiguration config = updateFile(file, YamlConfiguration.loadConfiguration(file));
int menusLoaded = 0;
int itemsLoaded = 0;
int templatesLoaded = 0;
long start = System.currentTimeMillis();
// Load menus
for (MenuType menuType : MenuType.values()) {
ConfigurationSection menu = config.getConfigurationSection(menuType.getPath());
if (menu != null) {
MenuOption menuOption = new MenuOption(menuType);
menuOption.setTitle(menu.getString("title"));
menuOption.setRows(menu.getInt("rows"));
menuOption.setFillEnabled(menu.getBoolean("fill.enabled", true));
// Load fill material
ItemStack fillItem = parseItem(menu.getString("fill.material"), XMaterial.BLACK_STAINED_GLASS_PANE.parseMaterial());
ItemMeta meta = fillItem.getItemMeta();
if (meta != null) {
meta.setDisplayName(" ");
fillItem.setItemMeta(meta);
}
menuOption.setFillItem(fillItem);
// Load items
for (ItemType itemType : menuType.getItems()) {
Class<?> loader = itemType.getLoader();
ConfigurableItem configurableItem;
try {
configurableItem = (ConfigurableItem) loader.getConstructors()[0].newInstance(plugin);
} catch (IllegalArgumentException e) {
configurableItem = (ConfigurableItem) loader.newInstance();
}
ConfigurationSection section = menu.getConfigurationSection("items." + itemType.name().toLowerCase(Locale.ROOT));
if (section != null) {
configurableItem.load(section);
menuOption.putItem(configurableItem);
itemsLoaded++;
}
}
// Load templates
for (TemplateType templateType : menuType.getTemplates()) {
Class<?> loader = templateType.getLoader();
ConfigurableTemplate configurableTemplate;
try {
configurableTemplate = (ConfigurableTemplate) loader.getConstructors()[0].newInstance(plugin);
} catch (IllegalArgumentException e) {
configurableTemplate = (ConfigurableTemplate) loader.newInstance();
}
ConfigurationSection section = menu.getConfigurationSection("templates." + templateType.name().toLowerCase(Locale.ROOT));
if (section != null) {
configurableTemplate.load(section);
menuOption.putTemplate(configurableTemplate);
templatesLoaded++;
}
}
menus.put(menuType, menuOption);
menusLoaded++;
}
}
long end = System.currentTimeMillis();
Bukkit.getLogger().info("[AureliumSkills] Loaded " + menusLoaded + " menus, " + itemsLoaded + " items, and " + templatesLoaded + " templates in " + (end - start) + " ms");
}
Aggregations