Unify SchematicType loading

This commit is contained in:
2025-10-26 09:36:44 +01:00
parent ef81626e02
commit 167a6b6dc4
9 changed files with 53 additions and 98 deletions
@@ -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<SchematicType> tmpTypes, Map<String, SchematicType> tmpFromDB);
File getSchemTypesFolder();
default void processSchematicType(GameModeConfig<String, String, String> gameModeConfig, SchematicType type) {
}
void additionalExceptionMetadata(StringBuilder builder);
}
@@ -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<String, String, String> 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);