diff --git a/CommonCore/SQL/src/de/steamwar/sql/GameModeConfig.java b/CommonCore/SQL/src/de/steamwar/sql/GameModeConfig.java index 686470ff..906a9c87 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/GameModeConfig.java +++ b/CommonCore/SQL/src/de/steamwar/sql/GameModeConfig.java @@ -52,6 +52,10 @@ public final class GameModeConfig { private static final Map> byGameName; private static final Map> bySchematicType; + public static Collection> getAll() { + return (Collection) byFileName.values(); + } + public static GameModeConfig getByFileName(File file) { return (GameModeConfig) byFileName.get(file.getName()); } @@ -87,8 +91,24 @@ public final class GameModeConfig { byFileName = new HashMap<>(); byGameName = new HashMap<>(); bySchematicType = new HashMap<>(); - SchematicType.values(); DEFAULTS = SQLWrapper.impl.loadGameModeConfig(null); + init(); + } + + public static void init() { + byFileName.clear(); + byGameName.clear(); + bySchematicType.clear(); + + File folder = SQLWrapper.impl.getSchemTypesFolder(); + if (!folder.exists()) return; + if (!folder.isDirectory()) return; + + for (File file : Objects.requireNonNull(folder.listFiles())) { + if (!file.getName().endsWith(".yml")) continue; + if (file.getName().endsWith(".kits.yml")) continue; + SQLWrapper.impl.loadGameModeConfig(file); + } byFileName.values().forEach(gameModeConfig -> { List subTypes = Collections.unmodifiableList(gameModeConfig.Schematic.SubTypesStrings.stream() @@ -671,9 +691,9 @@ public final class GameModeConfig { loaded = loader.canLoad(); Size = new SizeConfig(loader.with("Size")); Inset = new InsetConfig(loader.with("Inset")); - Type = loader.getSchematicType("Type", "Normal"); + Type = null; SubTypesStrings = loader.getStringList("SubTypes"); - SubTypes = loader.getSchematicTypeList("SubTypes"); + SubTypes = new ArrayList<>(); Shortcut = loader.getString("Shortcut", ""); Material = loader.getMaterial("Material", "STONE_BUTTON"); ManualCheck = loader.getBoolean("ManualCheck", true); diff --git a/CommonCore/SQL/src/de/steamwar/sql/SchematicType.kt b/CommonCore/SQL/src/de/steamwar/sql/SchematicType.kt index b7f7d5be..d4abc36c 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/SchematicType.kt +++ b/CommonCore/SQL/src/de/steamwar/sql/SchematicType.kt @@ -19,11 +19,7 @@ package de.steamwar.sql -import java.io.File import java.util.* -import java.util.Locale -import java.util.Locale.getDefault -import java.util.stream.Collectors data class SchematicType( val name: String, @@ -47,58 +43,65 @@ data class SchematicType( @JvmField val Normal = SchematicType("Normal", "", Type.NORMAL, null, "STONE_BUTTON", false) - private val types: List - private val fromDB: Map? + private val types: MutableList = mutableListOf() + private val fromDB: MutableMap = mutableMapOf() init { - val tmpTypes = mutableListOf() - val tmpFromDB = mutableMapOf() - - tmpTypes.add(Normal) - tmpFromDB[Normal.toDB()] = Normal - - val folder = SQLWrapper.impl.schemTypesFolder - if (folder.exists()) { - for (configFile in Arrays.stream(folder.listFiles { _, name -> - name.endsWith( - ".yml" - ) && !name.endsWith(".kits.yml") - }).sorted().collect(Collectors.toList())) { - val gameModeConfig = SQLWrapper.impl.loadGameModeConfig(configFile) - if (gameModeConfig.Schematic.Type == null) continue - if (tmpFromDB.containsKey(gameModeConfig.Schematic.Type.toDB())) continue - val current = gameModeConfig.Schematic.Type - if (gameModeConfig.CheckQuestions.isNotEmpty()) { - val checkType = current.checkType - tmpTypes.add(checkType!!) - tmpFromDB[checkType.toDB()] = checkType - } - tmpTypes.add(current) - tmpFromDB[current.toDB()] = current - SQLWrapper.impl.processSchematicType(gameModeConfig) - } - } - - types = tmpTypes.toList() - fromDB = tmpFromDB.toMap() + GameModeConfig.init() + init() } @JvmStatic - fun values() = types + fun init() { + types.clear() + fromDB.clear() + + types.add(Normal) + fromDB[Normal.toDB()] = Normal + + for (gameModeConfig in GameModeConfig.getAll()) { + val type = gameModeConfig.Schematic.Type + ?: continue + if (fromDB.containsKey(type.toDB())) continue + + types.add(type) + fromDB[type.toDB()] = type + if (gameModeConfig.CheckQuestions.isNotEmpty() && type.checkType != null) { + types.add(type.checkType) + fromDB[type.checkType.toDB()] = type.checkType + } + } + } @JvmStatic - fun fromDB(value: String) = fromDB?.let { it[value.lowercase()] } + fun values() = + types + + @JvmStatic + fun fromDB(value: String) = + fromDB[value.lowercase()] } - fun name() = name - fun toDB() = name.lowercase() + fun name() = + name - fun check() = type == Type.CHECK_TYPE - fun fightType() = type == Type.FIGHT_TYPE - fun writeable() = type == Type.NORMAL + fun toDB() = + name.lowercase() - fun checkType() = if (manualCheck) checkType else this - fun isAssignable() = type == Type.NORMAL || (type == Type.FIGHT_TYPE && checkType != null) || !manualCheck + fun check() = + type == Type.CHECK_TYPE + + fun fightType() = + type == Type.FIGHT_TYPE + + fun writeable() = + type == Type.NORMAL + + fun checkType() = + if (manualCheck) checkType else this + + fun isAssignable() = + type == Type.NORMAL || (type == Type.FIGHT_TYPE && checkType != null) || !manualCheck enum class Type { NORMAL, diff --git a/VelocityCore/src/de/steamwar/velocitycore/ArenaMode.java b/VelocityCore/src/de/steamwar/velocitycore/ArenaMode.java index 9657e30c..1d66ec3a 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/ArenaMode.java +++ b/VelocityCore/src/de/steamwar/velocitycore/ArenaMode.java @@ -25,7 +25,10 @@ import lombok.Getter; import lombok.experimental.UtilityClass; import java.io.File; -import java.util.*; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; @UtilityClass public class ArenaMode { @@ -50,12 +53,12 @@ public class ArenaMode { if(!folder.exists()) return; - for(File file : Arrays.stream(folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml") && !name.equals("config.yml"))).sorted().toList()) { - GameModeConfig gameModeConfig = new GameModeConfig<>(file, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToInternalName, false); + GameModeConfig.init(); + SchematicType.init(); + for (GameModeConfig gameModeConfig : GameModeConfig.getAll()) { if (!gameModeConfig.Server.loaded) continue; - allModes.add(gameModeConfig); - byInternal.put(file.getName().replace(".yml", ""), gameModeConfig); + byInternal.put(gameModeConfig.configFile.getName().replace(".yml", ""), gameModeConfig); for (String name : gameModeConfig.Server.ChatNames) { byChat.put(name.toLowerCase(), gameModeConfig); }