Fix GameModeConfig.Schematic.SubTypes

This commit is contained in:
2025-11-10 11:31:59 +01:00
parent 1c076b5bbf
commit a8c98594a9
2 changed files with 20 additions and 1 deletions
@@ -71,11 +71,15 @@ public final class GameModeConfig<M, W> {
} }
private static final Field Schematic_TypeField; private static final Field Schematic_TypeField;
private static final Field Schematic_SubTypesField;
static { static {
try { try {
Schematic_TypeField = SchematicConfig.class.getDeclaredField("Type"); Schematic_TypeField = SchematicConfig.class.getDeclaredField("Type");
Schematic_TypeField.setAccessible(true); Schematic_TypeField.setAccessible(true);
Schematic_SubTypesField = SchematicConfig.class.getDeclaredField("SubTypes");
Schematic_SubTypesField.setAccessible(true);
} catch (NoSuchFieldException e) { } catch (NoSuchFieldException e) {
throw new SecurityException(e.getMessage(), e); throw new SecurityException(e.getMessage(), e);
} }
@@ -85,6 +89,18 @@ public final class GameModeConfig<M, W> {
bySchematicType = new HashMap<>(); bySchematicType = new HashMap<>();
SchematicType.values(); SchematicType.values();
DEFAULTS = SQLWrapper.impl.loadGameModeConfig(null); DEFAULTS = SQLWrapper.impl.loadGameModeConfig(null);
byFileName.values().forEach(gameModeConfig -> {
List<SchematicType> subTypes = Collections.unmodifiableList(gameModeConfig.Schematic.SubTypesStrings.stream()
.map(SchematicType::fromDB)
.filter(Objects::nonNull)
.collect(Collectors.toList()));
try {
Schematic_SubTypesField.set(gameModeConfig.Schematic, subTypes);
} catch (IllegalAccessException e) {
throw new SecurityException(e.getMessage(), e);
}
});
} }
public final boolean loaded; public final boolean loaded;
@@ -524,6 +540,8 @@ public final class GameModeConfig<M, W> {
*/ */
public final SchematicType Type; public final SchematicType Type;
private final List<String> SubTypesStrings;
/** /**
* The schematic types that are also allowed to be chosen in this arena * The schematic types that are also allowed to be chosen in this arena
*/ */
@@ -631,6 +649,7 @@ public final class GameModeConfig<M, W> {
Size = new SizeConfig(loader.with("Size")); Size = new SizeConfig(loader.with("Size"));
Inset = new InsetConfig(loader.with("Inset")); Inset = new InsetConfig(loader.with("Inset"));
Type = loader.getSchematicType("Type", "Normal"); Type = loader.getSchematicType("Type", "Normal");
SubTypesStrings = loader.getStringList("SubTypes");
SubTypes = loader.getSchematicTypeList("SubTypes"); SubTypes = loader.getSchematicTypeList("SubTypes");
Shortcut = loader.getString("Shortcut", ""); Shortcut = loader.getString("Shortcut", "");
Material = loader.getMaterial("Material", "STONE_BUTTON"); Material = loader.getMaterial("Material", "STONE_BUTTON");
@@ -139,7 +139,7 @@ final class YMLWrapper<M, W> {
if (list.isEmpty()) { if (list.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} else { } else {
return Collections.unmodifiableList(list.stream().map(SchematicType::fromDB).collect(Collectors.toList())); return Collections.unmodifiableList(list.stream().map(SchematicType::fromDB).filter(Objects::nonNull).collect(Collectors.toList()));
} }
} }