SteamWar/SpigotCore
Archiviert
13
0

New config #128

Zusammengeführt
Lixfel hat 2 Commits von configRefactoring nach master 2021-12-02 14:33:07 +01:00 zusammengeführt
Nur Änderungen aus Commit 05cd8fd648 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -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<String, SchematicType> fromDB;
private static final List<SchematicType> 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<SchematicType> tmpTypes = new LinkedList<>();
Map<String, SchematicType> 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;