diff --git a/CommonCore/Data/build.gradle.kts b/CommonCore/Data/build.gradle.kts index 75a22699..a8ffa845 100644 --- a/CommonCore/Data/build.gradle.kts +++ b/CommonCore/Data/build.gradle.kts @@ -22,7 +22,4 @@ plugins { } dependencies { - api(project(":CommonCore:SQL")) - - implementation("org.yaml:snakeyaml:2.2") } \ No newline at end of file diff --git a/CommonCore/SQL/build.gradle.kts b/CommonCore/SQL/build.gradle.kts index cbb8141a..dc171dde 100644 --- a/CommonCore/SQL/build.gradle.kts +++ b/CommonCore/SQL/build.gradle.kts @@ -23,4 +23,6 @@ plugins { dependencies { compileOnly(libs.sqlite) + + implementation("org.yaml:snakeyaml:2.2") } \ No newline at end of file diff --git a/CommonCore/Data/src/de/steamwar/data/GameModeConfig.java b/CommonCore/SQL/src/de/steamwar/data/GameModeConfig.java similarity index 100% rename from CommonCore/Data/src/de/steamwar/data/GameModeConfig.java rename to CommonCore/SQL/src/de/steamwar/data/GameModeConfig.java diff --git a/CommonCore/Data/src/de/steamwar/data/YMLWrapper.java b/CommonCore/SQL/src/de/steamwar/data/YMLWrapper.java similarity index 100% rename from CommonCore/Data/src/de/steamwar/data/YMLWrapper.java rename to CommonCore/SQL/src/de/steamwar/data/YMLWrapper.java diff --git a/CommonCore/SQL/src/de/steamwar/sql/SQLWrapper.java b/CommonCore/SQL/src/de/steamwar/sql/SQLWrapper.java index 2e0340ed..ac1424f0 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/SQLWrapper.java +++ b/CommonCore/SQL/src/de/steamwar/sql/SQLWrapper.java @@ -20,14 +20,17 @@ package de.steamwar.sql; import de.steamwar.ImplementationProvider; +import de.steamwar.data.GameModeConfig; -import java.util.List; -import java.util.Map; +import java.io.File; public interface SQLWrapper { SQLWrapper impl = ImplementationProvider.getImpl("de.steamwar.sql.SQLWrapperImpl"); - void loadSchemTypes(List tmpTypes, Map tmpFromDB); + File getSchemTypesFolder(); + + default void processSchematicType(GameModeConfig gameModeConfig, SchematicType type) { + } void additionalExceptionMetadata(StringBuilder builder); } diff --git a/CommonCore/SQL/src/de/steamwar/sql/SchematicType.java b/CommonCore/SQL/src/de/steamwar/sql/SchematicType.java index 53c75eff..3cab7f0a 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/SchematicType.java +++ b/CommonCore/SQL/src/de/steamwar/sql/SchematicType.java @@ -19,11 +19,14 @@ package de.steamwar.sql; +import de.steamwar.data.GameModeConfig; import de.steamwar.sql.internal.SqlTypeMapper; import lombok.Getter; import lombok.extern.slf4j.Slf4j; +import java.io.File; import java.util.*; +import java.util.stream.Collectors; @Slf4j public class SchematicType { @@ -41,7 +44,33 @@ public class SchematicType { tmpFromDB.put(Normal.name().toLowerCase(), Normal); long time = System.currentTimeMillis(); - SQLWrapper.impl.loadSchemTypes(tmpTypes, tmpFromDB); + File folder = SQLWrapper.impl.getSchemTypesFolder(); + if (folder.exists()) { + for (File configFile : Arrays.stream(folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))).sorted().collect(Collectors.toList())) { + GameModeConfig gameModeConfig = new GameModeConfig<>(configFile, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear); + if (!gameModeConfig.Schematic.loaded) continue; + String type = gameModeConfig.Schematic.Type; + assert type != null; + String shortcut = gameModeConfig.Schematic.Shortcut; + if (tmpFromDB.containsKey(type.toLowerCase())) + continue; + + SchematicType checktype = null; + String material = gameModeConfig.Schematic.Material; + + if (!gameModeConfig.CheckQuestions.isEmpty()) { + checktype = new SchematicType("C" + type, "C" + shortcut, SchematicType.Type.CHECK_TYPE, null, material, true); + tmpTypes.add(checktype); + tmpFromDB.put(checktype.toDB(), checktype); + } + + SchematicType current = new SchematicType(type, shortcut, gameModeConfig.Server.loaded ? SchematicType.Type.FIGHT_TYPE : SchematicType.Type.NORMAL, checktype, material, gameModeConfig.Deadline, gameModeConfig.Schematic.ManualCheck); + tmpTypes.add(current); + tmpFromDB.put(type.toLowerCase(), current); + + SQLWrapper.impl.processSchematicType(gameModeConfig, current); + } + } time = System.currentTimeMillis() - time; log.info("Loaded {} Schematic Types in {}ms", tmpTypes.size(), time); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SQLWrapperImpl.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SQLWrapperImpl.java index e25e4bb6..daf33a15 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SQLWrapperImpl.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SQLWrapperImpl.java @@ -20,45 +20,17 @@ package de.steamwar.sql; import de.steamwar.core.Core; -import de.steamwar.data.GameModeConfig; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.entity.Player; import java.io.File; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; public class SQLWrapperImpl implements SQLWrapper { @Override - public void loadSchemTypes(List tmpTypes, Map tmpFromDB) { - File folder = new File(Core.getInstance().getDataFolder().getParentFile(), "FightSystem"); - if (!folder.exists()) return; - for (File configFile : Arrays.stream(folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))).sorted().collect(Collectors.toList())) { - GameModeConfig gameModeConfig = new GameModeConfig<>(configFile, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear); - if (!gameModeConfig.Schematic.loaded) continue; - String type = gameModeConfig.Schematic.Type; - assert type != null; - String shortcut = gameModeConfig.Schematic.Shortcut; - if (tmpFromDB.containsKey(type.toLowerCase())) - continue; - - SchematicType checktype = null; - String material = gameModeConfig.Schematic.Material; - - if (!gameModeConfig.CheckQuestions.isEmpty()) { - checktype = new SchematicType("C" + type, "C" + shortcut, SchematicType.Type.CHECK_TYPE, null, material, true); - tmpTypes.add(checktype); - tmpFromDB.put(checktype.toDB(), checktype); - } - - SchematicType current = new SchematicType(type, shortcut, gameModeConfig.Server.loaded ? SchematicType.Type.FIGHT_TYPE : SchematicType.Type.NORMAL, checktype, material, gameModeConfig.Deadline, gameModeConfig.Schematic.ManualCheck); - tmpTypes.add(current); - tmpFromDB.put(type.toLowerCase(), current); - } + public File getSchemTypesFolder() { + return new File(Core.getInstance().getDataFolder().getParentFile(), "FightSystem"); } private static final String SERVER_VERSION = Bukkit.getServer().getVersion(); diff --git a/VelocityCore/src/de/steamwar/sql/SQLWrapperImpl.java b/VelocityCore/src/de/steamwar/sql/SQLWrapperImpl.java index 156c45e9..73a1d393 100644 --- a/VelocityCore/src/de/steamwar/sql/SQLWrapperImpl.java +++ b/VelocityCore/src/de/steamwar/sql/SQLWrapperImpl.java @@ -26,39 +26,21 @@ import de.steamwar.velocitycore.VelocityCore; import de.steamwar.velocitycore.commands.CheckCommand; import java.io.File; -import java.util.Arrays; -import java.util.List; -import java.util.Map; public class SQLWrapperImpl implements SQLWrapper { @Override - public void loadSchemTypes(List tmpTypes, Map tmpFromDB) { - File folder = new File(VelocityCore.get().getDataDirectory().getParent().toFile(), "FightSystem"); - if(!folder.exists()) - return; + public File getSchemTypesFolder() { + return new File(VelocityCore.get().getDataDirectory().getParent().toFile(), "FightSystem"); + } - for(File file : Arrays.stream(folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))).sorted().toList()) { - GameModeConfig gameModeConfig = new GameModeConfig<>(file, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToInternalName); - if (!gameModeConfig.Schematic.loaded) continue; - if (tmpFromDB.containsKey(gameModeConfig.Schematic.Type.toLowerCase())) continue; - - String shortcut = gameModeConfig.Schematic.Shortcut; - String material = gameModeConfig.Schematic.Material; - - SchematicType checktype = null; - if (!gameModeConfig.CheckQuestions.isEmpty()) { - checktype = new SchematicType("C" + gameModeConfig.Schematic.Type, "C" + shortcut, SchematicType.Type.CHECK_TYPE, null, material, true); - tmpTypes.add(checktype); - tmpFromDB.put(checktype.toDB(), checktype); - CheckCommand.setCheckQuestions(checktype, gameModeConfig.CheckQuestions); - } - - SchematicType current = new SchematicType(gameModeConfig.Schematic.Type, shortcut, gameModeConfig.Server.loaded ? SchematicType.Type.FIGHT_TYPE : SchematicType.Type.NORMAL, checktype, material, gameModeConfig.Deadline, gameModeConfig.Schematic.ManualCheck); - tmpTypes.add(current); - tmpFromDB.put(gameModeConfig.Schematic.Type.toLowerCase(), current); - if(checktype != null) - CheckCommand.addFightType(checktype, current); + @Override + public void processSchematicType(GameModeConfig gameModeConfig, SchematicType type) { + if (!gameModeConfig.CheckQuestions.isEmpty()) { + CheckCommand.setCheckQuestions(type.checkType(), gameModeConfig.CheckQuestions); + } + if (type.checkType() != null) { + CheckCommand.addFightType(type.checkType(), type); } } diff --git a/WebsiteBackend/src/de/steamwar/sql/SQLWrapperImpl.kt b/WebsiteBackend/src/de/steamwar/sql/SQLWrapperImpl.kt index f00c4dbd..be7ef20b 100644 --- a/WebsiteBackend/src/de/steamwar/sql/SQLWrapperImpl.kt +++ b/WebsiteBackend/src/de/steamwar/sql/SQLWrapperImpl.kt @@ -19,42 +19,12 @@ package de.steamwar.sql -import de.steamwar.data.GameModeConfig import java.io.File -import java.util.* -import java.util.stream.Collectors - -fun loadSchematicTypes(tmpTypes: MutableList?, tmpFromDB: MutableMap?) { - val folder = File("/configs/GameModes") - if (folder.exists()) { - for (configFile in Arrays.stream(folder.listFiles { _, name -> name.endsWith(".yml") && !name.endsWith(".kits.yml") }) - .sorted().collect(Collectors.toList())) { - val gameModeConfig = GameModeConfig(configFile, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear) - - if (!gameModeConfig.Schematic.loaded) continue - val type = gameModeConfig.Schematic.Type - checkNotNull(type) - val shortcut = gameModeConfig.Schematic.Shortcut - if (tmpFromDB!!.containsKey(type.lowercase(Locale.getDefault()))) continue - - var checktype: SchematicType? = null - val material = gameModeConfig.Schematic.Material - - if (!gameModeConfig.CheckQuestions.isEmpty()) { - checktype = SchematicType("C" + type, "C" + shortcut, SchematicType.Type.CHECK_TYPE, null, material, true) - tmpTypes!!.add(checktype) - tmpFromDB.put(checktype.toDB(), checktype) - } - - val current = SchematicType(type, shortcut, if (gameModeConfig.Server.loaded) SchematicType.Type.FIGHT_TYPE else SchematicType.Type.NORMAL, checktype, material, gameModeConfig.Deadline, gameModeConfig.Schematic.ManualCheck) - tmpTypes!!.add(current) - tmpFromDB.put(type.lowercase(Locale.getDefault()), current) - } - } -} class SQLWrapperImpl: SQLWrapper { - override fun loadSchemTypes(tmpTypes: MutableList?, tmpFromDB: MutableMap?) = loadSchematicTypes(tmpTypes, tmpFromDB) + override fun getSchemTypesFolder(): File? { + return File("/configs/GameModes") + } override fun additionalExceptionMetadata(builder: StringBuilder) { builder.append("\n\nWebsiteApi")