Search in sources :

Example 1 with TemplateType

use of com.archyx.aureliumskills.menu.templates.TemplateType 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");
}
Also used : ConfigurableItem(com.archyx.aureliumskills.menu.items.ConfigurableItem) ConfigurableTemplate(com.archyx.aureliumskills.menu.templates.ConfigurableTemplate) ItemType(com.archyx.aureliumskills.menu.items.ItemType) TemplateType(com.archyx.aureliumskills.menu.templates.TemplateType) FileConfiguration(org.bukkit.configuration.file.FileConfiguration) ItemStack(org.bukkit.inventory.ItemStack) File(java.io.File) ItemMeta(org.bukkit.inventory.meta.ItemMeta) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Aggregations

ConfigurableItem (com.archyx.aureliumskills.menu.items.ConfigurableItem)1 ItemType (com.archyx.aureliumskills.menu.items.ItemType)1 ConfigurableTemplate (com.archyx.aureliumskills.menu.templates.ConfigurableTemplate)1 TemplateType (com.archyx.aureliumskills.menu.templates.TemplateType)1 File (java.io.File)1 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)1 FileConfiguration (org.bukkit.configuration.file.FileConfiguration)1 ItemStack (org.bukkit.inventory.ItemStack)1 ItemMeta (org.bukkit.inventory.meta.ItemMeta)1