diff --git a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/FixedGlobalRegion.java b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/FixedGlobalRegion.java index 1edc4787..af08c4ae 100644 --- a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/FixedGlobalRegion.java +++ b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/FixedGlobalRegion.java @@ -23,7 +23,8 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard; import de.steamwar.bausystem.region.*; import de.steamwar.bausystem.utils.PasteBuilder; import de.steamwar.data.GameModeConfig; -import de.steamwar.data.YMLWrapperImpl; +import de.steamwar.data.YMLWrapper; +import de.steamwar.data.YMLWrapperUtils; import de.steamwar.sql.SchematicType; import lombok.NonNull; import lombok.Setter; @@ -94,7 +95,7 @@ public final class FixedGlobalRegion implements Region { } }; - private static final GameModeConfig GLOBAL_CONFIG = new GameModeConfig<>(YMLWrapperImpl.ofTyped(null)); + private static final GameModeConfig GLOBAL_CONFIG = new GameModeConfig<>(null, YMLWrapperUtils.ToMaterial, YMLWrapper.ToSchematicType, YMLWrapper.ToString, YMLWrapper.ToStaticWarGear); private FixedGlobalRegion() { } diff --git a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/FixedRegion.java b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/FixedRegion.java index 69d7b9d0..399c5aba 100644 --- a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/FixedRegion.java +++ b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/FixedRegion.java @@ -29,7 +29,8 @@ import de.steamwar.bausystem.utils.PasteBuilder; import de.steamwar.bausystem.worlddata.WorldData; import de.steamwar.core.Core; import de.steamwar.data.GameModeConfig; -import de.steamwar.data.YMLWrapperImpl; +import de.steamwar.data.YMLWrapper; +import de.steamwar.data.YMLWrapperUtils; import de.steamwar.sql.SchematicType; import lombok.NonNull; import org.bukkit.Bukkit; @@ -339,7 +340,7 @@ public class FixedRegion implements Region { break; } } - this.gameModeConfig = new GameModeConfig<>(YMLWrapperImpl.ofTyped(found)); + this.gameModeConfig = new GameModeConfig<>(found, YMLWrapperUtils.ToMaterial, YMLWrapper.ToSchematicType, YMLWrapper.ToString, YMLWrapper.ToStaticWarGear); this.regionData = new RegionData.RegionDataImpl(regionData, WorldData::write); } diff --git a/CommonCore/Data/build.gradle.kts b/CommonCore/Data/build.gradle.kts index b458588b..75a22699 100644 --- a/CommonCore/Data/build.gradle.kts +++ b/CommonCore/Data/build.gradle.kts @@ -23,4 +23,6 @@ plugins { dependencies { api(project(":CommonCore:SQL")) + + 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/Data/src/de/steamwar/data/GameModeConfig.java index d68fddcd..ed405522 100644 --- a/CommonCore/Data/src/de/steamwar/data/GameModeConfig.java +++ b/CommonCore/Data/src/de/steamwar/data/GameModeConfig.java @@ -28,6 +28,7 @@ import java.text.SimpleDateFormat; import java.time.Instant; import java.time.LocalDateTime; import java.util.*; +import java.util.function.Function; import java.util.stream.Collectors; @ToString @@ -94,8 +95,10 @@ public final class GameModeConfig { public final List EnterStages; public final Techhider Techhider; - public GameModeConfig(YMLWrapper loader) { - configFile = loader.getFile(); + public GameModeConfig(File file, Function materialMapper, Function schematicTypeMapper, Function winconditionMapper, Function defaultGameName) { + YMLWrapper loader = new YMLWrapper<>(file, materialMapper, schematicTypeMapper, winconditionMapper); + + configFile = file; loaded = loader.canLoad(); Server = new Server(loader.with("Server")); @@ -116,7 +119,7 @@ public final class GameModeConfig { Times = new Times(loader.with("Times")); // Arena would be here to be in config order but needs Schematic.Size and EnterStages loaded afterwards Schematic = new Schematic<>(loader.with("Schematic")); - GameName = loader.getString("GameName", loader.getDefaultGameName()); + GameName = loader.getString("GameName", defaultGameName.apply(file)); ActiveMonths = loader.getIntList("ActiveMonths"); TeamChatPrefix = loader.getString("TeamChatPrefix", "+"); Blue = new Blue(loader.with("Blue")); diff --git a/CommonCore/Data/src/de/steamwar/data/YMLWrapper.java b/CommonCore/Data/src/de/steamwar/data/YMLWrapper.java index c7813b12..644a8c13 100644 --- a/CommonCore/Data/src/de/steamwar/data/YMLWrapper.java +++ b/CommonCore/Data/src/de/steamwar/data/YMLWrapper.java @@ -20,8 +20,11 @@ package de.steamwar.data; import de.steamwar.sql.SchematicType; +import org.yaml.snakeyaml.Yaml; import java.io.File; +import java.io.FileReader; +import java.io.IOException; import java.util.Collections; import java.util.List; import java.util.Map; @@ -29,34 +32,75 @@ import java.util.Objects; import java.util.function.Function; import java.util.stream.Collectors; -public abstract class YMLWrapper { +public final class YMLWrapper { public static final Function ToString = Function.identity(); public static final Function ToSchematicType = SchematicType::fromDB; - protected final File file; - public final Function materialMapper; - public final Function schematicTypeMapper; - public final Function winconditionMapper; + public static final Function ToStaticWarGear = __ -> "WarGear"; + public static final Function ToInternalName = file -> file.getName().replace(".yml", ""); - protected YMLWrapper(File file, Function materialMapper, Function schematicTypeMapper, Function winconditionMapper) { + private final File file; + final Function materialMapper; + final Function schematicTypeMapper; + final Function winconditionMapper; + + private final boolean canLoad; + private final Map document; + + public YMLWrapper(File file, Function materialMapper, Function schematicTypeMapper, Function winconditionMapper) { this.file = file; this.materialMapper = materialMapper; this.schematicTypeMapper = schematicTypeMapper; this.winconditionMapper = winconditionMapper; + + Yaml yaml = new Yaml(); + Map document = Collections.emptyMap(); + boolean canLoad = false; + if (file != null && file.exists() && file.isFile()) { + try { + document = yaml.load(new FileReader(file)); + canLoad = true; + } catch (IOException e) { + // Ignore + } + } + this.document = document; + this.canLoad = canLoad; } - public final File getFile() { - return file; + private YMLWrapper(boolean canLoad, Map document, Function materialMapper, Function schematicTypeMapper, Function winconditionMapper) { + this.file = null; + this.materialMapper = materialMapper; + this.schematicTypeMapper = schematicTypeMapper; + this.winconditionMapper = winconditionMapper; + this.canLoad = canLoad; + this.document = document; } - public abstract boolean canLoad(); + public boolean canLoad() { + return canLoad; + } - public abstract YMLWrapper with(String path); + public YMLWrapper with(String path) { + if (document.containsKey(path)) { + Object value = document.get(path); + if (value instanceof Map) { + return new YMLWrapper<>(true, (Map) value, materialMapper, schematicTypeMapper, winconditionMapper); + } + } + return new YMLWrapper<>(false, Collections.emptyMap(), materialMapper, schematicTypeMapper, winconditionMapper); + } - public abstract String getDefaultGameName(); - - public abstract T get(String path, T defaultValue, Function mapper); + public T get(String path, T defaultValue, Function mapper) { + Object value = this.document.get(path); + if (value == null) return defaultValue; + try { + return mapper.apply(value); + } catch (ClassCastException e) { + return defaultValue; + } + } public String getString(String path, String defaultValue) { return get(path, defaultValue, Objects::toString); @@ -74,16 +118,24 @@ public abstract class YMLWrapper { return get(path, defaultValue, Boolean.class::cast); } - public final ST getSchematicType(String path, String defaultValue) { + public ST getSchematicType(String path, String defaultValue) { String schematicType = getString(path, defaultValue); return schematicTypeMapper.apply(schematicType); } - public final M getMaterial(String path, String defaultValue) { + public M getMaterial(String path, String defaultValue) { return materialMapper.apply(getString(path, defaultValue).toUpperCase()); } - public abstract List get(String path, Function> mapper); + public List get(String path, Function> mapper) { + Object value = this.document.get(path); + if (value == null) return Collections.emptyList(); + try { + return Collections.unmodifiableList(mapper.apply(value)); + } catch (ClassCastException e) { + return Collections.emptyList(); + } + } public List getStringList(String path) { return get(path, o -> (List) o); @@ -93,7 +145,7 @@ public abstract class YMLWrapper { return get(path, o -> (List) o); } - public final List getSchematicTypeList(String path) { + public List getSchematicTypeList(String path) { List list = getStringList(path); if (list.isEmpty()) { return Collections.emptyList(); @@ -102,7 +154,7 @@ public abstract class YMLWrapper { } } - public final List getMaterialList(String path) { + public List getMaterialList(String path) { List list = getStringList(path); if (list.isEmpty()) { return Collections.emptyList(); @@ -111,5 +163,12 @@ public abstract class YMLWrapper { } } - public abstract List> getMapList(String path); + public List> getMapList(String path) { + Object value = this.document.get(path); + if (value instanceof List) { + return Collections.unmodifiableList((List>) value); + } else { + return Collections.emptyList(); + } + } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java index 57c556ed..f8e18d4f 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java @@ -20,7 +20,8 @@ package de.steamwar.fightsystem; import de.steamwar.data.GameModeConfig; -import de.steamwar.data.YMLWrapperImpl; +import de.steamwar.data.YMLWrapper; +import de.steamwar.data.YMLWrapperUtils; import de.steamwar.fightsystem.utils.Region; import de.steamwar.fightsystem.winconditions.Winconditions; import de.steamwar.sql.*; @@ -109,7 +110,7 @@ public class Config { Bukkit.getLogger().log(Level.SEVERE, "Arenaconfig fehlt!"); Bukkit.shutdown(); } - GameModeConfig = new GameModeConfig<>(YMLWrapperImpl.ofTyped(new File(FightSystem.getPlugin().getDataFolder(), configFile), Winconditions::valueOf)); + GameModeConfig = new GameModeConfig<>(new File(FightSystem.getPlugin().getDataFolder(), configFile), YMLWrapperUtils.ToMaterial, YMLWrapper.ToSchematicType, Winconditions::valueOf, YMLWrapper.ToStaticWarGear); File worldConfigFile = new File(world.getWorldFolder(), "config.yml"); if(!worldConfigFile.exists()) { diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemTypeManager.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemTypeManager.java index f881ce51..48bd8859 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemTypeManager.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemTypeManager.java @@ -20,7 +20,8 @@ package de.steamwar.schematicsystem; import de.steamwar.data.GameModeConfig; -import de.steamwar.data.YMLWrapperImpl; +import de.steamwar.data.YMLWrapper; +import de.steamwar.data.YMLWrapperUtils; import de.steamwar.sql.SchematicType; import lombok.experimental.UtilityClass; import org.bukkit.Material; @@ -38,7 +39,7 @@ public class CheckSchemTypeManager { File folder = new File(SchematicSystem.getInstance().getDataFolder().getParentFile(), "FightSystem"); if(folder.exists()) { for(File configFile : folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))) { - GameModeConfig gameModeConfig = new GameModeConfig<>(YMLWrapperImpl.ofTyped(configFile)); + GameModeConfig gameModeConfig = new GameModeConfig<>(configFile, YMLWrapperUtils.ToMaterial, YMLWrapper.ToSchematicType, YMLWrapper.ToString, YMLWrapper.ToStaticWarGear); if (gameModeConfig.CheckQuestions.isEmpty() && gameModeConfig.Schematic.ManualCheck) continue; types.put(gameModeConfig.Schematic.Type, gameModeConfig); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/data/YMLWrapperImpl.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/data/YMLWrapperImpl.java deleted file mode 100644 index 55b749bb..00000000 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/data/YMLWrapperImpl.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2025 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.data; - -import de.steamwar.sql.SchematicType; -import org.bukkit.Material; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; - -import java.io.File; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.function.Function; - -public class YMLWrapperImpl extends YMLWrapper { - - public static YMLWrapperImpl ofTyped(File file) { - return new YMLWrapperImpl<>(file, ToMaterial, ToSchematicType, ToString); - } - - public static YMLWrapperImpl ofTyped(File file, Function ToWincondtion) { - return new YMLWrapperImpl<>(file, ToMaterial, ToSchematicType, ToWincondtion); - } - - public static YMLWrapperImpl ofRaw(File file) { - return new YMLWrapperImpl<>(file, ToString, ToString, ToString); - } - - public static final Function ToMaterial = material -> { - Material mat = Material.getMaterial(material); - if (mat == null) { - try { - mat = Material.valueOf(material); - } catch (IllegalArgumentException e) { - // Ignore - } - } - return mat; - }; - - private final FileConfiguration config; - private final String pathPrefix; - - private YMLWrapperImpl(File file, Function materialMapper, Function schematicTypeMapper, Function winconditionMapper) { - super(file, materialMapper, schematicTypeMapper, winconditionMapper); - if (file == null || !file.exists()) { - config = null; - pathPrefix = ""; - } else { - config = YamlConfiguration.loadConfiguration(file); - pathPrefix = ""; - } - } - - private YMLWrapperImpl(FileConfiguration config, String pathPrefix, Function materialMapper, Function schematicTypeMapper, Function winconditionMapper) { - super(null, materialMapper, schematicTypeMapper, winconditionMapper); - this.config = config; - this.pathPrefix = pathPrefix; - } - - @Override - public boolean canLoad() { - return config != null; - } - - @Override - public YMLWrapper with(String path) { - if (pathPrefix.isEmpty()) { - path = path + "."; - } else { - path = pathPrefix + path + "."; - } - if (config != null && config.isConfigurationSection(path)) { - return new YMLWrapperImpl<>(this.config, path, materialMapper, schematicTypeMapper, winconditionMapper); - } else { - return new YMLWrapperImpl<>(null, path, materialMapper, schematicTypeMapper, winconditionMapper); - } - } - - @Override - public String getDefaultGameName() { - return "WarGear"; - } - - @Override - public T get(String path, T defaultValue, Function mapper) { - if (config == null) return defaultValue; - try { - return mapper.apply(config.get(path, defaultValue)); - } catch (ClassCastException e) { - return defaultValue; - } - } - - @Override - public List get(String path, Function> mapper) { - if (config == null) return Collections.emptyList(); - List list = config.getList(pathPrefix + path); - if (list == null || list.isEmpty()) { - return Collections.emptyList(); - } - try { - return Collections.unmodifiableList(mapper.apply(list)); - } catch (ClassCastException e) { - return Collections.emptyList(); - } - } - - @Override - public List> getMapList(String path) { - if (config == null) return Collections.emptyList(); - return config.getMapList(pathPrefix + path); - } -} diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/data/YMLWrapperUtils.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/data/YMLWrapperUtils.java new file mode 100644 index 00000000..15433cfc --- /dev/null +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/data/YMLWrapperUtils.java @@ -0,0 +1,41 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2025 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.data; + +import lombok.experimental.UtilityClass; +import org.bukkit.Material; + +import java.util.function.Function; + +@UtilityClass +public class YMLWrapperUtils { + + public static final Function ToMaterial = material -> { + Material mat = Material.getMaterial(material); + if (mat == null) { + try { + mat = Material.valueOf(material); + } catch (IllegalArgumentException e) { + // Ignore + } + } + return mat; + }; +} diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SQLWrapperImpl.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SQLWrapperImpl.java index 2d11fdec..340daf47 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SQLWrapperImpl.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SQLWrapperImpl.java @@ -21,7 +21,7 @@ package de.steamwar.sql; import de.steamwar.core.Core; import de.steamwar.data.GameModeConfig; -import de.steamwar.data.YMLWrapperImpl; +import de.steamwar.data.YMLWrapper; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.entity.Player; @@ -39,7 +39,7 @@ public class SQLWrapperImpl implements SQLWrapper { 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<>(YMLWrapperImpl.ofRaw(configFile)); + GameModeConfig gameModeConfig = new GameModeConfig<>(configFile, YMLWrapper.ToString, YMLWrapper.ToString, YMLWrapper.ToString, YMLWrapper.ToStaticWarGear); if (!gameModeConfig.Schematic.loaded) continue; String type = gameModeConfig.Schematic.Type; assert type != null; @@ -56,9 +56,7 @@ public class SQLWrapperImpl implements SQLWrapper { tmpFromDB.put(checktype.toDB(), checktype); } - boolean manualCheck = gameModeConfig.Schematic.ManualCheck; - - SchematicType current = new SchematicType(type, shortcut, gameModeConfig.Server.loaded ? SchematicType.Type.FIGHT_TYPE : SchematicType.Type.NORMAL, checktype, material, manualCheck); + 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); } diff --git a/VelocityCore/src/de/steamwar/data/YMLWrapperImpl.java b/VelocityCore/src/de/steamwar/data/YMLWrapperImpl.java deleted file mode 100644 index b5dc7a60..00000000 --- a/VelocityCore/src/de/steamwar/data/YMLWrapperImpl.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2025 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.data; - -import de.steamwar.sql.SchematicType; -import org.yaml.snakeyaml.Yaml; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.function.Function; - -public class YMLWrapperImpl extends YMLWrapper { - - public static YMLWrapperImpl ofTyped(File file) { - return new YMLWrapperImpl<>(file, ToSchematicType); - } - - public static YMLWrapperImpl ofRaw(File file) { - return new YMLWrapperImpl<>(file, ToString); - } - - private final boolean canLoad; - private final Map document; - - private YMLWrapperImpl(File file, Function schematicTypeMapper) { - super(file, ToString, schematicTypeMapper, ToString); - if (file == null || !file.exists()) { - canLoad = false; - document = new HashMap<>(); - } else { - canLoad = true; - Yaml yaml = new Yaml(); - try { - document = yaml.load(new FileInputStream(file)); - } catch (IOException e) { - throw new SecurityException(e.getMessage(), e); - } - } - } - - private YMLWrapperImpl(boolean canLoad, Map document, Function schematicTypeMapper) { - super(null, ToString, schematicTypeMapper, ToString); - this.canLoad = canLoad; - this.document = document; - } - - @Override - public boolean canLoad() { - return canLoad; - } - - @Override - public YMLWrapper with(String path) { - if (document.containsKey(path)) { - Object value = this.document.get(path); - if (value instanceof Map) { - return new YMLWrapperImpl(this.canLoad, (Map) value, schematicTypeMapper); - } - } - return new YMLWrapperImpl(false, Collections.emptyMap(), schematicTypeMapper); - } - - @Override - public String getDefaultGameName() { - return file.getName().replace(".yml", ""); - } - - @Override - public T get(String path, T defaultValue, Function mapper) { - Object value = this.document.get(path); - if (value == null) return defaultValue; - try { - return mapper.apply(value); - } catch (ClassCastException e) { - return defaultValue; - } - } - - @Override - public List get(String path, Function> mapper) { - Object value = this.document.get(path); - if (value == null) return Collections.emptyList(); - try { - return Collections.unmodifiableList(mapper.apply(value)); - } catch (ClassCastException e) { - return Collections.emptyList(); - } - } - - @Override - public List> getMapList(String path) { - Object value = this.document.get(path); - if (value instanceof List) { - return Collections.unmodifiableList((List>) value); - } else { - return Collections.emptyList(); - } - } -} diff --git a/VelocityCore/src/de/steamwar/sql/SQLWrapperImpl.java b/VelocityCore/src/de/steamwar/sql/SQLWrapperImpl.java index 8f4328a1..cde15d01 100644 --- a/VelocityCore/src/de/steamwar/sql/SQLWrapperImpl.java +++ b/VelocityCore/src/de/steamwar/sql/SQLWrapperImpl.java @@ -22,7 +22,7 @@ package de.steamwar.sql; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.server.RegisteredServer; import de.steamwar.data.GameModeConfig; -import de.steamwar.data.YMLWrapperImpl; +import de.steamwar.data.YMLWrapper; import de.steamwar.velocitycore.VelocityCore; import de.steamwar.velocitycore.commands.CheckCommand; @@ -40,7 +40,7 @@ public class SQLWrapperImpl implements SQLWrapper { return; for(File file : Arrays.stream(folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))).sorted().toList()) { - GameModeConfig gameModeConfig = new GameModeConfig<>(YMLWrapperImpl.ofRaw(file)); + GameModeConfig gameModeConfig = new GameModeConfig<>(file, YMLWrapper.ToString, YMLWrapper.ToString, YMLWrapper.ToString, YMLWrapper.ToInternalName); if (!gameModeConfig.Schematic.loaded) continue; if (tmpFromDB.containsKey(gameModeConfig.Schematic.Type.toLowerCase())) continue; diff --git a/VelocityCore/src/de/steamwar/velocitycore/ArenaMode.java b/VelocityCore/src/de/steamwar/velocitycore/ArenaMode.java index 7b94c584..53a2e0b0 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/ArenaMode.java +++ b/VelocityCore/src/de/steamwar/velocitycore/ArenaMode.java @@ -20,7 +20,7 @@ package de.steamwar.velocitycore; import de.steamwar.data.GameModeConfig; -import de.steamwar.data.YMLWrapperImpl; +import de.steamwar.data.YMLWrapper; import de.steamwar.sql.SchematicType; import lombok.Getter; import lombok.experimental.UtilityClass; @@ -52,7 +52,7 @@ public class ArenaMode { return; for(File file : Arrays.stream(folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))).sorted().toList()) { - de.steamwar.data.GameModeConfig gameModeConfig = new de.steamwar.data.GameModeConfig<>(YMLWrapperImpl.ofTyped(file)); + GameModeConfig gameModeConfig = new GameModeConfig<>(file, YMLWrapper.ToString, YMLWrapper.ToSchematicType, YMLWrapper.ToString, YMLWrapper.ToInternalName); if (!gameModeConfig.Server.loaded) continue; allModes.add(gameModeConfig); diff --git a/WebsiteBackend/src/de/steamwar/sql/SQLWrapperImpl.kt b/WebsiteBackend/src/de/steamwar/sql/SQLWrapperImpl.kt index 1e1b8625..714e34d4 100644 --- a/WebsiteBackend/src/de/steamwar/sql/SQLWrapperImpl.kt +++ b/WebsiteBackend/src/de/steamwar/sql/SQLWrapperImpl.kt @@ -19,7 +19,8 @@ package de.steamwar.sql -import org.bspfsystems.yamlconfiguration.file.YamlConfiguration +import de.steamwar.data.GameModeConfig +import de.steamwar.data.YMLWrapper import java.io.File import java.util.* import java.util.stream.Collectors @@ -29,32 +30,26 @@ fun loadSchematicTypes(tmpTypes: MutableList?, tmpFromDB: Mutable if (folder.exists()) { for (configFile in Arrays.stream(folder.listFiles { _, name -> name.endsWith(".yml") && !name.endsWith(".kits.yml") }) .sorted().collect(Collectors.toList())) { - val config: YamlConfiguration = YamlConfiguration.loadConfiguration(configFile) - if (!config.isConfigurationSection("Schematic")) continue - val type: String = config.getString("Schematic.Type")!! - val shortcut = config.getString("Schematic.Shortcut") - if (shortcut == null) { - println("No shortcut for $type") - continue - } + val gameModeConfig = GameModeConfig(configFile, YMLWrapper.ToString, YMLWrapper.ToString, YMLWrapper.ToString, YMLWrapper.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: String = config.getString("Schematic.Material", "STONE_BUTTON")!! - if (!config.getStringList("CheckQuestions").isEmpty()) { - checktype = SchematicType("C$type", "C$shortcut", SchematicType.Type.CHECK_TYPE, null, material, false) + 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[checktype.toDB()] = checktype + tmpFromDB.put(checktype.toDB(), checktype) } - val current = SchematicType( - type, - shortcut, - if (config.isConfigurationSection("Server")) SchematicType.Type.FIGHT_TYPE else SchematicType.Type.NORMAL, - checktype, - material, - false - ) + + 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[type.lowercase(Locale.getDefault())] = current + tmpFromDB.put(type.lowercase(Locale.getDefault()), current) } } }