Hotfix static initialisation of GameModeConfig

This commit is contained in:
2025-10-26 18:14:52 +01:00
parent b3f6312288
commit d7fb7c2a61
@@ -40,9 +40,9 @@ public final class GameModeConfig<M, W> {
public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yyyy HH:mm"); public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yyyy HH:mm");
private static final Random random = new Random(); private static final Random random = new Random();
private static final Map<String, GameModeConfig<?, String>> byFileName = new HashMap<>(); private static final Map<String, GameModeConfig<?, String>> byFileName;
private static final Map<String, GameModeConfig<?, String>> byGameName = new HashMap<>(); private static final Map<String, GameModeConfig<?, String>> byGameName;
private static final Map<SchematicType, GameModeConfig<?, String>> bySchematicType = new HashMap<>(); private static final Map<SchematicType, GameModeConfig<?, String>> bySchematicType;
public static <M> GameModeConfig<M, String> getByFileName(File file) { public static <M> GameModeConfig<M, String> getByFileName(File file) {
return (GameModeConfig<M, String>) byFileName.get(file.getName()); return (GameModeConfig<M, String>) byFileName.get(file.getName());
@@ -56,16 +56,20 @@ public final class GameModeConfig<M, W> {
return (GameModeConfig<M, String>) bySchematicType.get(schematicType); return (GameModeConfig<M, String>) bySchematicType.get(schematicType);
} }
static { private static final GameModeConfig<?, String> DEFAULTS;
SchematicType.values();
}
private static final GameModeConfig<?, String> DEFAULTS = SQLWrapper.impl.loadGameModeConfig(null);
public static <M> GameModeConfig<M, String> getDefaults() { public static <M> GameModeConfig<M, String> getDefaults() {
return (GameModeConfig<M, String>) DEFAULTS; return (GameModeConfig<M, String>) DEFAULTS;
} }
static {
byFileName = new HashMap<>();
byGameName = new HashMap<>();
bySchematicType = new HashMap<>();
SchematicType.values();
DEFAULTS = SQLWrapper.impl.loadGameModeConfig(null);
}
public final boolean loaded; public final boolean loaded;
public final File configFile; public final File configFile;
@@ -208,15 +212,13 @@ public final class GameModeConfig<M, W> {
Arena = new ArenaConfig(loader.with("Arena"), Schematic.Size, EnterStages); Arena = new ArenaConfig(loader.with("Arena"), Schematic.Size, EnterStages);
if (cacheInstance) { if (cacheInstance && file != null) {
if (configFile != null) { byFileName.put(configFile.getName(), (GameModeConfig) this);
byFileName.put(configFile.getName(), (GameModeConfig) this);
}
byGameName.put(GameName, (GameModeConfig) this); byGameName.put(GameName, (GameModeConfig) this);
} }
if (Schematic.Type != null) { if (Schematic.Type != null) {
if (cacheInstance) { if (cacheInstance && file != null) {
bySchematicType.put(Schematic.Type, (GameModeConfig) this); bySchematicType.put(Schematic.Type, (GameModeConfig) this);
if (Schematic.Type.checkType() != null) { if (Schematic.Type.checkType() != null) {
bySchematicType.put(Schematic.Type.checkType(), (GameModeConfig) this); bySchematicType.put(Schematic.Type.checkType(), (GameModeConfig) this);
@@ -239,7 +241,7 @@ public final class GameModeConfig<M, W> {
try { try {
Schematic_TypeField.set(Schematic, current); Schematic_TypeField.set(Schematic, current);
if (cacheInstance) { if (cacheInstance && file != null) {
bySchematicType.put(Schematic.Type, (GameModeConfig) this); bySchematicType.put(Schematic.Type, (GameModeConfig) this);
if (Schematic.Type.checkType() != null) { if (Schematic.Type.checkType() != null) {
bySchematicType.put(Schematic.Type.checkType(), (GameModeConfig) this); bySchematicType.put(Schematic.Type.checkType(), (GameModeConfig) this);