From 05cd8fd6486aa9b80a8d99c93a2baf589daa3acb Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 12 Nov 2021 14:57:12 +0100 Subject: [PATCH] New config --- .../src/de/steamwar/sql/SchematicType.java | 43 ++++++++++++------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/SchematicType.java b/SpigotCore_Main/src/de/steamwar/sql/SchematicType.java index 569727b..6914f4c 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SchematicType.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SchematicType.java @@ -20,7 +20,6 @@ package de.steamwar.sql; import de.steamwar.core.Core; -import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; import java.io.File; @@ -32,13 +31,8 @@ public class SchematicType { private static final Map fromDB; private static final List types; - static{ - File file = new File(Core.getInstance().getDataFolder(), "SchematicTypes.yml"); - - if(!file.exists()) - throw new SecurityException("SchematicType-ConfigFile not found!"); - - YamlConfiguration config = YamlConfiguration.loadConfiguration(file); + static { + File folder = new File(Core.getInstance().getDataFolder().getParentFile(), "FightSystem"); List tmpTypes = new LinkedList<>(); Map tmpFromDB = new HashMap<>(); @@ -46,13 +40,30 @@ public class SchematicType { tmpTypes.add(Normal); tmpFromDB.put(Normal.name().toLowerCase(), Normal); - for(String type : config.getKeys(false)){ - ConfigurationSection section = config.getConfigurationSection(type); - assert section != null; - String checktype = section.getString("checktype"); - SchematicType current = new SchematicType(type, section.getString("kuerzel"), Type.valueOf(section.getString("type")), checktype != null ? tmpFromDB.get(checktype.toLowerCase()) : null); - tmpTypes.add(current); - tmpFromDB.put(type.toLowerCase(), current); + if(folder.exists()) { + for(File configFile : folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))) { + YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile); + if(!config.isConfigurationSection("Schematic")) + continue; + + String type = config.getString("Schematic.Type"); + assert type != null; + String shortcut = config.getString("Schematic.Shortcut"); + if(tmpFromDB.containsKey(type.toLowerCase())) + continue; + + SchematicType checktype = null; + + if(!config.getStringList("CheckQuestions").isEmpty()) { + checktype = new SchematicType("C" + type, "C" + shortcut, Type.CHECK_TYPE, null); + tmpTypes.add(checktype); + tmpFromDB.put(checktype.toDB(), checktype); + } + + SchematicType current = new SchematicType(type, shortcut, config.isConfigurationSection("Server") ? Type.FIGHT_TYPE : Type.NORMAL, checktype); + tmpTypes.add(current); + tmpFromDB.put(type.toLowerCase(), current); + } } fromDB = Collections.unmodifiableMap(tmpFromDB); @@ -62,7 +73,7 @@ public class SchematicType { private final String name; private final String kuerzel; private final Type type; - private SchematicType checkType; + private final SchematicType checkType; private SchematicType(String name, String kuerzel, Type type, SchematicType checkType){ this.name = name;