package me.unurled.raxen.config; import java.io.File; import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import me.unurled.raxen.Raxen; import me.unurled.raxen.components.glyph.GlyphBuilder; import me.unurled.raxen.components.glyph.GlyphParser; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; public class GlyphConfig { private Raxen main; private File glyphFolder; public GlyphConfig(Raxen main) { this.main = main; validatesConfig(); } public void validatesConfig() { glyphFolder = new File(main.getDataFolder(), "items"); if (!glyphFolder.exists()) { glyphFolder.mkdirs(); } } public Map> parseGlyphConfigs() { Map> parseMap = new LinkedHashMap<>(); List config = Arrays.stream(getGlyphFiles()) .filter(file -> file.getName().endsWith(".yml")) .toList(); for (File file : config) { parseMap.put(file, parseGlyphConfig(YamlConfiguration.loadConfiguration(file), file)); } return parseMap; } public Map parseGlyphConfig(YamlConfiguration config, File file) { Map parseMap = new LinkedHashMap<>(); for (String glyphSelection : config.getKeys(false)) { if (!config.isConfigurationSection(glyphSelection)) { continue; } ConfigurationSection glyphSection = config.getConfigurationSection(glyphSelection); parseMap.put(glyphSelection, new GlyphParser(glyphSection)); } boolean configUpdated = false; Map map = new LinkedHashMap<>(); for (Map.Entry entry : parseMap.entrySet()) { GlyphParser parser = entry.getValue(); try { map.put(entry.getKey(), parser.buildGlyph()); } catch (Exception e) { e.printStackTrace(); } } return map; } private File[] getGlyphFiles() { if (!glyphFolder.exists()) { glyphFolder.mkdirs(); return new File[0]; } File[] itemConfigs = Arrays.stream(glyphFolder.listFiles()).filter(File::isFile) .toArray(File[]::new); Arrays.sort(itemConfigs); return itemConfigs; } }