From 87a4836fa10cd72824903e6293d7747a38cefca8 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sat, 25 Oct 2025 21:45:44 +0200 Subject: [PATCH 01/16] Add Unified GameModeConfig --- .../features/autostart/AutostartListener.java | 2 +- .../design/endstone/DesignEndStone.java | 12 +- .../endstone/DesignEndStoneCommand.java | 2 +- .../region/RegionScoreboardElement.java | 4 +- .../features/script/lua/libs/RegionLib.java | 2 +- .../features/techhider/TechHiderCommand.java | 4 +- .../bausystem/features/xray/XrayCommand.java | 4 +- .../bausystem/region/GameModeConfig.java | 128 --- .../de/steamwar/bausystem/region/Region.java | 5 +- .../region/fixed/FixedGlobalRegion.java | 6 +- .../bausystem/region/fixed/FixedRegion.java | 7 +- CommonCore/Data/build.gradle.kts | 1 + .../src/de/steamwar/data/GameModeConfig.java | 821 ++++++++++++++++++ .../Data/src/de/steamwar/data/YMLWrapper.java | 98 +++ .../src/de/steamwar/sql/SchematicType.java | 5 + FightSystem/FightSystem_Core/src/config.yml | 23 +- .../src/de/steamwar/fightsystem/Config.java | 195 +---- .../de/steamwar/fightsystem/ai/DummyAI.java | 2 +- .../fightsystem/commands/Commands.java | 4 +- .../de/steamwar/fightsystem/commands/GUI.java | 22 +- .../countdown/EnternCountdown.java | 4 +- .../countdown/EventSpectateCountdown.java | 2 +- .../countdown/NoPlayersOnlineCountdown.java | 4 +- .../countdown/PostSchemCountdown.java | 4 +- .../countdown/PreRunningCountdown.java | 2 +- .../countdown/PreSchemCountdown.java | 2 +- .../countdown/SpectateOverCountdown.java | 2 +- .../countdown/TimeOverCountdown.java | 2 +- .../de/steamwar/fightsystem/fight/Fight.java | 2 +- .../fightsystem/fight/FightPlayer.java | 8 +- .../fightsystem/fight/FightSchematic.java | 18 +- .../steamwar/fightsystem/fight/FightTeam.java | 12 +- .../fightsystem/fight/FightWorld.java | 2 +- .../steamwar/fightsystem/fight/HotbarKit.java | 2 +- .../de/steamwar/fightsystem/fight/Kit.java | 16 +- .../fightsystem/listener/ArenaBorder.java | 4 +- .../fightsystem/listener/ArrowStopper.java | 4 +- .../listener/BlockFadeListener.java | 2 +- .../steamwar/fightsystem/listener/Chat.java | 2 +- .../listener/DenyWorldInteraction.java | 4 +- .../fightsystem/listener/InFightDamage.java | 2 +- .../listener/JoinRequestListener.java | 2 +- .../fightsystem/listener/LeaveableArena.java | 2 +- .../fightsystem/listener/Permanent.java | 12 +- .../listener/PersonalKitCreator.java | 2 +- .../fightsystem/listener/PistonListener.java | 4 +- .../fightsystem/listener/PrepareSchem.java | 2 +- .../fightsystem/listener/Shutdown.java | 2 +- .../fightsystem/listener/WaterRemover.java | 2 +- .../fightsystem/record/PacketProcessor.java | 4 +- .../states/OneShotStateDependent.java | 2 +- .../fightsystem/states/StateDependent.java | 2 +- .../states/StateDependentCountdown.java | 2 +- .../states/StateDependentListener.java | 2 +- .../states/StateDependentTask.java | 2 +- .../fightsystem/utils/BungeeFightInfo.java | 2 +- .../fightsystem/utils/FightStatistics.java | 2 +- .../de/steamwar/fightsystem/utils/Hull.java | 2 +- .../fightsystem/utils/TechHiderWrapper.java | 4 +- .../WinconditionBasePercent.java | 12 +- .../winconditions/WinconditionBlocks.java | 2 +- .../WinconditionComparisonTimeout.java | 2 +- .../winconditions/WinconditionPoints.java | 2 +- .../winconditions/WinconditionTimeTechKO.java | 2 +- .../WinconditionTimedDamageTechKO.java | 2 +- .../winconditions/WinconditionTimeout.java | 2 +- .../autocheck/AutoChecker15.java | 7 +- .../schematiccommand/SchematicCommand15.java | 15 +- .../autocheck/AutoChecker8.java | 7 +- .../schematiccommand/SchematicCommand8.java | 7 +- .../schematicsystem/CheckSchemType.java | 113 --- .../CheckSchemTypeManager.java | 56 ++ .../autocheck/AutoChecker.java | 11 +- .../autocheck/AutoCheckerResult.java | 48 +- .../commands/schematiccommand/GUI.java | 4 +- .../schematiccommand/SchematicCommand.java | 21 +- .../SchematicCommandUtils.java | 10 +- .../schematiccommand/SchematicMapper.java | 14 +- .../schematiccommand/SchematicValidator.java | 1 - .../schematiccommand/parts/CheckPart.java | 14 +- .../schematiccommand/parts/ModifyPart.java | 4 +- .../schematiccommand/parts/SearchPart.java | 2 +- .../src/de/steamwar/data/YMLWrapperImpl.java | 154 ++++ .../src/de/steamwar/sql/SQLWrapperImpl.java | 52 +- .../src/de/steamwar/data/YMLWrapperImpl.java | 159 ++++ .../src/de/steamwar/sql/SQLWrapperImpl.java | 46 +- .../de/steamwar/velocitycore/ArenaMode.java | 105 +-- .../steamwar/velocitycore/GameModeConfig.java | 98 --- .../steamwar/velocitycore/ServerStarter.java | 17 +- .../steamwar/velocitycore/ServerVersion.java | 12 + .../velocitycore/commands/BauCommand.java | 4 +- .../commands/BuilderCloudCommand.java | 6 +- .../commands/ChallengeCommand.java | 10 +- .../velocitycore/commands/CheckCommand.java | 5 +- .../velocitycore/commands/FightCommand.java | 20 +- .../commands/HistoricCommand.java | 6 +- .../velocitycore/commands/RankCommand.java | 6 +- .../velocitycore/commands/ReplayCommand.java | 11 +- .../velocitycore/commands/TypeMappers.java | 16 +- .../velocitycore/listeners/ChatListener.java | 3 +- .../network/handlers/EloPlayerHandler.java | 6 +- .../network/handlers/EloSchemHandler.java | 5 +- .../network/handlers/PrepareSchemHandler.java | 9 +- 103 files changed, 1731 insertions(+), 876 deletions(-) delete mode 100644 BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/GameModeConfig.java create mode 100644 CommonCore/Data/src/de/steamwar/data/GameModeConfig.java create mode 100644 CommonCore/Data/src/de/steamwar/data/YMLWrapper.java delete mode 100644 SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemType.java create mode 100644 SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemTypeManager.java create mode 100644 SpigotCore/SpigotCore_Main/src/de/steamwar/data/YMLWrapperImpl.java create mode 100644 VelocityCore/src/de/steamwar/data/YMLWrapperImpl.java delete mode 100644 VelocityCore/src/de/steamwar/velocitycore/GameModeConfig.java diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java index 5aaf3ed6..d45a7029 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java @@ -129,7 +129,7 @@ public class AutostartListener implements Listener { if (!regionStartTime.containsKey(region)) return; if (!region.getTestblockArea().inRegion(block.getLocation(), true)) return; long tickDiff = TPSUtils.currentRealTick.get() - regionStartTime.remove(region); - long preFightDurationInSeconds = region.getGameModeConfig().getTimes().getPreFightDuration(); + long preFightDurationInSeconds = region.getGameModeConfig().Times.PreFightDuration; RegionUtils.message(region, "AUTOSTART_MESSAGE_RESULT1", tickDiff); RegionUtils.message(region, "AUTOSTART_MESSAGE_RESULT2", preFightDurationInSeconds, ((preFightDurationInSeconds * 20) - tickDiff)); RegionUtils.message(region, "AUTOSTART_MESSAGE_RESULT3"); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStone.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStone.java index 0b2bde85..fe529864 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStone.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStone.java @@ -29,10 +29,12 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; -import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; -import java.util.*; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; import java.util.stream.Collectors; public class DesignEndStone { @@ -54,15 +56,13 @@ public class DesignEndStone { this.maxY = region.getBuildArea().getMaxPoint(false).getY(); this.maxZ = region.getBuildArea().getMaxPoint(false).getZ(); - limited = region.getGameModeConfig() - .getSchematic() - .getLimited() + limited = region.getGameModeConfig().Schematic.Limited .entrySet() .stream() .filter(entry -> entry.getValue() == 0) .flatMap(entry -> entry.getKey().stream()) .collect(Collectors.toSet()); - calculateFromBottom = region.getGameModeConfig().getArena().isNoFloor(); + calculateFromBottom = region.getGameModeConfig().Arena.NoFloor; entityServer.setCallback((player, rEntity, entityAction) -> { if (entityAction != REntityServer.EntityAction.ATTACK) return; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStoneCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStoneCommand.java index d049d2f1..79d0d408 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStoneCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStoneCommand.java @@ -52,7 +52,7 @@ public class DesignEndStoneCommand extends SWCommand implements Listener { BauSystem.MESSAGE.send("DESIGN_ENDSTONE_REGION_ERROR", player); return; } - if (!region.getGameModeConfig().isLoaded()) { + if (!region.getGameModeConfig().loaded) { BauSystem.MESSAGE.send("DESIGN_ENDSTONE_REGION_ERROR", player); return; } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionScoreboardElement.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionScoreboardElement.java index e4c900fc..7d6db5db 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionScoreboardElement.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionScoreboardElement.java @@ -43,8 +43,8 @@ public class RegionScoreboardElement implements ScoreboardElement { @Override public String get(Region region, Player p) { if (region.getType().isGlobal()) return null; - if (!region.getGameModeConfig().isLoaded()) return null; - List names = region.getGameModeConfig().getServer().getChatNames(); + if (!region.getGameModeConfig().loaded) return null; + List names = region.getGameModeConfig().Server.ChatNames; if (names.isEmpty()) return null; return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_REGION", p) + "§8: §7" + names.get(0); } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/RegionLib.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/RegionLib.java index 87ee8687..265d7a45 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/RegionLib.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/RegionLib.java @@ -51,7 +51,7 @@ public class RegionLib implements LuaLib { if (rg.getType().isGlobal()) { return "global"; } - List chatNames = rg.getGameModeConfig().getServer().getChatNames(); + List chatNames = rg.getGameModeConfig().Server.ChatNames; if (chatNames.isEmpty()) { return "unknown"; } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java index fe7b8a4b..7cb18b50 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java @@ -65,7 +65,7 @@ public class TechHiderCommand extends SWCommand implements Listener, ScoreboardE } Optional techHider = techHiders.computeIfAbsent(region, rg -> { - if (!region.getGameModeConfig().getTechhider().isActive()) { + if (!region.getGameModeConfig().Techhider.Active) { return Optional.empty(); } @@ -74,7 +74,7 @@ public class TechHiderCommand extends SWCommand implements Listener, ScoreboardE TechHider current = new TechHider((p, cX, cY) -> { if (rg.getBuildArea().isChunkOutside(cX, cY)) return true; return !hidden.get(rg).contains(p); - }, region.getGameModeConfig().getTechhider().getObfuscateWith(), region.getGameModeConfig().getTechhider().getHiddenBlocks(), region.getGameModeConfig().getTechhider().getHiddenBlockEntities()); + }, region.getGameModeConfig().Techhider.ObfuscateWith, region.getGameModeConfig().Techhider.HiddenBlocks, region.getGameModeConfig().Techhider.HiddenBlockEntities); current.enable(); return Optional.of(current); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java index 29c83ec8..babd0d88 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java @@ -67,13 +67,13 @@ public class XrayCommand extends SWCommand implements Listener, ScoreboardElemen } Optional techHider = techHiders.computeIfAbsent(region, rg -> { - if (!region.getGameModeConfig().getTechhider().isActive()) { + if (!region.getGameModeConfig().Techhider.Active) { return Optional.empty(); } hidden.put(rg, new HashSet<>()); - Set blocks = new HashSet<>(Arrays.asList(region.getGameModeConfig().getTechhider().getObfuscateWith())); + Set blocks = new HashSet<>(Arrays.asList(region.getGameModeConfig().Techhider.ObfuscateWith)); if (blocks.contains(Material.END_STONE)) blocks.add(Material.END_STONE_BRICKS); xrayedBlocks.put(region, blocks); return Optional.of(createXray(rg, blocks)); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/GameModeConfig.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/GameModeConfig.java deleted file mode 100644 index ee4089ab..00000000 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/GameModeConfig.java +++ /dev/null @@ -1,128 +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.bausystem.region; - -import de.steamwar.core.FlatteningWrapper; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; -import org.bukkit.Material; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; - -import java.io.File; -import java.util.*; -import java.util.stream.Collectors; - -@Getter -public class GameModeConfig { - - private final boolean loaded; - - /** - * See gamemode config Times key - */ - private Times Times = new Times(); - private Schematic Schematic = new Schematic(); - private Arena Arena = new Arena(); - private Server Server = new Server(); - private Techhider Techhider = new Techhider(); - - public GameModeConfig(File file) { - if (file == null || !file.exists()) { - loaded = false; - return; - } - loaded = true; - - FileConfiguration config = YamlConfiguration.loadConfiguration(file); - - Times.load(config.getConfigurationSection("Times")); - Schematic.load(config.getConfigurationSection("Schematic")); - Arena.load(config.getConfigurationSection("Arena")); - Server.load(config.getConfigurationSection("Server")); - Techhider.load(config.getConfigurationSection("Techhider")); - } - - @NoArgsConstructor(access = AccessLevel.PRIVATE) - @Getter - public static class Times { - private int PreFightDuration = 30; - - private void load(ConfigurationSection section) { - PreFightDuration = section.getInt("PreFightDuration", 30); - } - } - - @NoArgsConstructor(access = AccessLevel.PRIVATE) - @Getter - public static class Schematic { - private Map, Integer> Limited = new HashMap<>(); - - private void load(ConfigurationSection section) { - for(Map entry : section.getMapList("Limited")) { - int amount = (Integer) entry.get("Amount"); - Set materials = new HashSet<>((List) entry.get("Materials")); - if (amount == 0) { - materials.forEach(material -> Limited.put(Collections.singleton(Material.getMaterial(material)), 0)); - } else { - Limited.put(materials.stream().map(Material::getMaterial).collect(Collectors.toSet()), amount); - } - } - } - } - - @NoArgsConstructor(access = AccessLevel.PRIVATE) - @Getter - public static class Arena { - private boolean NoFloor = false; - - private void load(ConfigurationSection section) { - NoFloor = section.getBoolean("NoFloor", false); - } - } - - @NoArgsConstructor(access = AccessLevel.PRIVATE) - @Getter - public static class Server { - private List ChatNames; - - private void load(ConfigurationSection section) { - ChatNames = section.getStringList("ChatNames"); - } - } - - @NoArgsConstructor(access = AccessLevel.PRIVATE) - @Getter - public static class Techhider { - private boolean Active = false; - private Material ObfuscateWith = Material.END_STONE; - private Set HiddenBlocks = new HashSet<>(); - private Set HiddenBlockEntities = new HashSet<>(); - - private void load(ConfigurationSection section) { - Active = section.getBoolean("Active", false); - ObfuscateWith = Material.getMaterial(section.getString("ObfuscateWith", "END_STONE")); - HiddenBlocks = section.getStringList("HiddenBlocks").stream().map(String::toUpperCase).map(FlatteningWrapper.impl::getMaterial).filter(Objects::nonNull).collect(Collectors.toUnmodifiableSet()); - HiddenBlockEntities = Collections.unmodifiableSet(new HashSet<>(section.getStringList("HiddenBlockEntities"))); - } - } -} diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java index 4b99d523..4b98caf1 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java @@ -22,8 +22,11 @@ package de.steamwar.bausystem.region; import com.sk89q.worldedit.extent.clipboard.Clipboard; import de.steamwar.bausystem.utils.FlatteningWrapper; import de.steamwar.bausystem.utils.PasteBuilder; +import de.steamwar.data.GameModeConfig; +import de.steamwar.sql.SchematicType; import lombok.NonNull; import org.bukkit.Location; +import org.bukkit.Material; import javax.annotation.Nullable; import java.io.File; @@ -64,7 +67,7 @@ public interface Region { Area getTestblockArea(); @NonNull - GameModeConfig getGameModeConfig(); + GameModeConfig getGameModeConfig(); @NonNull RegionHistory getHistory(); 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 66f7c44a..1edc4787 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 @@ -22,9 +22,13 @@ package de.steamwar.bausystem.region.fixed; 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.sql.SchematicType; import lombok.NonNull; import lombok.Setter; import org.bukkit.Location; +import org.bukkit.Material; import javax.annotation.Nullable; import java.io.File; @@ -90,7 +94,7 @@ public final class FixedGlobalRegion implements Region { } }; - private static final GameModeConfig GLOBAL_CONFIG = new GameModeConfig(null); + private static final GameModeConfig GLOBAL_CONFIG = new GameModeConfig<>(YMLWrapperImpl.ofTyped(null)); 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 d6278424..69d7b9d0 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 @@ -28,9 +28,12 @@ import de.steamwar.bausystem.utils.FlatteningWrapper; 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.sql.SchematicType; import lombok.NonNull; import org.bukkit.Bukkit; +import org.bukkit.Material; import yapion.hierarchy.types.YAPIONObject; import javax.annotation.Nullable; @@ -57,7 +60,7 @@ public class FixedRegion implements Region { private final Area testblock; private final int floorLevel; private final int waterLevel; - private final GameModeConfig gameModeConfig; + private final GameModeConfig gameModeConfig; private final RegionData regionData; private final RegionHistory regionHistory = new RegionHistory.Impl(20); @@ -336,7 +339,7 @@ public class FixedRegion implements Region { break; } } - this.gameModeConfig = new GameModeConfig(found); + this.gameModeConfig = new GameModeConfig<>(YMLWrapperImpl.ofTyped(found)); this.regionData = new RegionData.RegionDataImpl(regionData, WorldData::write); } diff --git a/CommonCore/Data/build.gradle.kts b/CommonCore/Data/build.gradle.kts index a8ffa845..b458588b 100644 --- a/CommonCore/Data/build.gradle.kts +++ b/CommonCore/Data/build.gradle.kts @@ -22,4 +22,5 @@ plugins { } dependencies { + api(project(":CommonCore:SQL")) } \ 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 new file mode 100644 index 00000000..d68fddcd --- /dev/null +++ b/CommonCore/Data/src/de/steamwar/data/GameModeConfig.java @@ -0,0 +1,821 @@ +/* + * 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 lombok.ToString; + +import java.io.File; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.time.Instant; +import java.time.LocalDateTime; +import java.util.*; +import java.util.stream.Collectors; + +@ToString +public final class GameModeConfig { + + private static final Random random = new Random(); + public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yyyy HH:mm"); + + public final boolean loaded; + public final File configFile; + + public final Server Server; + + /** + * Submission deadline for schematics in 'dd.MM.yyyy HH:mm' format + * @implSpec {@code null} by default + */ + public final Date Deadline; + + /** + * The questions that have to be answered to accept the schematic + * + * @implSpec Disables check schem type if missing + */ + public final List CheckQuestions; + public final Times Times; + public final Arena Arena; + public final Schematic Schematic; + + /** + * The name of the game mode presented to the players + * + * @implSpec {@code YMLWrapper.getDefaultGameName()} by default + */ + public final String GameName; + + /** + * The months this game mode should be active and playable
+ * The empty List means all of them + * + * @implNote 1 is January - 12 is December + */ + public final List ActiveMonths; + + /** + * The prefix used for team chats + * + * @implSpec {@code +} by default + */ + public final String TeamChatPrefix; + public final Blue Blue; + public final Red Red; + + /** + * The list of active win conditions + */ + public final List WinConditions; + public final WinConditionParams WinConditionParams; + public final Kits Kits; + + /** + * A list of integers containing the waiting time of this enter stage in the fight + */ + public final List EnterStages; + public final Techhider Techhider; + + public GameModeConfig(YMLWrapper loader) { + configFile = loader.getFile(); + loaded = loader.canLoad(); + Server = new Server(loader.with("Server")); + + String deadlineString = loader.getString("Deadline", null); + if (deadlineString != null) { + Date Deadline = null; + try { + Deadline = DATE_FORMAT.parse(deadlineString); + } catch (ParseException e) { + Deadline = null; + } + this.Deadline = Deadline; + } else { + Deadline = null; + } + + CheckQuestions = loader.getStringList("CheckQuestions"); + 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()); + ActiveMonths = loader.getIntList("ActiveMonths"); + TeamChatPrefix = loader.getString("TeamChatPrefix", "+"); + Blue = new Blue(loader.with("Blue")); + Red = new Red(loader.with("Red")); + WinConditions = Collections.unmodifiableList(loader.getStringList("WinConditions").stream().map(loader.winconditionMapper).collect(Collectors.toList())); + WinConditionParams = new WinConditionParams<>(loader.with("WinConditionParams")); + Kits = new Kits<>(loader.with("Kits")); + EnterStages = loader.getIntList("EnterStages"); + Techhider = new Techhider<>(loader.with("Techhider")); + + Arena = new Arena(loader.with("Arena"), Schematic.Size, EnterStages); + } + + @ToString + public static final class Server { + + public final boolean loaded; + + /** + * Base server folder + */ + public final String Folder; + + /** + * Server java archive + */ + public final String ServerJar; + + /** + * Available arenas + */ + public final List Maps; + + /** + * Names to address the game mode in the chat interface + */ + public final List ChatNames; + + /** + * If the Server is a Spigot server + * + * @implSpec {@code false} by default + */ + public final boolean Spigot; + + /** + * If the game mode should be marked as a historic game mode + * + * @implSpec {@code false} by default + */ + public final boolean Historic; + + /** + * If ranked matches should be available for the game mode + * + * @implSpec {@code false} by default + */ + public final boolean Ranked; + + private Server(YMLWrapper loader) { + loaded = loader.canLoad(); + Folder = loader.getString("Folder", null); + ServerJar = loader.getString("ServerJar", null); + Maps = loader.getStringList("Maps"); + ChatNames = loader.getStringList("ChatNames"); + Spigot = loader.getBoolean("Spigot", false); + Historic = loader.getBoolean("Historic", false); + Ranked = loader.getBoolean("Ranked", false); + } + } + + @ToString + public static final class Times { + public final boolean loaded; + + /** + * Time in seconds the server stops after starting if nobody joins + * + * @implSpec {@code 300} by default + */ + public final int NoPlayersOnlineDuration; + + /** + * Time in seconds the team leaders have to choose their schematic + * + * @implSpec {@code 120} by default + */ + public final int PreSchemPasteDuration; + + /** + * Time in seconds for preparing + * + * @implSpec {@code 300} by default + */ + public final int SetupDuration; + + /** + * Time in seconds the final countdown is long + * + * @implSpec {@code 30} by default + */ + public final int PreFightDuration; + + /** + * Time in seconds to spectate the arena after the fight + * + * @implSpec {@code 30} by default + */ + public final int SpectatorDuration; + + private Times(YMLWrapper loader) { + loaded = loader.canLoad(); + NoPlayersOnlineDuration = loader.getInt("NoPlayersOnlineDuration", 300); + PreSchemPasteDuration = loader.getInt("PreSchemPasteDuration", 120); + SetupDuration = loader.getInt("SetupDuration", 300); + PreFightDuration = loader.getInt("PreFightDuration", 30); + SpectatorDuration = loader.getInt("SpectatorDuration", 60); + } + } + + @ToString + public static final class Arena { + + public final boolean loaded; + + /** + * The amount of blocks the schematics should be pasted under the surface + * + * @implSpec {@code 0} by default + */ + public final int WaterDepth; + + /** + * The outer border of the arena, measured in blocks around the schematic areas + */ + public final Schem2Border Schem2Border; + + /** + * The offset the teams spawn relative to the center of their area + */ + public final SpawnOffset SpawnOffset; + + /** + * The size of the team areas are expanded around the schematics + * + * @implSpec {@code 12} by default + */ + public final int BorderFromSchematic; + + /** + * If ground walkable, teams can walk below the lower arena border during setup + * + * @implSpec {@code true} by default + */ + public final boolean GroundWalkable; + + /** + * Disable snow and ice melting + * + * @implSpec {@code false} by default + */ + public final boolean DisableSnowMelt; + + /** + * Allow leaving the arena area as spectator + * + * @implSpec {@code false} by default + */ + public final boolean Leaveable; + + /** + * Allow missiles to fly to the enemy and not stop at the schem border. + * + * @implSpec {@code !EnterStages.isEmpty()} by default + */ + public final boolean AllowMissiles; + + /** + * Denotes that there is no floor for this GameMode + * + * @implSpec {@code false} by default + */ + public final boolean NoFloor; + + private Arena(YMLWrapper loader, Schematic.Size Size, List EnterStages) { + loaded = loader.canLoad(); + WaterDepth = loader.getInt("WaterDepth", 0); + Schem2Border = new Schem2Border(loader.with("Schem2Border")); + SpawnOffset = new SpawnOffset(loader.with("SpawnOffset"), Size); + BorderFromSchematic = loader.getInt("BorderFromSchematic", 21); + GroundWalkable = loader.getBoolean("GroundWalkable", true); + DisableSnowMelt = loader.getBoolean("DisableSnowMelt", false); + Leaveable = loader.getBoolean("Leaveable", false); + AllowMissiles = loader.getBoolean("AllowMissiles", !EnterStages.isEmpty()); + NoFloor = loader.getBoolean("NoFloor", false); + } + + @ToString + public static final class Schem2Border { + + public final boolean loaded; + + /** + * @implSpec {@code 24} by default + */ + public final int x; + + /** + * @implSpec {@code 24} by default + */ + public final int z; + + private Schem2Border(YMLWrapper loader) { + loaded = loader.canLoad(); + x = loader.getInt("x", 24); + z = loader.getInt("z", 24); + } + } + + @ToString + public static final class SpawnOffset { + + public final boolean loaded; + + /** + * @implSpec {@code 0} by default + */ + public final double x; + + /** + * @implSpec {@code Schematic.Size.y} by default + */ + public final double y; + + /** + * @implSpec {@code 0} by default + */ + public final double z; + + private SpawnOffset(YMLWrapper loader, Schematic.Size Size) { + loaded = loader.canLoad(); + x = loader.getDouble("x", 0); + y = loader.getDouble("y", Size.y); + z = loader.getDouble("z", 0); + } + } + } + + @ToString + public static final class Schematic { + + public final boolean loaded; + + /** + * The size of the schematics + */ + public final Size Size; + + /** + * Used for GameModes with a technic area + */ + public final Inset Inset; + + /** + * The schematic type that can be chosen in this arena + * + * @implSpec {@code Normal} by default + */ + public final ST Type; + + /** + * The schematic types that are also allowed to be chosen in this arena + */ + public final List SubTypes; + + /** + * Shortcut of the schematic type + * + * @implSpec {@code ""} by default + */ + public final String Shortcut; + + /** + * Spigot (1.8) material for GUIs + * + * @implSpec {@code STONE_BUTTON} by default + */ + public final M Material; + + /** + * Manual check of schematic necessary + * + * @implSpec {@code true} by default + */ + public final boolean ManualCheck; + + /** + * If the schematics should be rotated during pasting + * + * @implSpec {@code true} by default + */ + public final boolean Rotate; + + /** + * If the schematics should be pasted aligned to the borders instead of centered + * + * @implSpec {@code false} by default + */ + public final boolean PasteAligned; + + /** + * If only public schematics are allowed + * + * @implSpec {@code false} by default + */ + public final boolean OnlyPublicSchematics; + + /** + * If the public only force should be completely disabled + * + * @implSpec {@code false} by default + */ + public final boolean IgnorePublicOnly; + + /** + * If obsidian and bedrock should be replaced during PRE_RUNNING + * + * @implSpec {@code false} by default + */ + public final boolean ReplaceObsidianBedrock; + + /** + * If the replacement should happen with block updates + * + * @implSpec {@code false} by default + */ + public final boolean ReplaceWithBlockupdates; + + /** + * If the schematic perparation arena mode is time limited + * + * @implSpec {@code false} by default + */ + public final boolean UnlimitedPrepare; + + /** + * Maximal amount of blocks allowed in the schematic + * + * @implSpec {@code 0} by default + */ + public final int MaxBlocks; + + /** + * Maximal amount of items per dispenser + * + * @implSpec {@code 128} by default + */ + public final int MaxDispenserItems; + + /** + * Maximal blast resistance for the design blocks + * + * @implSpec {@code Double.MAX_VALUE} by default + */ + public final double MaxDesignBlastResistance; + + /** + * List of limited material (combinations)
+ * List contains tags Amount (integer) and Materials (List of material names in Spigot 1.12 AND Spigot 1.15 format) + */ + public final Map, Integer> Limited; + + private Schematic(YMLWrapper loader) { + loaded = loader.canLoad(); + Size = new Size(loader.with("Size")); + Inset = new Inset(loader.with("Inset")); + Type = loader.getSchematicType("Type", "Normal"); + SubTypes = loader.getSchematicTypeList("SubTypes"); + Shortcut = loader.getString("Shortcut", ""); + Material = loader.getMaterial("Material", "STONE_BUTTON"); + ManualCheck = loader.getBoolean("ManualCheck", true); + Rotate = loader.getBoolean("Rotate", true); + PasteAligned = loader.getBoolean("PasteAligned", false); + OnlyPublicSchematics = loader.getBoolean("OnlyPublicSchematics", false); + IgnorePublicOnly = loader.getBoolean("IgnorePublicOnly", false); + ReplaceObsidianBedrock = loader.getBoolean("ReplaceObsidianBedrock", false); + ReplaceWithBlockupdates = loader.getBoolean("ReplaceWithBlockupdates", false); + UnlimitedPrepare = loader.getBoolean("UnlimitedPrepare", false); + MaxBlocks = loader.getInt("MaxBlocks", 0); + MaxDispenserItems = loader.getInt("MaxDispenserItems", 128); + MaxDesignBlastResistance = loader.getDouble("MaxDesignBlastResistance", Double.MAX_VALUE); + + Map, Integer> Limited = new HashMap<>(); + for (Map entry : loader.getMapList("Limited")) { + int amount = (Integer) entry.get("Amount"); + Set materials = new HashSet<>((List) entry.get("Materials")); + if (amount == 0) { + materials.forEach(material -> { + Limited.put(Collections.singleton(loader.materialMapper.apply(material.toUpperCase())), 0); + }); + } else { + Limited.put(Collections.unmodifiableSet(materials.stream().map(String::toUpperCase).map(loader.materialMapper).collect(Collectors.toSet())), amount); + } + } + this.Limited = Collections.unmodifiableMap(Limited); + } + + @ToString + public static final class Size { + + public final boolean loaded; + + /** + * @implSpec {@code 0} by default + */ + public final int x; + + /** + * @implSpec {@code 0} by default + */ + public final int y; + + /** + * @implSpec {@code 0} by default + */ + public final int z; + + private Size(YMLWrapper loader) { + loaded = loader.canLoad(); + x = loader.getInt("x", 0); + y = loader.getInt("y", 0); + z = loader.getInt("z", 0); + } + } + + @ToString + public static final class Inset { + + public final boolean loaded; + + /** + * @implSpec {@code 0} by default + */ + public final int x; + + /** + * @implSpec {@code 0} by default + */ + public final int z; + + /** + * @implSpec {@code 0} by default + */ + public final int top; + + /** + * @implSpec {@code 0} by default + */ + public final int bottom; + + private Inset(YMLWrapper loader) { + loaded = loader.canLoad(); + x = loader.getInt("x", 0); + z = loader.getInt("z", 0); + top = loader.getInt("top", 0); + bottom = loader.getInt("bottom", 0); + } + } + } + + @ToString + public static final class Blue { + + public final boolean loaded; + + /** + * @implSpec {@code Blau} by default + */ + public final String Name; + + /** + * @implSpec {@code §3} by default + */ + public final String Prefix; + + private Blue(YMLWrapper loader) { + loaded = loader.canLoad(); + Name = loader.getString("Name", "Blau"); + Prefix = loader.getString("Prefix", "§3"); + } + } + + @ToString + public static final class Red { + + public final boolean loaded; + + /** + * @implSpec {@code Rot} by default + */ + public final String Name; + + /** + * @implSpec {@code §c} by default + */ + public final String Prefix; + + private Red(YMLWrapper loader) { + loaded = loader.canLoad(); + Name = loader.getString("Name", "Rot"); + Prefix = loader.getString("Prefix", "§c"); + } + } + + @ToString + public static final class WinConditionParams { + + public final boolean loaded; + + /** + * The time of any of the timeout win conditions in seconds + * + * @implSpec {@code 1200} by default + */ + public final int TimeoutTime; + + /** + * The percentage when any of the percent win conditions limits or triggers a win + * + * @implSpec {@code 7.0} by default + */ + public final double PercentWin; + + /** + * Does the percentage still change after the start of the enter phase + * + * @implSpec {@code true} by default + */ + public final boolean PercentEntern; + + /** + * Is Blocks a whitelist (true) or blacklist (false) + * + * @implSpec {@code false} by default + */ + public final boolean BlocksWhitelist; + + /** + * Special Blocks (Valid spigot material values) used by the percent win conditions + */ + public final List Blocks; + + /** + * Time for being declared TechKo without a shot given. + * + * @implSpec {@code 90} by default + */ + public final int TechKoTime; + + private WinConditionParams(YMLWrapper loader) { + loaded = loader.canLoad(); + TimeoutTime = loader.getInt("TimeoutTime", 1200); + PercentWin = loader.getDouble("PercentWin", 7.0); + PercentEntern = loader.getBoolean("PercentEntern", true); + BlocksWhitelist = loader.getBoolean("BlocksWhitelist", false); + Blocks = loader.getMaterialList("Blocks"); + TechKoTime = loader.getInt("TechKoTime", 90); + } + } + + @ToString + public static final class Kits { + + public final boolean loaded; + + /** + * The kit file for this configuration + * + * @implSpec {@code kits.yml} by default + */ + public final String File; + + /** + * The default kit for team members + * + * @implSpec {@code default} by default + */ + public final String MemberDefault; + + /** + * The default kit for team leaders + * + * @implSpec {@code default} by default + */ + public final String LeaderDefault; + + /** + * If the personal kit system is active + * + * @implSpec {@code false} by default + */ + public final boolean PersonalKits; + + /** + * Items (Valid spigot material values) that are not allowed in the personal kit + */ + public final List ForbiddenItems; + + private Kits(YMLWrapper loader) { + loaded = loader.canLoad(); + File = loader.getString("File", "kits.yml"); + MemberDefault = loader.getString("MemberDefault", "default"); + LeaderDefault = loader.getString("LeaderDefault", "default"); + PersonalKits = loader.getBoolean("PersonalKits", false); + ForbiddenItems = loader.getMaterialList("ForbiddenItems"); + } + } + + @ToString + public static final class Techhider { + + public final boolean loaded; + + /** + * Activates the tech hider + * + * @implSpec {@code false} by default + */ + public final boolean Active; + + /** + * Which block the tech hider replaces to. + * + * @implSpec {@code end_stone} by default + */ + public final M ObfuscateWith; + + /** + * A list of all hidden blocks. "water" results in the hiding of all waterlogged blocks as well. + */ + public final Set HiddenBlocks; + + /** + * The block entity contents that are hidden (here with minecraft:nametag) + */ + public final Set HiddenBlockEntities; + + private Techhider(YMLWrapper loader) { + loaded = loader.canLoad(); + Active = loader.getBoolean("Active", false); + ObfuscateWith = loader.getMaterial("ObfuscateWith", "end_stone"); + HiddenBlocks = Collections.unmodifiableSet(new HashSet<>(loader.getMaterialList("HiddenBlocks"))); + HiddenBlockEntities = Collections.unmodifiableSet(new HashSet<>(loader.getStringList("HiddenBlockEntities"))); + } + } + + public boolean isAfterDeadline() { + return Deadline != null && Deadline.before(Date.from(Instant.now())); + } + + public String hasMap(String map) { + for (String m : Server.Maps) { + if (m.equalsIgnoreCase(map)) + return m; + } + return null; + } + + public String getRandomMap() { + return Server.Maps.get(random.nextInt(Server.Maps.size())); + } + + public String convertToRealMapName(String map) { + for (String m : Server.Maps) { + if (m.equalsIgnoreCase(map)) + return m; + } + return null; + } + + public String getChatName() { + return Server.ChatNames.get(0); + } + + public boolean isActive() { + if (Server.ChatNames.isEmpty()) return false; + if (ActiveMonths.isEmpty()) return true; + return ActiveMonths.contains(LocalDateTime.now().getMonth().getValue()); + } + + public String getSchemTypeOrInternalName() { + if (Schematic.loaded) { + ST type = Schematic.Type; + if (type instanceof SchematicType) { + return ((SchematicType) type).toDB(); + } else if (type instanceof String) { + return (String) type; + } + } + return configFile.getName().replace(".yml", ""); + } +} diff --git a/CommonCore/Data/src/de/steamwar/data/YMLWrapper.java b/CommonCore/Data/src/de/steamwar/data/YMLWrapper.java new file mode 100644 index 00000000..7e9df6b4 --- /dev/null +++ b/CommonCore/Data/src/de/steamwar/data/YMLWrapper.java @@ -0,0 +1,98 @@ +/* + * 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 java.io.File; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; + +public abstract 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; + + protected YMLWrapper(File file, Function materialMapper, Function schematicTypeMapper, Function winconditionMapper) { + this.file = file; + this.materialMapper = materialMapper; + this.schematicTypeMapper = schematicTypeMapper; + this.winconditionMapper = winconditionMapper; + } + + public final File getFile() { + return file; + } + + public abstract boolean canLoad(); + + public abstract YMLWrapper with(String path); + + public abstract String getDefaultGameName(); + + public abstract String getString(String path, String defaultValue); + + public abstract int getInt(String path, int defaultValue); + + public abstract double getDouble(String path, double defaultValue); + + public abstract boolean getBoolean(String path, boolean defaultValue); + + public final ST getSchematicType(String path, String defaultValue) { + String schematicType = getString(path, defaultValue); + return schematicTypeMapper.apply(schematicType); + } + + public final M getMaterial(String path, String defaultValue) { + return materialMapper.apply(getString(path, defaultValue).toUpperCase()); + } + + public abstract List getStringList(String path); + + public abstract List getIntList(String path); + + public final List getSchematicTypeList(String path) { + List list = getStringList(path); + if (list.isEmpty()) { + return Collections.emptyList(); + } else { + return Collections.unmodifiableList(list.stream().map(schematicTypeMapper).collect(Collectors.toList())); + } + } + + public final List getMaterialList(String path) { + List list = getStringList(path); + if (list.isEmpty()) { + return Collections.emptyList(); + } else { + return Collections.unmodifiableList(list.stream().map(String::toUpperCase).map(materialMapper).collect(Collectors.toList())); + } + } + + public abstract List> getMapList(String path); +} diff --git a/CommonCore/SQL/src/de/steamwar/sql/SchematicType.java b/CommonCore/SQL/src/de/steamwar/sql/SchematicType.java index 10d96a92..53c75eff 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/SchematicType.java +++ b/CommonCore/SQL/src/de/steamwar/sql/SchematicType.java @@ -21,9 +21,11 @@ package de.steamwar.sql; import de.steamwar.sql.internal.SqlTypeMapper; import lombok.Getter; +import lombok.extern.slf4j.Slf4j; import java.util.*; +@Slf4j public class SchematicType { public static final SchematicType Normal = new SchematicType("Normal", "", Type.NORMAL, null, "STONE_BUTTON", false); @@ -38,7 +40,10 @@ public class SchematicType { tmpTypes.add(Normal); tmpFromDB.put(Normal.name().toLowerCase(), Normal); + long time = System.currentTimeMillis(); SQLWrapper.impl.loadSchemTypes(tmpTypes, tmpFromDB); + time = System.currentTimeMillis() - time; + log.info("Loaded {} Schematic Types in {}ms", tmpTypes.size(), time); fromDB = Collections.unmodifiableMap(tmpFromDB); types = Collections.unmodifiableList(tmpTypes); diff --git a/FightSystem/FightSystem_Core/src/config.yml b/FightSystem/FightSystem_Core/src/config.yml index ca3645d6..3356e254 100644 --- a/FightSystem/FightSystem_Core/src/config.yml +++ b/FightSystem/FightSystem_Core/src/config.yml @@ -12,11 +12,11 @@ Server: # If ranked matches should be available for the game mode Ranked: false # defaults to false if missing -# The questions that have to be answered to accept the schematic -CheckQuestions: [] # Disables check schem type if missing +# Submission deadline for schematics in 'dd.MM.yyyy HH:mm' format +Deadline: null # defaults to null if missing -# The available schematic ranks -Ranks: [] # Disables ranks for this schematic type if missing +# The questions that have to be answered to accept the schematic +CheckQuestions: [] # Disables check schem type if missing Times: # Time in seconds the server stops after starting if nobody joins @@ -52,6 +52,8 @@ Arena: Leaveable: false # defaults to false if missing # Allow missiles to fly to the enemy and not stop at the schem border. AllowMissiles: false # defaults to true if EnterStages are present otherwise 'false' + # Denotes that there is no floor for this GameMode + NoFloor: false # defaults to false if missing Schematic: # The size of the schematics @@ -59,6 +61,12 @@ Schematic: x: 0 y: 0 z: 0 + # Used for GameModes with a technic area + Inset: + x: 0 + z: 0 + top: 0 + bottom: 0 # The schematic type that can be chosen in this arena Type: Normal # defaults to Normal if missing # The schematic types that are also allowed to be chosen in this arena @@ -87,6 +95,8 @@ Schematic: MaxBlocks: 0 # defaults to 0 (ignored) if missing # Maximal amount of items per dispenser MaxDispenserItems: 128 # defaults to 128 if missing + # Maximal blast resistance for the design blocks + MaxDesignBlastResistance: 100000000 # defaults to Double.MAX_VALUE if missing # List of limited material (combinations) # List contains tags Amount (integer) and Materials (List of material names in Spigot 1.12 AND Spigot 1.15 format) Limited: @@ -95,6 +105,9 @@ Schematic: # The name of the game mode presented to the players GameName: WarGear # defaults to WarGear if missing +# The months this game mode should be active and playable +# The empty List means all of them +ActiveMonths: [] # defaults to none if missing # The prefix used for team chats TeamChatPrefix: + # defaults to + if missing Blue: @@ -137,6 +150,8 @@ WinConditionParams: BlocksWhitelist: false # defaults to false if missing # Special Blocks (Valid spigot material values) used by the percent win conditions Blocks: [] # defaults to none if missing + # Time for being declared TechKo without a shot given. + TechKoTime: 90 # defaults to 90 if missing Kits: # The kit file for this configuration diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java index 289b76d3..57c556ed 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java @@ -19,6 +19,8 @@ package de.steamwar.fightsystem; +import de.steamwar.data.GameModeConfig; +import de.steamwar.data.YMLWrapperImpl; import de.steamwar.fightsystem.utils.Region; import de.steamwar.fightsystem.winconditions.Winconditions; import de.steamwar.sql.*; @@ -32,9 +34,10 @@ import org.bukkit.entity.Player; import org.bukkit.util.Vector; import java.io.File; -import java.util.*; +import java.util.Collections; +import java.util.Set; +import java.util.UUID; import java.util.logging.Level; -import java.util.stream.Collectors; public class Config { @@ -42,15 +45,7 @@ public class Config { public static final World world = Bukkit.getWorlds().get(0); - //Fight sequence - public static final int NoPlayerOnlineDuration; - public static final int PreSchemPasteDuration; - public static final int SetupDuration; - public static final int PreFightDuration; - public static final int SpectatorDuration; - - // entern parameter - public static final List EnterStages; + public static final GameModeConfig GameModeConfig; //arena parameter public static final Region BluePasteRegion; @@ -69,60 +64,20 @@ public class Config { private static final int BlueToRedY; public static final int BlueToRedZ; - public static final int PreperationArea; - public static final int WaterDepth; - public static final boolean GroundWalkable; - public static final boolean DisableSnowMelt; - public static final boolean ArenaLeaveable; - public static final boolean AllowMissiles; - //schematic parameter - public static final boolean RanksEnabled; public static final boolean OnlyPublicSchematics; - public static final boolean IgnorePublicOnly; - public static final de.steamwar.sql.SchematicType SchematicType; - public static final List SubTypes; + public static final boolean RedRotate; public static final boolean BlueRotate; - public static final boolean PasteAligned; - public static final boolean ReplaceObsidianBedrock; - public static final boolean ReplaceWithBlockupdates; - public static final boolean UnlimitedPrepare; //team parameter public static final String TeamRedName; public static final String TeamBlueName; public static final String TeamRedColor; public static final String TeamBlueColor; - public static final String GameName; - public static final String TeamChatDetection; public static final UUID BlueLeader; public static final UUID RedLeader; - //Active win conditions - public static final Set ActiveWinconditions; - - //win condition parameters - public static final int TimeoutTime; - public static final double PercentWin; - public static final boolean PercentEntern; - public static final boolean PercentBlocksWhitelist; - public static final Set PercentBlocks; - public static final int TechKoTime; - - //default kits - public static final String MemberDefault; - public static final String LeaderDefault; - public static final boolean PersonalKits; - public static final Set ForbiddenItems; - public static final String KitFile; - - //tech hider parameter - public static final boolean TechhiderActive; - public static final Set HiddenBlocks; - public static final Set HiddenBlockEntities; - public static final Material ObfuscateWith; - //event parameter public static final EventFight EventKampf; private static final Set Referees; @@ -154,7 +109,7 @@ public class Config { Bukkit.getLogger().log(Level.SEVERE, "Arenaconfig fehlt!"); Bukkit.shutdown(); } - FileConfiguration config = YamlConfiguration.loadConfiguration(new File(FightSystem.getPlugin().getDataFolder(), configFile)); + GameModeConfig = new GameModeConfig<>(YMLWrapperImpl.ofTyped(new File(FightSystem.getPlugin().getDataFolder(), configFile), Winconditions::valueOf)); File worldConfigFile = new File(world.getWorldFolder(), "config.yml"); if(!worldConfigFile.exists()) { @@ -163,111 +118,37 @@ public class Config { } FileConfiguration worldconfig = YamlConfiguration.loadConfiguration(worldConfigFile); - NoPlayerOnlineDuration = config.getInt("Times.NoPlayersOnlineDuration", 300); - PreSchemPasteDuration = config.getInt("Times.PreSchemPasteDuration", 120); - SetupDuration = config.getInt("Times.SetupDuration", 300); - PreFightDuration = config.getInt("Times.PreFightDuration", 30); - SpectatorDuration = config.getInt("Times.SpectatorDuration", 30); - int blueCornerX = worldconfig.getInt("BlueCorner.x"); int blueCornerY = worldconfig.getInt("BlueCorner.y"); int blueCornerZ = worldconfig.getInt("BlueCorner.z"); int underBorder = worldconfig.getInt("UnderBorder", blueCornerY); - WaterDepth = config.getInt("Arena.WaterDepth", 0); - int schem2BorderX = config.getInt("Arena.Schem2Border.x", 24); - int schem2BorderZ = config.getInt("Arena.Schem2Border.z", 24); - PreperationArea = config.getInt("Arena.BorderFromSchematic", 12); - GroundWalkable = config.getBoolean("Arena.GroundWalkable", true); - DisableSnowMelt = config.getBoolean("Arena.DisableSnowMelt", false); - ArenaLeaveable = config.getBoolean("Arena.Leaveable", false); - - int schemsizeX = config.getInt("Schematic.Size.x"); - int schemsizeY = config.getInt("Schematic.Size.y"); - int schemsizeZ = config.getInt("Schematic.Size.z"); - RanksEnabled = !config.getStringList("Ranks").isEmpty(); - SchematicType = de.steamwar.sql.SchematicType.fromDB(Objects.requireNonNull(config.getString("Schematic.Type", "normal"))); - SubTypes = config.getStringList("Schematic.SubTypes").stream().map(de.steamwar.sql.SchematicType::fromDB).collect(Collectors.toList()); - IgnorePublicOnly = config.getBoolean("Schematic.IgnorePublicOnly", false); - boolean rotate = config.getBoolean("Schematic.Rotate", true); - PasteAligned = config.getBoolean("Schematic.PasteAligned", false); - ReplaceObsidianBedrock = config.getBoolean("Schematic.ReplaceObsidianBedrock", false); - ReplaceWithBlockupdates = config.getBoolean("Schematic.ReplaceWithBlockupdates", false); - UnlimitedPrepare = config.getBoolean("Schematic.UnlimitedPrepare", false); - - int schemInsetX = config.getInt("Schematic.Inset.x", 0); - int schemInsetZ = config.getInt("Schematic.Inset.z", 0); - int schemInsetBottom = config.getInt("Schematic.Inset.bottom", 0); - int schemInsetTop = config.getInt("Schematic.Inset.top", 0); - - GameName = config.getString("GameName", "WarGear"); - TeamChatDetection = config.getString("TeamChatPrefix", "+"); - - ActiveWinconditions = Collections.unmodifiableSet(config.getStringList("WinConditions").stream().map(Winconditions::valueOf).collect(Collectors.toSet())); - - TimeoutTime = config.getInt("WinConditionParams.TimeoutTime", 1200); - PercentWin = config.getDouble("WinConditionParams.PercentWin", 7.0); - PercentEntern = config.getBoolean("WinConditionParams.PercentEntern", true); - PercentBlocksWhitelist = config.getBoolean("WinConditionParams.BlocksWhitelist", false); - PercentBlocks = Collections.unmodifiableSet(config.getStringList("WinConditionParams.Blocks").stream().map(Material::valueOf).collect(Collectors.toSet())); - TechKoTime = config.getInt("WinConditionParams.TechKoTime", 90); - - EnterStages = Collections.unmodifiableList(config.getIntegerList("EnterStages")); - AllowMissiles = config.getBoolean("Arena.AllowMissiles", !EnterStages.isEmpty()); - - KitFile = config.getString("Kits.File", "kits.yml"); - MemberDefault = config.getString("Kits.MemberDefault", "default"); - LeaderDefault = config.getString("Kits.LeaderDefault", "default"); - PersonalKits = config.getBoolean("Kits.PersonalKits", false); - ForbiddenItems = Collections.unmodifiableSet(config.getStringList("Kits.ForbiddenItems").stream().map(Material::valueOf).collect(Collectors.toSet())); - - TechhiderActive = config.getBoolean("Techhider.Active", false); - ObfuscateWith = Material.getMaterial(config.getString("Techhider.ObfuscateWith", "end_stone").toUpperCase()); - HiddenBlocks = config.getStringList("Techhider.HiddenBlocks").stream().map(String::toUpperCase).map(Material::getMaterial).collect(Collectors.toSet()); - HiddenBlockEntities = Collections.unmodifiableSet(new HashSet<>(config.getStringList("Techhider.HiddenBlockEntities"))); - - if(schemsizeX < 0){ - schemsizeX = -schemsizeX; - blueCornerX = blueCornerX - schemsizeX; - } - if(schemsizeY < 0){ - schemsizeY = -schemsizeY; - blueCornerY = blueCornerY - schemsizeY; - } - if(schemsizeZ < 0){ - schemsizeZ = -schemsizeZ; - blueCornerZ = blueCornerZ - schemsizeZ; - } - BlueToRedX = worldconfig.getInt("BlueToRed.x", 0); BlueToRedY = worldconfig.getInt("BlueToRed.y", 0); - BlueToRedZ = worldconfig.getInt("BlueToRed.z", schemsizeZ + 50); - double teamBlueSpawnOffsetX = config.getDouble("Arena.SpawnOffset.x", 0); - double teamBlueSpawnOffsetY = config.getDouble("Arena.SpawnOffset.y", schemsizeY); - double teamBlueSpawnOffsetZ = config.getDouble("Arena.SpawnOffset.z", 0); + BlueToRedZ = worldconfig.getInt("BlueToRed.z", GameModeConfig.Schematic.Size.z + 50); int teamRedCornerX = BlueToRedX + blueCornerX; int teamRedCornerY = BlueToRedY + blueCornerY; int teamRedCornerZ = BlueToRedZ + blueCornerZ; - int teamBluePasteX = blueCornerX + schemsizeX / 2; - int teamBluePasteZ = blueCornerZ + schemsizeZ / 2; + int teamBluePasteX = blueCornerX + GameModeConfig.Schematic.Size.x / 2; + int teamBluePasteZ = blueCornerZ + GameModeConfig.Schematic.Size.z / 2; int teamRedPasteX = teamBluePasteX + BlueToRedX; int teamRedPasteZ = teamBluePasteZ + BlueToRedZ; TeamBlueSpawn = new Location(world, - teamBluePasteX + 0.5 + teamBlueSpawnOffsetX, - blueCornerY + 0.5 + teamBlueSpawnOffsetY, - teamBluePasteZ + 0.5 + teamBlueSpawnOffsetZ); + teamBluePasteX + 0.5 + GameModeConfig.Arena.SpawnOffset.x, + blueCornerY + 0.5 + GameModeConfig.Arena.SpawnOffset.y, + teamBluePasteZ + 0.5 + GameModeConfig.Arena.SpawnOffset.z); TeamRedSpawn = new Location(world, - teamRedPasteX + 0.5 - teamBlueSpawnOffsetX, - teamRedCornerY + 0.5 + teamBlueSpawnOffsetY, - teamRedPasteZ + 0.5 - teamBlueSpawnOffsetZ); + teamRedPasteX + 0.5 - GameModeConfig.Arena.SpawnOffset.x, + teamRedCornerY + 0.5 + GameModeConfig.Arena.SpawnOffset.y, + teamRedPasteZ + 0.5 - GameModeConfig.Arena.SpawnOffset.z); SpecSpawn = new Location(world, teamBluePasteX + BlueToRedX /2.0, - blueCornerY + BlueToRedY /2.0 + schemsizeY/2.0, + blueCornerY + BlueToRedY /2.0 + GameModeConfig.Schematic.Size.y/2.0, teamBluePasteZ + BlueToRedZ /2.0); Vector v1 = TeamBlueSpawn.toVector().subtract(TeamRedSpawn.toVector()); @@ -288,45 +169,45 @@ public class Config { int arenaMinZ; int arenaMaxZ; if(BlueToRedX > 0){ - arenaMinX = blueCornerX - schem2BorderX; - arenaMaxX = teamRedCornerX + schemsizeX + schem2BorderX; + arenaMinX = blueCornerX - GameModeConfig.Arena.Schem2Border.x; + arenaMaxX = teamRedCornerX + GameModeConfig.Schematic.Size.x + GameModeConfig.Arena.Schem2Border.x; teamRedRotate = true; teamBlueRotate = false; }else{ - arenaMinX = teamRedCornerX - schem2BorderX; - arenaMaxX = blueCornerX + schemsizeX + schem2BorderX; + arenaMinX = teamRedCornerX - GameModeConfig.Arena.Schem2Border.x; + arenaMaxX = blueCornerX + GameModeConfig.Schematic.Size.x + GameModeConfig.Arena.Schem2Border.x; teamRedRotate = false; teamBlueRotate = true; } if(BlueToRedZ > 0){ - arenaMinZ = blueCornerZ - schem2BorderZ; - arenaMaxZ = teamRedCornerZ + schemsizeZ + schem2BorderZ; + arenaMinZ = blueCornerZ - GameModeConfig.Arena.Schem2Border.z; + arenaMaxZ = teamRedCornerZ + GameModeConfig.Schematic.Size.z + GameModeConfig.Arena.Schem2Border.z; teamRedRotate = true; teamBlueRotate = false; }else{ - arenaMinZ = teamRedCornerZ - schem2BorderZ; - arenaMaxZ = blueCornerZ + schemsizeZ + schem2BorderZ; + arenaMinZ = teamRedCornerZ - GameModeConfig.Arena.Schem2Border.z; + arenaMaxZ = blueCornerZ + GameModeConfig.Schematic.Size.z + GameModeConfig.Arena.Schem2Border.z; if(BlueToRedZ != 0){ teamRedRotate = false; teamBlueRotate = true; } } - if(!rotate){ + if(!GameModeConfig.Schematic.Rotate){ teamRedRotate = false; teamBlueRotate = false; } RedRotate = teamRedRotate; BlueRotate = teamBlueRotate; - RedPasteRegion = Region.fromSize(teamRedCornerX, teamRedCornerY, teamRedCornerZ, schemsizeX, schemsizeY, schemsizeZ); - BluePasteRegion = Region.fromSize(blueCornerX, blueCornerY, blueCornerZ, schemsizeX, schemsizeY, schemsizeZ); + RedPasteRegion = Region.fromSize(teamRedCornerX, teamRedCornerY, teamRedCornerZ, GameModeConfig.Schematic.Size.x, GameModeConfig.Schematic.Size.y, GameModeConfig.Schematic.Size.z); + BluePasteRegion = Region.fromSize(blueCornerX, blueCornerY, blueCornerZ, GameModeConfig.Schematic.Size.x, GameModeConfig.Schematic.Size.y, GameModeConfig.Schematic.Size.z); - RedExtendRegion = Region.withExtension(teamRedCornerX, teamRedCornerY, teamRedCornerZ, schemsizeX, schemsizeY, schemsizeZ, PreperationArea, PreperationArea, PreperationArea); - BlueExtendRegion = Region.withExtension(blueCornerX, blueCornerY, blueCornerZ, schemsizeX, schemsizeY, schemsizeZ, PreperationArea, PreperationArea, PreperationArea); - ArenaRegion = Region.withExtension(arenaMinX, blueCornerY, arenaMinZ, arenaMaxX - arenaMinX, schemsizeY, arenaMaxZ - arenaMinZ, 0, PreperationArea, 0); + RedExtendRegion = Region.withExtension(teamRedCornerX, teamRedCornerY, teamRedCornerZ, GameModeConfig.Schematic.Size.x, GameModeConfig.Schematic.Size.y, GameModeConfig.Schematic.Size.z, GameModeConfig.Arena.BorderFromSchematic, GameModeConfig.Arena.BorderFromSchematic, GameModeConfig.Arena.BorderFromSchematic); + BlueExtendRegion = Region.withExtension(blueCornerX, blueCornerY, blueCornerZ, GameModeConfig.Schematic.Size.x, GameModeConfig.Schematic.Size.y, GameModeConfig.Schematic.Size.z, GameModeConfig.Arena.BorderFromSchematic, GameModeConfig.Arena.BorderFromSchematic, GameModeConfig.Arena.BorderFromSchematic); + ArenaRegion = Region.withExtension(arenaMinX, blueCornerY, arenaMinZ, arenaMaxX - arenaMinX, GameModeConfig.Schematic.Size.y, arenaMaxZ - arenaMinZ, 0, GameModeConfig.Arena.BorderFromSchematic, 0); PlayerRegion = new Region(arenaMinX, underBorder, arenaMinZ, arenaMaxX, world.getMaxHeight(), arenaMaxZ); - BlueInsetRegion = new Region(BluePasteRegion.getMinX() + schemInsetX, BluePasteRegion.getMinY() + schemInsetBottom, BluePasteRegion.getMinZ() + schemInsetZ, BluePasteRegion.getMaxX() - schemInsetX, BluePasteRegion.getMaxY() - schemInsetTop, BluePasteRegion.getMaxZ() - schemInsetZ); + BlueInsetRegion = new Region(BluePasteRegion.getMinX() + GameModeConfig.Schematic.Inset.x, BluePasteRegion.getMinY() + GameModeConfig.Schematic.Inset.bottom, BluePasteRegion.getMinZ() + GameModeConfig.Schematic.Inset.z, BluePasteRegion.getMaxX() - GameModeConfig.Schematic.Inset.x, BluePasteRegion.getMaxY() - GameModeConfig.Schematic.Inset.top, BluePasteRegion.getMaxZ() - GameModeConfig.Schematic.Inset.z); int eventKampfID = Integer.parseInt(System.getProperty("fightID", "0")); if(eventKampfID >= 1){ @@ -368,11 +249,11 @@ public class Config { } }else{ //No event - TeamRedColor = config.getString("Red.Prefix", "§c"); - TeamBlueColor = config.getString("Blue.Prefix", "§9"); - TeamRedName = config.getString("Red.Name", "Rot"); - TeamBlueName = config.getString("Blue.Name", "Blau"); - OnlyPublicSchematics = config.getBoolean("Schematic.OnlyPublicSchematics", false); + TeamRedColor = GameModeConfig.Red.Prefix; + TeamBlueColor = GameModeConfig.Blue.Prefix; + TeamRedName = GameModeConfig.Red.Name; + TeamBlueName = GameModeConfig.Blue.Name; + OnlyPublicSchematics = GameModeConfig.Schematic.OnlyPublicSchematics; EventTeamBlueID = 0; EventTeamRedID = 0; EventKampf = null; diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/DummyAI.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/DummyAI.java index eab9bfd3..fd7e108c 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/DummyAI.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/DummyAI.java @@ -43,7 +43,7 @@ public class DummyAI extends AI { @Override public SchematicNode chooseSchematic() { - List publics = SchematicNode.getAllSchematicsOfType(0, Config.SchematicType.toDB()); + List publics = SchematicNode.getAllSchematicsOfType(0, Config.GameModeConfig.Schematic.Type.toDB()); return publics.get(random.nextInt(publics.size())); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java index c5fc83fb..7119173e 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java @@ -149,8 +149,8 @@ public class Commands { return; Kit k = null; - if(Config.PersonalKits){ - PersonalKit kit = PersonalKit.get(SteamwarUser.get(p.getUniqueId()).getId(), Config.SchematicType.toDB(), kitName); + if(Config.GameModeConfig.Kits.PersonalKits){ + PersonalKit kit = PersonalKit.get(SteamwarUser.get(p.getUniqueId()).getId(), Config.GameModeConfig.Schematic.Type.toDB(), kitName); if(kit != null){ kit.setInUse(); k = new Kit(kit); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java index a365dc96..729ce0b6 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java @@ -152,8 +152,8 @@ public class GUI { List> entries = new ArrayList<>(); - if(Config.PersonalKits){ - List kits = PersonalKit.get(SteamwarUser.get(p.getUniqueId()).getId(), Config.SchematicType.toDB()); + if(Config.GameModeConfig.Kits.PersonalKits){ + List kits = PersonalKit.get(SteamwarUser.get(p.getUniqueId()).getId(), Config.GameModeConfig.Schematic.Type.toDB()); kits.forEach(kit -> entries.add(new SWListInv.SWListEntry<>(new SWItem(Material.LEATHER_CHESTPLATE, "§e" + kit.getName(), new ArrayList<>(), kit.isInUse(), clickType -> {}), new Kit(kit)))); }else{ List kitList = Kit.getAvailableKits(fightPlayer.isLeader()); @@ -169,19 +169,19 @@ public class GUI { if(entries.isEmpty()) { inv.setItem(22, new SWItem(Material.BARRIER, msg.parse("KIT_NO_KITS", p))); } - if(Config.PersonalKits){ + if(Config.GameModeConfig.Kits.PersonalKits){ inv.setItem(48, Material.NETHER_STAR, msg.parse("KIT_CREATE", p), clickType -> { SWAnvilInv anvilInv = new SWAnvilInv(p, msg.parse("KITNAME_TITLE", p)); anvilInv.setItem(Material.LEATHER_CHESTPLATE); anvilInv.setCallback(s -> { SteamwarUser user = SteamwarUser.get(p.getUniqueId()); - if(PersonalKit.get(user.getId(), Config.SchematicType.toDB(), s) != null) { + if(PersonalKit.get(user.getId(), Config.GameModeConfig.Schematic.Type.toDB(), s) != null) { msg.sendPrefixless("KITNAME_IN_USE", p, ChatMessageType.ACTION_BAR); p.closeInventory(); return; } Kit prototype = Kit.getAvailableKits(Fight.getFightPlayer(p).isLeader()).get(0); - PersonalKit kit = PersonalKit.create(user.getId(), Config.SchematicType.toDB(), s, prototype.getInventory(), prototype.getArmor()); + PersonalKit kit = PersonalKit.create(user.getId(), Config.GameModeConfig.Schematic.Type.toDB(), s, prototype.getInventory(), prototype.getArmor()); PersonalKitCreator.openKitCreator(p, kit); }); anvilInv.open(); @@ -202,14 +202,14 @@ public class GUI { return; } - int invSize = (Config.SubTypes.size() + 1) * 9; - SWInventory inv = new SWInventory(p, invSize, msg.parse("SCHEM_TITLE", p, Config.GameName)); - setupSchemTypeRow(p, inv, Config.SchematicType, 0); - for (int i = 0; i < Config.SubTypes.size(); i++) { - setupSchemTypeRow(p, inv, Config.SubTypes.get(i), i + 1); + int invSize = (Config.GameModeConfig.Schematic.SubTypes.size() + 1) * 9; + SWInventory inv = new SWInventory(p, invSize, msg.parse("SCHEM_TITLE", p, Config.GameModeConfig.GameName)); + setupSchemTypeRow(p, inv, Config.GameModeConfig.Schematic.Type, 0); + for (int i = 0; i < Config.GameModeConfig.Schematic.SubTypes.size(); i++) { + setupSchemTypeRow(p, inv, Config.GameModeConfig.Schematic.SubTypes.get(i), i + 1); } if (!Config.test() && SteamwarUser.get(p.getUniqueId()).hasPerm(UserPerm.TEAM)) { - SchematicNode node = SchematicNode.getSchematicNode(-1, Config.GameName, (Integer) null); + SchematicNode node = SchematicNode.getSchematicNode(-1, Config.GameModeConfig.GameName, (Integer) null); if (node != null) { inv.setItem(2, new SWItem(SWItem.getMaterial(node.getItem()), msg.parse("SCHEM_DIRT", p), click -> { schemSelect(p, node); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EnternCountdown.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EnternCountdown.java index 1a019c3a..80d41fd0 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EnternCountdown.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EnternCountdown.java @@ -36,10 +36,10 @@ import java.util.List; public class EnternCountdown extends Countdown { private static int calcTime(FightPlayer fp, Countdown countdown) { - int time = Config.EnterStages.get(fp.getKit().getEnterStage()); + int time = Config.GameModeConfig.EnterStages.get(fp.getKit().getEnterStage()); if(countdown != null) { - time -= Config.TimeoutTime - countdown.getTimeLeft(); + time -= Config.GameModeConfig.WinConditionParams.TimeoutTime - countdown.getTimeLeft(); if(time < 0) time = 0; diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EventSpectateCountdown.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EventSpectateCountdown.java index 64b02810..9f8d2503 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EventSpectateCountdown.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EventSpectateCountdown.java @@ -32,7 +32,7 @@ import de.steamwar.linkage.Linked; public class EventSpectateCountdown extends Countdown { public EventSpectateCountdown() { - super(Config.SpectatorDuration, new Message("SHUTDOWN_COUNTDOWN"), SWSound.BLOCK_NOTE_PLING, false); + super(Config.GameModeConfig.Times.SpectatorDuration, new Message("SHUTDOWN_COUNTDOWN"), SWSound.BLOCK_NOTE_PLING, false); new StateDependentCountdown(ArenaMode.NotRestartable.contains(Config.mode) && !Config.replayserver(), FightState.Spectate, this); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/countdown/NoPlayersOnlineCountdown.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/countdown/NoPlayersOnlineCountdown.java index 0fefdae2..467854e0 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/countdown/NoPlayersOnlineCountdown.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/countdown/NoPlayersOnlineCountdown.java @@ -31,9 +31,9 @@ import org.bukkit.Bukkit; public class NoPlayersOnlineCountdown extends Countdown { public NoPlayersOnlineCountdown() { - super(Config.NoPlayerOnlineDuration, new Message("SHUTDOWN_COUNTDOWN"), null, false); + super(Config.GameModeConfig.Times.NoPlayersOnlineDuration, new Message("SHUTDOWN_COUNTDOWN"), null, false); - if (!Config.ArenaLeaveable) + if (!Config.GameModeConfig.Arena.Leaveable) new StateDependentCountdown(ArenaMode.AntiReplay, FightState.PreLeaderSetup, this); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/countdown/PostSchemCountdown.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/countdown/PostSchemCountdown.java index 262ee06d..4c15fa07 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/countdown/PostSchemCountdown.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/countdown/PostSchemCountdown.java @@ -30,8 +30,8 @@ import de.steamwar.linkage.Linked; public class PostSchemCountdown extends Countdown { public PostSchemCountdown() { - super(Config.SetupDuration, new Message("POST_SCHEM_COUNTDOWN"), null, false); - if(Config.mode == ArenaMode.PREPARE && Config.UnlimitedPrepare) + super(Config.GameModeConfig.Times.SetupDuration, new Message("POST_SCHEM_COUNTDOWN"), null, false); + if(Config.mode == ArenaMode.PREPARE && Config.GameModeConfig.Schematic.UnlimitedPrepare) return; new StateDependentCountdown(ArenaMode.SeriousFight, FightState.PostSchemSetup, this); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/countdown/PreRunningCountdown.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/countdown/PreRunningCountdown.java index 4e6e21de..45b8202e 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/countdown/PreRunningCountdown.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/countdown/PreRunningCountdown.java @@ -31,7 +31,7 @@ import de.steamwar.linkage.Linked; public class PreRunningCountdown extends Countdown { public PreRunningCountdown() { - super(Config.PreFightDuration, new Message("PRE_RUNNING_COUNTDOWN"), SWSound.BLOCK_NOTE_PLING, true); + super(Config.GameModeConfig.Times.PreFightDuration, new Message("PRE_RUNNING_COUNTDOWN"), SWSound.BLOCK_NOTE_PLING, true); new StateDependentCountdown(ArenaMode.AntiReplay, FightState.PreRunning, this); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/countdown/PreSchemCountdown.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/countdown/PreSchemCountdown.java index a023b005..45a44296 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/countdown/PreSchemCountdown.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/countdown/PreSchemCountdown.java @@ -31,7 +31,7 @@ import de.steamwar.linkage.Linked; public class PreSchemCountdown extends Countdown { public PreSchemCountdown() { - super(Config.PreSchemPasteDuration, new Message("PRE_SCHEM_COUNTDOWN"), SWSound.BLOCK_NOTE_PLING, false); + super(Config.GameModeConfig.Times.PreSchemPasteDuration, new Message("PRE_SCHEM_COUNTDOWN"), SWSound.BLOCK_NOTE_PLING, false); new StateDependentCountdown(ArenaMode.AntiReplay, FightState.PreSchemSetup, this); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/countdown/SpectateOverCountdown.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/countdown/SpectateOverCountdown.java index fca8fa28..4844536a 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/countdown/SpectateOverCountdown.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/countdown/SpectateOverCountdown.java @@ -31,7 +31,7 @@ import de.steamwar.linkage.Linked; public class SpectateOverCountdown extends Countdown { public SpectateOverCountdown() { - super(Config.test() ? 3600 : Config.SpectatorDuration, new Message("SPECTATE_COUNTDOWN"), SWSound.BLOCK_NOTE_PLING, false); + super(Config.test() ? 3600 : Config.GameModeConfig.Times.SpectatorDuration, new Message("SPECTATE_COUNTDOWN"), SWSound.BLOCK_NOTE_PLING, false); new StateDependentCountdown(ArenaMode.Restartable.contains(Config.mode) || Config.replayserver(), FightState.Spectate, this); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/countdown/TimeOverCountdown.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/countdown/TimeOverCountdown.java index 600e9a4f..ed90d5e9 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/countdown/TimeOverCountdown.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/countdown/TimeOverCountdown.java @@ -28,7 +28,7 @@ public class TimeOverCountdown extends Countdown { private final Runnable timeOver; public TimeOverCountdown(Runnable timeOver) { - super(Config.TimeoutTime, new Message("RUNNING_COUNTDOWN"), SWSound.BLOCK_NOTE_BASS, false); + super(Config.GameModeConfig.WinConditionParams.TimeoutTime, new Message("RUNNING_COUNTDOWN"), SWSound.BLOCK_NOTE_BASS, false); this.timeOver = timeOver; } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java index 53bd6734..8d983b56 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java @@ -102,7 +102,7 @@ public class Fight { if (Config.OnlyPublicSchematics) { return true; } - if (Config.IgnorePublicOnly || ArenaMode.RankedEvent.contains(Config.mode)) { + if (Config.GameModeConfig.Schematic.IgnorePublicOnly || ArenaMode.RankedEvent.contains(Config.mode)) { return false; } if (redTeam.getLeader() == null || blueTeam.getLeader() == null) { diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightPlayer.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightPlayer.java index 91a967e5..a5d605aa 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightPlayer.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightPlayer.java @@ -53,9 +53,9 @@ public class FightPlayer { this.entity = entity; this.team = team; this.isOut = false; - kit = Kit.getKitByName(Config.MemberDefault); - if(Config.PersonalKits){ - PersonalKit personalKit = PersonalKit.getKitInUse(user.getId(), Config.SchematicType.toDB()); + kit = Kit.getKitByName(Config.GameModeConfig.Kits.MemberDefault); + if(Config.GameModeConfig.Kits.PersonalKits){ + PersonalKit personalKit = PersonalKit.getKitInUse(user.getId(), Config.GameModeConfig.Schematic.Type.toDB()); if(personalKit != null){ kit = new Kit(personalKit); } @@ -75,7 +75,7 @@ public class FightPlayer { } public void startEnternCountdown(Countdown countdown) { - if(Config.EnterStages.size() > kit.getEnterStage() && kit.getEnterStage() >= 0) + if(Config.GameModeConfig.EnterStages.size() > kit.getEnterStage() && kit.getEnterStage() >= 0) enternCountdown = new EnternCountdown(this, countdown); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java index cfca90ac..a9f38555 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -115,9 +115,9 @@ public class FightSchematic extends StateDependent { return; if(clipboard == null){ - List publics = SchematicNode.getAllSchematicsOfType(0, Config.SchematicType.toDB()); + List publics = SchematicNode.getAllSchematicsOfType(0, Config.GameModeConfig.Schematic.Type.toDB()); if(publics.isEmpty()) { - for (SchematicType type : Config.SubTypes) { + for (SchematicType type : Config.GameModeConfig.Schematic.SubTypes) { publics = SchematicNode.getAllSchematicsOfType(0, type.toDB()); if (!publics.isEmpty()) { break; @@ -133,7 +133,7 @@ public class FightSchematic extends StateDependent { if(ArenaMode.AntiReplay.contains(Config.mode)) { boolean changeRotation = false; - if (Config.ActiveWinconditions.contains(Winconditions.RANDOM_ROTATE)) { + if (Config.GameModeConfig.WinConditions.contains(Winconditions.RANDOM_ROTATE)) { changeRotation = new Random().nextBoolean(); usedRotate = rotate ^ changeRotation; } @@ -163,9 +163,9 @@ public class FightSchematic extends StateDependent { clipboard, new Location(Config.world, region.centerX(), region.getMinY(), region.centerZ()), new Vector( - Config.PasteAligned && Config.BlueToRedX != 0 ? region.getSizeX()/2.0 - dims.getBlockX() : -dims.getBlockX()/2.0, - Config.WaterDepth != 0 ? Config.WaterDepth - WorldeditWrapper.impl.getWaterDepth(clipboard) : 0, - Config.PasteAligned && Config.BlueToRedZ != 0 ? region.getSizeZ()/2.0 - dims.getBlockZ() : -dims.getBlockZ()/2.0 + Config.GameModeConfig.Schematic.PasteAligned && Config.BlueToRedX != 0 ? region.getSizeX()/2.0 - dims.getBlockX() : -dims.getBlockX()/2.0, + Config.GameModeConfig.Arena.WaterDepth != 0 ? Config.GameModeConfig.Arena.WaterDepth - WorldeditWrapper.impl.getWaterDepth(clipboard) : 0, + Config.GameModeConfig.Schematic.PasteAligned && Config.BlueToRedZ != 0 ? region.getSizeZ()/2.0 - dims.getBlockZ() : -dims.getBlockZ()/2.0 ).add(new Vector(usedRotate ? 1 : 0, 0, usedRotate ? 1 : 0)), new AffineTransform().rotateY(usedRotate ? 180 : 0) ); @@ -179,17 +179,17 @@ public class FightSchematic extends StateDependent { @Override public void disable() { - if(!Config.ReplaceObsidianBedrock || Config.mode == ArenaMode.PREPARE) + if(!Config.GameModeConfig.Schematic.ReplaceObsidianBedrock || Config.mode == ArenaMode.PREPARE) return; FreezeWorld freezer = null; - if(!Config.ReplaceWithBlockupdates) + if(!Config.GameModeConfig.Schematic.ReplaceWithBlockupdates) freezer = new FreezeWorld(); replaceSync(Material.OBSIDIAN, Material.TNT); replaceSync(Material.BEDROCK, Material.SLIME_BLOCK); - if(!Config.ReplaceWithBlockupdates) + if(!Config.GameModeConfig.Schematic.ReplaceWithBlockupdates) freezer.disable(); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index 7418518f..768a2851 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -56,7 +56,7 @@ import java.util.function.Consumer; public class FightTeam { private static void setKitButton(HotbarKit kit, boolean leader) { - if (Kit.getAvailableKits(leader).size() > 1 || Config.PersonalKits) + if (Kit.getAvailableKits(leader).size() > 1 || Config.GameModeConfig.Kits.PersonalKits) kit.setItem(1, "CHOOSE_KIT", new ItemBuilder(Material.LEATHER_CHESTPLATE).enchant().build(), player -> GUI.kitSelection(player, "")); else kit.setItem(1, null, null, null); @@ -144,7 +144,7 @@ public class FightTeam { WorldOfColorWrapper.impl.setTeamColor(team, color); BountifulWrapper.impl.setNametagVisibility(team); team.setNameTagVisibility(NameTagVisibility.HIDE_FOR_OTHER_TEAMS); - if (!Config.ActiveWinconditions.contains(Winconditions.AMONG_US)) { + if (!Config.GameModeConfig.WinConditions.contains(Winconditions.AMONG_US)) { team.setAllowFriendlyFire(false); } @@ -357,10 +357,10 @@ public class FightTeam { if(!silent) FightUI.addSubtitle("UI_LEADER_JOINS", prefix, leader.getEntity().getName()); - publicsOnly = SchematicNode.getAllAccessibleSchematicsOfType(leader.getUser().getId(), Config.SchematicType.toDB()).isEmpty(); + publicsOnly = SchematicNode.getAllAccessibleSchematicsOfType(leader.getUser().getId(), Config.GameModeConfig.Schematic.Type.toDB()).isEmpty(); - if(!Config.PersonalKits) - leader.setKit(Kit.getKitByName(Config.LeaderDefault)); + if(!Config.GameModeConfig.Kits.PersonalKits) + leader.setKit(Kit.getKitByName(Config.GameModeConfig.Kits.LeaderDefault)); leader.ifPlayer(player -> { if(FightState.getFightState() != FightState.POST_SCHEM_SETUP) @@ -417,7 +417,7 @@ public class FightTeam { public void setSchem(SchematicNode schematic, int revision){ this.schematic.setSchematic(schematic, revision); - broadcast("SCHEMATIC_CHOSEN", Config.GameName, schematic.getName()); + broadcast("SCHEMATIC_CHOSEN", Config.GameModeConfig.GameName, schematic.getName()); } public void setReady(boolean ready) { diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightWorld.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightWorld.java index 764de118..36a7c6fa 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightWorld.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightWorld.java @@ -71,7 +71,7 @@ public class FightWorld extends StateDependent { public static void resetWorld(){ List entities = new ArrayList<>(); Recording.iterateOverEntities(Objects::nonNull, entity -> { - if(entity.getType() != EntityType.PLAYER && (!Config.ArenaLeaveable || Config.ArenaRegion.inRegion(entity.getLocation()))) + if(entity.getType() != EntityType.PLAYER && (!Config.GameModeConfig.Arena.Leaveable || Config.ArenaRegion.inRegion(entity.getLocation()))) entities.add(entity); }); entities.forEach(Entity::remove); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/HotbarKit.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/HotbarKit.java index 17edca7e..01d20315 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/HotbarKit.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/HotbarKit.java @@ -71,7 +71,7 @@ public class HotbarKit extends Kit { for(int i = 0; i < HOTBAR_SIZE; i++) { if(nameTags[i] != null) { ItemMeta meta = Objects.requireNonNull(getInventory()[i].getItemMeta()); - meta.setDisplayName(FightSystem.getMessage().parse(nameTags[i], player, Config.GameName)); + meta.setDisplayName(FightSystem.getMessage().parse(nameTags[i], player, Config.GameModeConfig.GameName)); getInventory()[i].setItemMeta(meta); } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java index 8183d98c..0bba6ae5 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java @@ -49,7 +49,7 @@ import java.util.*; import java.util.logging.Level; public class Kit { - private static final File kits = new File(FightSystem.getPlugin().getDataFolder(), Config.KitFile); + private static final File kits = new File(FightSystem.getPlugin().getDataFolder(), Config.GameModeConfig.Kits.File); private static final ArrayList loadedKits = new ArrayList<>(); protected static final Map activeKits = new HashMap<>(); @@ -179,7 +179,7 @@ public class Kit { } public void removeBadItems(){ - Kit normal = Kit.getKitByName(Config.MemberDefault); + Kit normal = Kit.getKitByName(Config.GameModeConfig.Kits.MemberDefault); assert normal != null; for(int i = 0; i < inventory.length; i++){ @@ -194,7 +194,7 @@ public class Kit { return false; //Check for forbidden item - if(Config.ForbiddenItems.contains(stack.getType())) + if(Config.GameModeConfig.Kits.ForbiddenItems.contains(stack.getType())) return true; //Check for attribute modifiers @@ -211,7 +211,7 @@ public class Kit { return true; //Blocks prefilled inventories } - Kit normal = Kit.getKitByName(Config.MemberDefault); + Kit normal = Kit.getKitByName(Config.GameModeConfig.Kits.MemberDefault); assert normal != null; return !normal.isEnchantmentInKit(stack) && !stack.getEnchantments().isEmpty(); } @@ -303,8 +303,8 @@ public class Kit { } inv.setCallback(-999, click -> player.closeInventory()); - if(Config.PersonalKits){ - inv.setItem(49, SWItem.getMaterial("WOOD_AXE"), FightSystem.getMessage().parse("KIT_PREVIEW_EDIT", player), clickType -> PersonalKitCreator.openKitCreator(player, PersonalKit.get(SteamwarUser.get(player.getUniqueId()).getId(), Config.SchematicType.toDB(), name))); + if(Config.GameModeConfig.Kits.PersonalKits){ + inv.setItem(49, SWItem.getMaterial("WOOD_AXE"), FightSystem.getMessage().parse("KIT_PREVIEW_EDIT", player), clickType -> PersonalKitCreator.openKitCreator(player, PersonalKit.get(SteamwarUser.get(player.getUniqueId()).getId(), Config.GameModeConfig.Schematic.Type.toDB(), name))); inv.setItem(53, Material.BARRIER, FightSystem.getMessage().parse("KIT_PREVIEW_DELETE", player), clickType -> { player.closeInventory(); SWInventory conf = new SWInventory(player, 9, FightSystem.getMessage().parse("KIT_DELETION_CONFIRMATION", player)); @@ -312,9 +312,9 @@ public class Kit { conf.setItem(0, SWItem.getDye(10), FightSystem.getMessage().parse("KIT_DELETION_DELETE", player), click -> { player.closeInventory(); SteamwarUser user = SteamwarUser.get(player.getUniqueId()); - PersonalKit kit = PersonalKit.get(user.getId(), Config.SchematicType.toDB(), name); + PersonalKit kit = PersonalKit.get(user.getId(), Config.GameModeConfig.Schematic.Type.toDB(), name); if(kit.isInUse()) { - List kits = PersonalKit.get(user.getId(), Config.SchematicType.toDB()); + List kits = PersonalKit.get(user.getId(), Config.GameModeConfig.Schematic.Type.toDB()); if(!kits.isEmpty()){ PersonalKit kit1 = kits.get(0); kit1.setInUse(); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArenaBorder.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArenaBorder.java index 57d8ec6a..16c125c3 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArenaBorder.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArenaBorder.java @@ -47,7 +47,7 @@ public class ArenaBorder implements Listener { public ArenaBorder() { new StateDependentListener(ArenaMode.All, FightState.All, this); new StateDependentTask(ArenaMode.All, FightState.Running, this::damage, 2, 2); - new StateDependentListener(!Config.GroundWalkable, FightState.AntiRunning, new Listener() { + new StateDependentListener(!Config.GameModeConfig.Arena.GroundWalkable, FightState.AntiRunning, new Listener() { @EventHandler public void onMove(PlayerMoveEvent e) { Player player = e.getPlayer(); @@ -102,7 +102,7 @@ public class ArenaBorder implements Listener { } private void addToSpectator(Player player) { - if(Config.ArenaLeaveable || !player.isOnline() || playerBorder.contains(player)) + if(Config.GameModeConfig.Arena.Leaveable || !player.isOnline() || playerBorder.contains(player)) return; spectatorBorder.addPlayer(player); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java index 926ef27b..19d2db5f 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java @@ -40,7 +40,7 @@ public class ArrowStopper { private static final BlockFace[] BLOCK_FACES = {BlockFace.UP, BlockFace.DOWN, BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH}; public ArrowStopper() { - new StateDependentTask(Config.TechhiderActive, FightState.Running, this::run, 1, 1); + new StateDependentTask(Config.GameModeConfig.Techhider.Active, FightState.Running, this::run, 1, 1); } private static final Class entityArrow = Reflection.getClass("net.minecraft.world.entity.projectile.AbstractArrow"); @@ -87,7 +87,7 @@ public class ArrowStopper { } private boolean checkBlock(Block block) { - return Config.HiddenBlocks.contains(block.getType()); + return Config.GameModeConfig.Techhider.HiddenBlocks.contains(block.getType()); } private boolean invalidEntity(Projectile entity) { diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/BlockFadeListener.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/BlockFadeListener.java index 4cf9a3d1..55179a5b 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/BlockFadeListener.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/BlockFadeListener.java @@ -32,7 +32,7 @@ import org.bukkit.event.block.BlockFadeEvent; public class BlockFadeListener implements Listener { public BlockFadeListener() { - new StateDependentListener(Config.DisableSnowMelt, FightState.All, this); + new StateDependentListener(Config.GameModeConfig.Arena.DisableSnowMelt, FightState.All, this); } @EventHandler diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Chat.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Chat.java index 610c5859..00a5c41e 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Chat.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Chat.java @@ -51,7 +51,7 @@ public class Chat implements Listener { FightTeam fightTeam = Fight.getPlayerTeam(player); if(fightTeam != null) { String teamName = fightTeam.getColoredName(); - if(message.startsWith(Config.TeamChatDetection)) { + if(message.startsWith(Config.GameModeConfig.TeamChatPrefix)) { fightTeam.broadcastChat(player, message.substring(1)); } else { broadcastChat("PARTICIPANT_CHAT", teamName, player.getName(), message); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/DenyWorldInteraction.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/DenyWorldInteraction.java index 91c76db1..f21fb3d4 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/DenyWorldInteraction.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/DenyWorldInteraction.java @@ -82,13 +82,13 @@ public class DenyWorldInteraction implements Listener { @EventHandler public void handleEntityExplode(EntityExplodeEvent event) { - if(!Config.ArenaLeaveable || Config.ArenaRegion.inRegion(event.getLocation())) + if(!Config.GameModeConfig.Arena.Leaveable || Config.ArenaRegion.inRegion(event.getLocation())) event.setCancelled(true); } @EventHandler public void handleBlockBurn(BlockIgniteEvent event) { - if(!Config.ArenaLeaveable || Config.ArenaRegion.inRegion(event.getBlock())) + if(!Config.GameModeConfig.Arena.Leaveable || Config.ArenaRegion.inRegion(event.getBlock())) event.setCancelled(true); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/InFightDamage.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/InFightDamage.java index 5a2d2cfc..3fc94b27 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/InFightDamage.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/InFightDamage.java @@ -39,7 +39,7 @@ import java.util.Objects; public class InFightDamage implements Listener { public InFightDamage() { - new StateDependentListener(!Config.ActiveWinconditions.contains(Winconditions.AMONG_US), FightState.Running, this); + new StateDependentListener(!Config.GameModeConfig.WinConditions.contains(Winconditions.AMONG_US), FightState.Running, this); } @EventHandler diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/JoinRequestListener.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/JoinRequestListener.java index 5a6d8d20..267b32c2 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/JoinRequestListener.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/JoinRequestListener.java @@ -54,7 +54,7 @@ public class JoinRequestListener implements Listener { Player player = event.getPlayer(); FightPlayer fp = Fight.getFightPlayer(player); - if (!Config.ArenaLeaveable && (fp == null || !fp.isLiving())) { + if (!Config.GameModeConfig.Arena.Leaveable && (fp == null || !fp.isLiving())) { HotbarKit.SPECTATOR_KIT.loadToPlayer(player); } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/LeaveableArena.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/LeaveableArena.java index 6daa719b..d08df0f2 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/LeaveableArena.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/LeaveableArena.java @@ -42,7 +42,7 @@ public class LeaveableArena implements Listener { private final Map spectatorsInArena = new HashMap<>(); public LeaveableArena() { - new StateDependentListener(Config.ArenaLeaveable, FightState.All, this); + new StateDependentListener(Config.GameModeConfig.Arena.Leaveable, FightState.All, this); } @EventHandler(priority = EventPriority.MONITOR) diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java index 444eb1a1..f4489caf 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java @@ -99,7 +99,7 @@ public class Permanent implements Listener { Player player = event.getPlayer(); FightPlayer fp = Fight.getFightPlayer(player); - if (!Config.ArenaLeaveable && fp == null) { + if (!Config.GameModeConfig.Arena.Leaveable && fp == null) { player.setGameMode(GameMode.SPECTATOR); spectatorTeam.addEntry(player.getName()); player.teleport(Config.SpecSpawn); @@ -111,13 +111,13 @@ public class Permanent implements Listener { @EventHandler(priority = EventPriority.MONITOR) public void handlePlayerDeath(PlayerDeathEvent event) { - if(!Config.ArenaLeaveable || Fight.fighting(event.getEntity())) + if(!Config.GameModeConfig.Arena.Leaveable || Fight.fighting(event.getEntity())) event.setDeathMessage(null); } @EventHandler(priority = EventPriority.MONITOR) public void handlePlayerLeave(PlayerQuitEvent event) { - if(!Config.ArenaLeaveable) + if(!Config.GameModeConfig.Arena.Leaveable) event.setQuitMessage(null); } @@ -163,8 +163,8 @@ public class Permanent implements Listener { Player player = e.getPlayer(); ItemStack stack = e.getItem().getItemStack(); - if(Config.PersonalKits) { - if(Config.ForbiddenItems.contains(stack.getType())) { + if(Config.GameModeConfig.Kits.PersonalKits) { + if(Config.GameModeConfig.Kits.ForbiddenItems.contains(stack.getType())) { e.setCancelled(true); } } else { @@ -192,7 +192,7 @@ public class Permanent implements Listener { @EventHandler public void onWorldLoad(WorldLoadEvent e) { - if(!Config.ArenaLeaveable) + if(!Config.GameModeConfig.Arena.Leaveable) e.getWorld().setAutoSave(false); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java index 02fb7487..422e2a94 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java @@ -53,7 +53,7 @@ public class PersonalKitCreator implements Listener { private static final Map openKitCreators = new HashMap<>(); public PersonalKitCreator(){ - new StateDependentListener(Config.PersonalKits, FightState.Setup, this); + new StateDependentListener(Config.GameModeConfig.Kits.PersonalKits, FightState.Setup, this); } public static void openKitCreator(Player player, PersonalKit kit){ diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/PistonListener.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/PistonListener.java index cb583a08..a7dffacb 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/PistonListener.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/PistonListener.java @@ -45,8 +45,8 @@ public class PistonListener implements Listener { return; //Wenn Entern aktiv ist, sollen Raketen etc. entern können - new StateDependentListener(!Config.AllowMissiles, FightState.All, this); - new StateDependentListener(Config.AllowMissiles, FightState.Setup, this); + new StateDependentListener(!Config.GameModeConfig.Arena.AllowMissiles, FightState.All, this); + new StateDependentListener(Config.GameModeConfig.Arena.AllowMissiles, FightState.Setup, this); } @EventHandler diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java index 1da8cb58..151a74ce 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java @@ -85,7 +85,7 @@ public class PrepareSchem implements Listener { return; } - schem.setSchemtype(Config.SchematicType.checkType()); + schem.setSchemtype(Config.GameModeConfig.Schematic.Type.checkType()); schem.setPrepared(true); try{ diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Shutdown.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Shutdown.java index 5fc5e4b4..c298ba7e 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Shutdown.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Shutdown.java @@ -38,7 +38,7 @@ public class Shutdown implements Listener { @EventHandler public void handlePlayerQuit(PlayerQuitEvent event) { - if(Config.replayserver() || Config.ArenaLeaveable) + if(Config.replayserver() || Config.GameModeConfig.Arena.Leaveable) return; //Shutdown server if nobody online diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/WaterRemover.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/WaterRemover.java index ac39a7fc..c8dda3cb 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/WaterRemover.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/WaterRemover.java @@ -42,7 +42,7 @@ import java.util.Map; @Linked public class WaterRemover implements Listener { - private static final int MIN_Y = Config.BluePasteRegion.getMinY() + Config.WaterDepth; + private static final int MIN_Y = Config.BluePasteRegion.getMinY() + Config.GameModeConfig.Arena.WaterDepth; private final Map tnt = new HashMap<>(); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java index ccb6d085..8628d3fb 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -90,8 +90,8 @@ public class PacketProcessor implements Listener { private final PacketSource source; private final BukkitTask task; private final LinkedList syncList = new LinkedList<>(); - private final Set hiddenBlockIds = Config.HiddenBlocks.stream().flatMap(m -> BlockIds.impl.materialToAllIds(m).stream()).collect(Collectors.toSet()); - private final int obfuscateWith = BlockIds.impl.materialToId(Config.ObfuscateWith); + private final Set hiddenBlockIds = Config.GameModeConfig.Techhider.HiddenBlocks.stream().flatMap(m -> BlockIds.impl.materialToAllIds(m).stream()).collect(Collectors.toSet()); + private final int obfuscateWith = BlockIds.impl.materialToId(Config.GameModeConfig.Techhider.ObfuscateWith); private final FreezeWorld freezer = new FreezeWorld(); private final REntityServer entityServer = new REntityServer(); private final Map entities = new HashMap<>(); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/states/OneShotStateDependent.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/states/OneShotStateDependent.java index a09ea35c..afa992ca 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/states/OneShotStateDependent.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/states/OneShotStateDependent.java @@ -36,7 +36,7 @@ public class OneShotStateDependent extends StateDependent{ } public OneShotStateDependent(Winconditions wincondition, Set states, Runnable runnable) { - super(Config.ActiveWinconditions.contains(wincondition), states); + super(Config.GameModeConfig.WinConditions.contains(wincondition), states); this.runnable = runnable; register(); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/states/StateDependent.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/states/StateDependent.java index 53fa852e..56bee0ec 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/states/StateDependent.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/states/StateDependent.java @@ -31,7 +31,7 @@ public abstract class StateDependent implements IStateDependent { private final boolean register; protected StateDependent(Winconditions wincondition, Set states){ - this(Config.ActiveWinconditions.contains(wincondition), states); + this(Config.GameModeConfig.WinConditions.contains(wincondition), states); } protected StateDependent(Set mode, Set states){ diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/states/StateDependentCountdown.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/states/StateDependentCountdown.java index 3ad3bc4c..df8a93d5 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/states/StateDependentCountdown.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/states/StateDependentCountdown.java @@ -43,7 +43,7 @@ public class StateDependentCountdown extends StateDependent { } public StateDependentCountdown(Winconditions wincondition, Set states, Countdown countdown) { - this(Config.ActiveWinconditions.contains(wincondition), states, countdown); + this(Config.GameModeConfig.WinConditions.contains(wincondition), states, countdown); } public StateDependentCountdown(boolean active, Set states, Countdown countdown) { diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/states/StateDependentListener.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/states/StateDependentListener.java index c3c3a7cb..ba5c64b5 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/states/StateDependentListener.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/states/StateDependentListener.java @@ -34,7 +34,7 @@ public class StateDependentListener extends StateDependent{ private final Listener listener; public StateDependentListener(Winconditions wincondition, Set states, Listener listener){ - super(Config.ActiveWinconditions.contains(wincondition), states); + super(Config.GameModeConfig.WinConditions.contains(wincondition), states); this.listener = listener; register(); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/states/StateDependentTask.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/states/StateDependentTask.java index 7753d477..87e65f49 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/states/StateDependentTask.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/states/StateDependentTask.java @@ -37,7 +37,7 @@ public class StateDependentTask extends StateDependent { private BukkitTask task = null; public StateDependentTask(Winconditions wincondition, Set states, Runnable runnable, long delay, long period){ - this(Config.ActiveWinconditions.contains(wincondition), states, runnable, delay, period); + this(Config.GameModeConfig.WinConditions.contains(wincondition), states, runnable, delay, period); } public StateDependentTask(boolean enabled, Set states, Runnable runnable, long delay, long period){ diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/BungeeFightInfo.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/BungeeFightInfo.java index f01d7865..7d3b31f8 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/BungeeFightInfo.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/BungeeFightInfo.java @@ -43,7 +43,7 @@ public class BungeeFightInfo { private void send() { NetworkSender.send(new FightInfoPacket( Config.world.getName(), - Config.SchematicType.toDB(), + Config.GameModeConfig.Schematic.Type.toDB(), "", Fight.getBlueTeam().getColoredName(), Fight.getRedTeam().getColoredName(), diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java index 38931d74..f3cd3d5c 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java @@ -94,7 +94,7 @@ public class FightStatistics { private void disable() { FightTeam winner = FightSystem.getLastWinner(); String windescription = FightSystem.getLastWinreason(); - String gameMode = Config.SchematicType.toDB(); + String gameMode = Config.GameModeConfig.Schematic.Type.toDB(); Instant endTime = Instant.now(); int blueLeader = getLeader(Fight.getBlueTeam()); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java index 5c793107..60fbd3ac 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java @@ -42,7 +42,7 @@ public class Hull { private static final IntVector[] NO_BRANCHES = new IntVector[0]; private static boolean isOccluding(Material material) { - return material.isOccluding() || Config.HiddenBlocks.contains(material); + return material.isOccluding() || Config.GameModeConfig.Techhider.HiddenBlocks.contains(material); } @Getter diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java index 935a3a9f..d72e6949 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java @@ -50,7 +50,7 @@ import java.util.concurrent.ConcurrentHashMap; public class TechHiderWrapper extends StateDependent implements TechHider.LocationEvaluator, Listener { - public static final boolean ENABLED = !Config.OnlyPublicSchematics && !Config.test() && Config.TechhiderActive; + public static final boolean ENABLED = !Config.OnlyPublicSchematics && !Config.test() && Config.GameModeConfig.Techhider.Active; @Getter private final ConcurrentHashMap hiddenRegion = new ConcurrentHashMap<>(); @@ -60,7 +60,7 @@ public class TechHiderWrapper extends StateDependent implements TechHider.Locati public TechHiderWrapper() { super(ENABLED, FightState.Schem); - techHider = new TechHider(this, Config.ObfuscateWith, Config.HiddenBlocks, Config.HiddenBlockEntities); + techHider = new TechHider(this, Config.GameModeConfig.Techhider.ObfuscateWith, Config.GameModeConfig.Techhider.HiddenBlocks, Config.GameModeConfig.Techhider.HiddenBlockEntities); try { key = new SecretKeySpec(Files.readAllBytes(new File(System.getProperty("user.home"), "hullhider.key").toPath()), "AES"); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionBasePercent.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionBasePercent.java index afeca37d..73711f2b 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionBasePercent.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionBasePercent.java @@ -40,7 +40,7 @@ public abstract class WinconditionBasePercent extends Wincondition implements Pr private final Map teamMap = new HashMap<>(); protected Consumer checkWin = team -> { - if (getPercent(team) >= Config.PercentWin) { + if (getPercent(team) >= Config.GameModeConfig.WinConditionParams.PercentWin) { win(Fight.getOpposite(team), "WIN_PERCENT", team.getColoredName()); } }; @@ -49,7 +49,7 @@ public abstract class WinconditionBasePercent extends Wincondition implements Pr public WinconditionBasePercent(Winconditions wincondition, String windescription) { super(windescription); - if (Config.ActiveWinconditions.contains(wincondition)) { + if (Config.GameModeConfig.WinConditions.contains(wincondition)) { printableWinconditions.add(this); percentWincondition = this; } @@ -58,7 +58,7 @@ public abstract class WinconditionBasePercent extends Wincondition implements Pr } public Message getDisplay(FightTeam team) { - return new Message("BAR_PERCENT", team.getPrefix() + (Math.round(10000.0 * (1.0 - getPercent(team) / Config.PercentWin)) / 100.0)); + return new Message("BAR_PERCENT", team.getPrefix() + (Math.round(10000.0 * (1.0 - getPercent(team) / Config.GameModeConfig.WinConditionParams.PercentWin)) / 100.0)); } public double getPercent(FightTeam team) { @@ -93,13 +93,13 @@ public abstract class WinconditionBasePercent extends Wincondition implements Pr if ( event.getEntityType() == EntityType.FIREBALL || !team.getExtendRegion().inRegion(event.getEntity().getLocation()) || - (!Config.PercentEntern && !Config.EnterStages.isEmpty() && Config.EnterStages.get(0) >= Wincondition.getTimeOverCountdown().getTimeLeft()) + (!Config.GameModeConfig.WinConditionParams.PercentEntern && !Config.GameModeConfig.EnterStages.isEmpty() && Config.GameModeConfig.EnterStages.get(0) >= Wincondition.getTimeOverCountdown().getTimeLeft()) ) { return; } event.blockList().forEach(block -> { - if (countAnyBlock || Config.PercentBlocks.contains(block.getType()) == Config.PercentBlocksWhitelist) { + if (countAnyBlock || Config.GameModeConfig.WinConditionParams.Blocks.contains(block.getType()) == Config.GameModeConfig.WinConditionParams.BlocksWhitelist) { currentBlocks--; } }); @@ -111,7 +111,7 @@ public abstract class WinconditionBasePercent extends Wincondition implements Pr totalBlocks = 0; countAnyBlock = false; team.getSchemRegion().forEach((x, y, z) -> { - if (Config.PercentBlocks.contains(Config.world.getBlockAt(x, y, z).getType()) == Config.PercentBlocksWhitelist) + if (Config.GameModeConfig.WinConditionParams.Blocks.contains(Config.world.getBlockAt(x, y, z).getType()) == Config.GameModeConfig.WinConditionParams.BlocksWhitelist) totalBlocks++; }); // Edge Case for DirtBlock diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionBlocks.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionBlocks.java index 21fab040..fce8f574 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionBlocks.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionBlocks.java @@ -57,7 +57,7 @@ public abstract class WinconditionBlocks extends Wincondition implements Printab } }; - if(Config.ActiveWinconditions.contains(wincondition)) + if(Config.GameModeConfig.WinConditions.contains(wincondition)) printableWinconditions.add(this); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionComparisonTimeout.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionComparisonTimeout.java index ae9cc0b1..375e7ad5 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionComparisonTimeout.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionComparisonTimeout.java @@ -31,7 +31,7 @@ public abstract class WinconditionComparisonTimeout extends Wincondition { public WinconditionComparisonTimeout(Winconditions wincondition, String windescription, String winMessage, ToDoubleFunction evaluate) { super(windescription); - if(Config.ActiveWinconditions.contains(wincondition)) { + if(Config.GameModeConfig.WinConditions.contains(wincondition)) { timeOverCountdown = new StateDependentCountdown(wincondition, FightState.Running, new TimeOverCountdown(() -> comparisonWin(evaluate, winMessage, "WIN_TIME_OVER"))); } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java index a1e252df..558a66be 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java @@ -52,7 +52,7 @@ public class WinconditionPoints extends WinconditionBasePercent implements Liste new StateDependentListener(Winconditions.POINTS, FightState.Ingame, this); - if(Config.ActiveWinconditions.contains(Winconditions.POINTS)){ + if(Config.GameModeConfig.WinConditions.contains(Winconditions.POINTS)){ timeOverCountdown = new StateDependentCountdown(Winconditions.POINTS, FightState.Running, new TimeOverCountdown(this::timeOver)); } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java index a04dd2e2..9e9a92a9 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java @@ -43,7 +43,7 @@ import java.util.Map; @Linked public class WinconditionTimeTechKO extends Wincondition implements Listener { - private static final int TECH_KO_HALF_TIME = Config.TechKoTime/2; + private static final int TECH_KO_HALF_TIME = Config.GameModeConfig.WinConditionParams.TechKoTime/2; private final Map spawnLocations = new HashMap<>(); private final Map countdowns = new HashMap<>(); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimedDamageTechKO.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimedDamageTechKO.java index 3f2f8204..f118a0eb 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimedDamageTechKO.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimedDamageTechKO.java @@ -51,7 +51,7 @@ public class WinconditionTimedDamageTechKO extends Wincondition implements Print @Override public void enable() { Fight.teams().forEach(team -> { - TechKOCountdown countdown = new TechKOCountdown(team, Config.TechKoTime); + TechKOCountdown countdown = new TechKOCountdown(team, Config.GameModeConfig.WinConditionParams.TechKoTime); countdowns.put(team, countdown); countdown.enable(); }); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java index 4424b6f5..56355722 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java @@ -30,7 +30,7 @@ public class WinconditionTimeout extends Wincondition { public WinconditionTimeout() { super("Timeout"); - if(Config.ActiveWinconditions.contains(Winconditions.TIMEOUT)){ + if(Config.GameModeConfig.WinConditions.contains(Winconditions.TIMEOUT)){ timeOverCountdown = new StateDependentCountdown(Winconditions.TIMEOUT, FightState.Running, new TimeOverCountdown(this::timeOver)); } } diff --git a/SchematicSystem/SchematicSystem_15/src/de/steamwar/schematicsystem/autocheck/AutoChecker15.java b/SchematicSystem/SchematicSystem_15/src/de/steamwar/schematicsystem/autocheck/AutoChecker15.java index 4d5d2d8c..d77f615c 100644 --- a/SchematicSystem/SchematicSystem_15/src/de/steamwar/schematicsystem/autocheck/AutoChecker15.java +++ b/SchematicSystem/SchematicSystem_15/src/de/steamwar/schematicsystem/autocheck/AutoChecker15.java @@ -24,7 +24,8 @@ import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BaseBlock; -import de.steamwar.schematicsystem.CheckSchemType; +import de.steamwar.data.GameModeConfig; +import de.steamwar.sql.SchematicType; import org.bukkit.Material; import java.util.*; @@ -118,7 +119,7 @@ public class AutoChecker15 implements AutoChecker.IAutoChecker { } @Override - public AutoCheckerResult check(Clipboard clipboard, CheckSchemType type) { + public AutoCheckerResult check(Clipboard clipboard, GameModeConfig type) { return AutoCheckerResult.builder() .type(type) .height(clipboard.getDimensions().getBlockY()) @@ -130,7 +131,7 @@ public class AutoChecker15 implements AutoChecker.IAutoChecker { } @Override - public AutoCheckerResult sizeCheck(Clipboard clipboard, CheckSchemType type) { + public AutoCheckerResult sizeCheck(Clipboard clipboard, GameModeConfig type) { return AutoCheckerResult.builder() .type(type) .height(clipboard.getDimensions().getBlockY()) diff --git a/SchematicSystem/SchematicSystem_15/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommand15.java b/SchematicSystem/SchematicSystem_15/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommand15.java index 6c55ab0d..1a7f8a97 100644 --- a/SchematicSystem/SchematicSystem_15/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommand15.java +++ b/SchematicSystem/SchematicSystem_15/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommand15.java @@ -31,10 +31,10 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypes; -import de.steamwar.schematicsystem.CheckSchemType; +import de.steamwar.data.GameModeConfig; import de.steamwar.schematicsystem.autocheck.AutoCheckerResult; import de.steamwar.schematicsystem.autocheck.BlockPos; -import de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommand; +import de.steamwar.sql.SchematicType; import org.bukkit.Material; import java.util.*; @@ -42,7 +42,7 @@ import java.util.stream.Collectors; public class SchematicCommand15 implements SchematicCommand.ISchematicCommand { @Override - public Clipboard fixClipboard(Clipboard clipboard, AutoCheckerResult result, CheckSchemType type) throws Exception { + public Clipboard fixClipboard(Clipboard clipboard, AutoCheckerResult result, GameModeConfig type) throws Exception { for (BlockPos blockPos : result.getBlockScanResult().getRecords()) { BlockVector3 vector = BlockVector3.at(blockPos.getX(), blockPos.getY(), blockPos.getZ()); clipboard.setBlock(vector, clipboard.getFullBlock(vector).toBaseBlock(new CompoundTag(Collections.emptyMap()))); @@ -76,9 +76,9 @@ public class SchematicCommand15 implements SchematicCommand.ISchematicCommand { clipboard.setBlock(vector, block.toBaseBlock(builder.build())); } - if(type.getMaxDispenserItems() > 0 ) { + if(type.Schematic.MaxDispenserItems > 0 ) { for (Map.Entry entry : result.getBlockScanResult().getDispenserItems().entrySet()) { - if(entry.getValue() <= type.getMaxDispenserItems()) { + if(entry.getValue() <= type.Schematic.MaxDispenserItems) { continue; } @@ -90,7 +90,7 @@ public class SchematicCommand15 implements SchematicCommand.ISchematicCommand { List items = tag.getList("Items", CompoundTag.class); Collections.reverse(items); // To let the first item be in the Dispenser List list = new ArrayList<>(); - int diff = entry.getValue() - type.getMaxDispenserItems(); + int diff = entry.getValue() - type.Schematic.MaxDispenserItems; for (CompoundTag item : items) { if(item == null) { continue; @@ -117,10 +117,9 @@ public class SchematicCommand15 implements SchematicCommand.ISchematicCommand { } if(!result.isLimitedBlocksOK()) { - Set toReplace = type.getLimits().entrySet().stream() + Set toReplace = type.Schematic.Limited.entrySet().stream() .filter(setIntegerEntry -> setIntegerEntry.getValue() == 0) .flatMap(setIntegerEntry -> setIntegerEntry.getKey().stream()) - .map(Material::matchMaterial) .collect(Collectors.toSet()); BlockState replaceType = Objects.requireNonNull(toReplace.contains(Material.END_STONE) ? BlockTypes.IRON_BLOCK : BlockTypes.END_STONE).getDefaultState(); BlockVector3 min = clipboard.getMinimumPoint(); diff --git a/SchematicSystem/SchematicSystem_8/src/de/steamwar/schematicsystem/autocheck/AutoChecker8.java b/SchematicSystem/SchematicSystem_8/src/de/steamwar/schematicsystem/autocheck/AutoChecker8.java index 981acd46..cf457f62 100644 --- a/SchematicSystem/SchematicSystem_8/src/de/steamwar/schematicsystem/autocheck/AutoChecker8.java +++ b/SchematicSystem/SchematicSystem_8/src/de/steamwar/schematicsystem/autocheck/AutoChecker8.java @@ -25,7 +25,8 @@ import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.regions.Region; -import de.steamwar.schematicsystem.CheckSchemType; +import de.steamwar.data.GameModeConfig; +import de.steamwar.sql.SchematicType; import org.bukkit.Material; import java.util.*; @@ -148,7 +149,7 @@ public class AutoChecker8 implements AutoChecker.IAutoChecker { } @Override - public AutoCheckerResult check(Clipboard clipboard, CheckSchemType type) { + public AutoCheckerResult check(Clipboard clipboard, GameModeConfig type) { AutoChecker.BlockScanResult blockScanResult = new AutoChecker.BlockScanResult(); scan(blockScanResult, clipboard); @@ -163,7 +164,7 @@ public class AutoChecker8 implements AutoChecker.IAutoChecker { } @Override - public AutoCheckerResult sizeCheck(Clipboard clipboard, CheckSchemType type) { + public AutoCheckerResult sizeCheck(Clipboard clipboard, GameModeConfig type) { return AutoCheckerResult.builder() .type(type) .height(clipboard.getDimensions().getBlockY()) diff --git a/SchematicSystem/SchematicSystem_8/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommand8.java b/SchematicSystem/SchematicSystem_8/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommand8.java index 8245fb51..58c334cd 100644 --- a/SchematicSystem/SchematicSystem_8/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommand8.java +++ b/SchematicSystem/SchematicSystem_8/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommand8.java @@ -24,14 +24,15 @@ import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.function.operation.ForwardExtentCopy; import com.sk89q.worldedit.function.operation.Operations; -import de.steamwar.schematicsystem.CheckSchemType; +import de.steamwar.data.GameModeConfig; import de.steamwar.schematicsystem.autocheck.AutoCheckerResult; -import de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommand; +import de.steamwar.sql.SchematicType; +import org.bukkit.Material; public class SchematicCommand8 implements SchematicCommand.ISchematicCommand { @Override - public Clipboard fixClipboard(Clipboard clipboard, AutoCheckerResult result, CheckSchemType type) throws Exception { + public Clipboard fixClipboard(Clipboard clipboard, AutoCheckerResult result, GameModeConfig type) throws Exception { return null; } diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemType.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemType.java deleted file mode 100644 index dc8ca24b..00000000 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemType.java +++ /dev/null @@ -1,113 +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.schematicsystem; - -import de.steamwar.sql.SchematicType; -import lombok.Getter; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.file.YamlConfiguration; - -import java.io.File; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.time.Instant; -import java.util.*; - -@Getter -public class CheckSchemType { - - private static final Map types = new HashMap<>(); - - private final int width; - private final int height; - private final int depth; - private final int maxDispenserItems; - - private final Map, Integer> limits; - private final int maxBlocks; - - private final Date deadline; - private final float maxBlastResistance; - - private CheckSchemType(ConfigurationSection section) { - String name = section.getString("Schematic.Type"); - width = section.getInt("Schematic.Size.x"); - height = section.getInt("Schematic.Size.y"); - depth = section.getInt("Schematic.Size.z"); - - maxDispenserItems = section.getInt("Schematic.MaxDispenserItems", 128); - maxBlocks = section.getInt("Schematic.MaxBlocks", 0); - - maxBlastResistance = (float) section.getDouble("Schematic.MaxDesignBlastResistance", Double.MAX_VALUE); - - limits = new HashMap<>(); - for(Map entry : section.getMapList("Schematic.Limited")) { - int amount = (Integer) entry.get("Amount"); - Set materials = new HashSet<>((List) entry.get("Materials")); - if(amount == 0) { - materials.forEach(material -> limits.put(Collections.singleton(material), 0)); - } else { - limits.put(materials, amount); - } - } - - String deadlineString = section.getString("deadline", null); - if (deadlineString != null) { - try { - SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm"); - deadline = dateFormat.parse(deadlineString); - } catch (ParseException e) { - throw new SecurityException(e.getMessage(), e); - } - } else { - deadline = null; - } - - types.put(SchematicType.fromDB(name.toLowerCase()), this); - types.put(SchematicType.fromDB("c" + name.toLowerCase()), this); - } - - static { - 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"))) { - YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile); - if (!config.isList("CheckQuestions") && config.getBoolean("Schematic.ManualCheck", true)) - continue; - - new CheckSchemType(config); - } - } - } - - public static CheckSchemType get(SchematicType type){ - return types.get(type); - } - - public Map, Integer> getLimits() { - return new HashMap<>(limits); - } - - public boolean isAfterDeadline() { - return deadline != null && deadline.before(Date.from(Instant.now())); - } -} diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemTypeManager.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemTypeManager.java new file mode 100644 index 00000000..2b0e8317 --- /dev/null +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemTypeManager.java @@ -0,0 +1,56 @@ +/* + * 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.schematicsystem; + +import de.steamwar.data.GameModeConfig; +import de.steamwar.data.YMLWrapperImpl; +import de.steamwar.sql.SchematicType; +import lombok.experimental.UtilityClass; +import org.bukkit.Material; + +import java.io.File; +import java.util.HashMap; +import java.util.Map; + +@UtilityClass +public class CheckSchemTypeManager { + + private static final Map> types = new HashMap<>(); + + static { + 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)); + if (gameModeConfig.CheckQuestions.isEmpty() && gameModeConfig.Schematic.ManualCheck) + continue; + types.put(gameModeConfig.Schematic.Type, gameModeConfig); + if (gameModeConfig.Schematic.Type.checkType() != null) { + types.put(gameModeConfig.Schematic.Type.checkType(), gameModeConfig); + } + } + } + } + + public static GameModeConfig get(SchematicType type){ + return types.get(type); + } +} diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/autocheck/AutoChecker.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/autocheck/AutoChecker.java index 0d2eb937..ac4220fe 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/autocheck/AutoChecker.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/autocheck/AutoChecker.java @@ -21,8 +21,9 @@ package de.steamwar.schematicsystem.autocheck; import com.sk89q.worldedit.extent.clipboard.Clipboard; import de.steamwar.core.VersionDependent; -import de.steamwar.schematicsystem.CheckSchemType; +import de.steamwar.data.GameModeConfig; import de.steamwar.schematicsystem.SchematicSystem; +import de.steamwar.sql.SchematicType; import lombok.Getter; import lombok.ToString; import org.bukkit.Material; @@ -31,19 +32,19 @@ import java.util.*; public class AutoChecker { - public static AutoCheckerResult check(Clipboard clipboard, CheckSchemType type) { + public static AutoCheckerResult check(Clipboard clipboard, GameModeConfig type) { return impl.check(clipboard, type); } - public static AutoCheckerResult sizeCheck(Clipboard clipboard, CheckSchemType type) { + public static AutoCheckerResult sizeCheck(Clipboard clipboard, GameModeConfig type) { return impl.sizeCheck(clipboard, type); } private static final IAutoChecker impl = VersionDependent.getVersionImpl(SchematicSystem.getInstance()); public interface IAutoChecker { - AutoCheckerResult check(Clipboard clipboard, CheckSchemType type); - AutoCheckerResult sizeCheck(Clipboard clipboard, CheckSchemType type); + AutoCheckerResult check(Clipboard clipboard, GameModeConfig type); + AutoCheckerResult sizeCheck(Clipboard clipboard, GameModeConfig type); } @Getter diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/autocheck/AutoCheckerResult.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/autocheck/AutoCheckerResult.java index 002ff8ab..9aad0edb 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/autocheck/AutoCheckerResult.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/autocheck/AutoCheckerResult.java @@ -20,8 +20,9 @@ package de.steamwar.schematicsystem.autocheck; import de.steamwar.core.Core; -import de.steamwar.schematicsystem.CheckSchemType; +import de.steamwar.data.GameModeConfig; import de.steamwar.schematicsystem.SchematicSystem; +import de.steamwar.sql.SchematicType; import lombok.Builder; import lombok.Getter; import lombok.ToString; @@ -29,13 +30,15 @@ import net.md_5.bungee.api.chat.ClickEvent; import org.bukkit.Material; import org.bukkit.entity.Player; -import java.util.*; +import java.util.Collection; +import java.util.List; +import java.util.Map; @Builder @Getter @ToString public class AutoCheckerResult { - private final CheckSchemType type; + private final GameModeConfig type; private final int width; private final int height; private final int depth; @@ -61,7 +64,7 @@ public class AutoCheckerResult { } public boolean isDispenserItemsOK() { - return blockScanResult.getDispenserItems().values().stream().allMatch(i -> i <= type.getMaxDispenserItems()); + return blockScanResult.getDispenserItems().values().stream().allMatch(i -> i <= type.Schematic.MaxDispenserItems); } public boolean hasWarnings() { @@ -73,25 +76,25 @@ public class AutoCheckerResult { } public boolean isTooWide() { - return width > type.getWidth(); + return width > type.Schematic.Size.x; } public boolean isTooHigh() { - return height > type.getHeight(); + return height > type.Schematic.Size.y; } public boolean isTooDeep() { - return depth > type.getDepth(); + return depth > type.Schematic.Size.z; } public boolean isBlockCountOk() { - return type.getMaxBlocks() == 0 || blockScanResult.getBlockCounts().entrySet().stream().filter(entry -> entry.getKey() != Material.AIR).map(Map.Entry::getValue).reduce(Integer::sum).map(i -> i <= type.getMaxBlocks()).orElse(false); + return type.Schematic.MaxBlocks == 0 || blockScanResult.getBlockCounts().entrySet().stream().filter(entry -> entry.getKey() != Material.AIR).map(Map.Entry::getValue).reduce(Integer::sum).map(i -> i <= type.Schematic.MaxBlocks).orElse(false); } public boolean isLimitedBlocksOK() { try { - return type.getLimits().entrySet().stream() - .map(setIntegerEntry -> setIntegerEntry.getKey().stream().map(Material::getMaterial).map(blockScanResult.getBlockCounts()::get).map(i -> i == null || i <= setIntegerEntry.getValue()).reduce(Boolean::logicalAnd).orElse(false)) + return type.Schematic.Limited.entrySet().stream() + .map(setIntegerEntry -> setIntegerEntry.getKey().stream().map(blockScanResult.getBlockCounts()::get).map(i -> i == null || i <= setIntegerEntry.getValue()).reduce(Boolean::logicalAnd).orElse(false)) .reduce(Boolean::logicalAnd).orElse(true); } catch (NullPointerException e) { return false; @@ -99,21 +102,20 @@ public class AutoCheckerResult { } public boolean isDesignBlastResistanceOK() { - return blockScanResult.getDesignBlocks().keySet().stream().map(Material::getBlastResistance).noneMatch(i -> i > type.getMaxBlastResistance()); + return blockScanResult.getDesignBlocks().keySet().stream().map(Material::getBlastResistance).noneMatch(i -> i > type.Schematic.MaxDesignBlastResistance); } public void sendErrorMessage(Player p, String schemName) { SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_HEADER", p, schemName); - if(isTooWide()) SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_WIDTH", p, width, type.getWidth()); - if(isTooHigh()) SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_HEIGHT", p, height, type.getHeight()); - if(isTooDeep()) SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_LENGTH", p, depth, type.getDepth()); - if(type.getMaxBlocks() != 0 && !isBlockCountOk()) { - SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_BLOCKS", p, blockScanResult.getBlockCounts().values().stream().reduce(Integer::sum).orElse(0), type.getMaxBlocks()); + if(isTooWide()) SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_WIDTH", p, width, type.Schematic.Size.x); + if(isTooHigh()) SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_HEIGHT", p, height, type.Schematic.Size.y); + if(isTooDeep()) SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_LENGTH", p, depth, type.Schematic.Size.z); + if(type.Schematic.MaxBlocks != 0 && !isBlockCountOk()) { + SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_BLOCKS", p, blockScanResult.getBlockCounts().values().stream().reduce(Integer::sum).orElse(0), type.Schematic.MaxBlocks); } if(!isLimitedBlocksOK()) { - type.getLimits().forEach((strings, integer) -> { - for (String string : strings) { - Material mat = Material.matchMaterial(string); + type.Schematic.Limited.forEach((materials, integer) -> { + for (Material mat : materials) { if(mat != null && blockScanResult.getBlockCounts().getOrDefault(mat, 0) > integer) { if(integer == 0) { SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_FORBIDDEN_BLOCK", p, mat.name()); @@ -124,13 +126,13 @@ public class AutoCheckerResult { } }); } - blockScanResult.getDispenserItems().entrySet().stream().filter(blockVector3IntegerEntry -> blockVector3IntegerEntry.getValue() > type.getMaxDispenserItems()).forEach(blockVector3IntegerEntry -> { + blockScanResult.getDispenserItems().entrySet().stream().filter(blockVector3IntegerEntry -> blockVector3IntegerEntry.getValue() > type.Schematic.MaxDispenserItems).forEach(blockVector3IntegerEntry -> { SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_TOO_MANY_DISPENSER_ITEMS", p, SchematicSystem.MESSAGE.parse("AUTO_CHECKER_RESULT_TELEPORT_HERE", p), tpCommandTo(blockVector3IntegerEntry.getKey()), blockVector3IntegerEntry.getKey().getBlockX(), blockVector3IntegerEntry.getKey().getBlockY(), blockVector3IntegerEntry.getKey().getBlockZ(), blockVector3IntegerEntry.getValue(), - type.getMaxDispenserItems()); + type.Schematic.MaxDispenserItems); }); blockScanResult.getRecords().forEach(blockVector3 -> { SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_RECORD", p, SchematicSystem.MESSAGE.parse("AUTO_CHECKER_RESULT_TELEPORT_HERE", p), tpCommandTo(blockVector3), blockVector3.getBlockX(), blockVector3.getBlockY(), blockVector3.getBlockZ()); @@ -146,7 +148,7 @@ public class AutoCheckerResult { }); if(Core.getVersion() > 12) { blockScanResult.getDesignBlocks().forEach((material, poss) -> { - if(material.getBlastResistance() > type.getMaxBlastResistance()) { + if(material.getBlastResistance() > type.Schematic.MaxDesignBlastResistance) { poss.forEach(pos -> { SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_DESIGN_BLOCK", p, SchematicSystem.MESSAGE.parse("AUTO_CHECKER_RESULT_TELEPORT_HERE", p), tpCommandTo(pos), material.name(), pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()); }); @@ -157,7 +159,7 @@ public class AutoCheckerResult { SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_ENTITY", p, SchematicSystem.MESSAGE.parse("AUTO_CHECKER_RESULT_TELEPORT_HERE", p), tpCommandTo(blockPos), blockPos.getX(), blockPos.getY(), blockPos.getZ()); }); if(type.isAfterDeadline()) { - SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_AFTER_DEADLINE", p, type.getDeadline()); + SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_AFTER_DEADLINE", p, type.Deadline); } } diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/GUI.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/GUI.java index a9c90380..ece48694 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/GUI.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/GUI.java @@ -23,7 +23,7 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard; import de.steamwar.core.Core; import de.steamwar.data.CMDs; import de.steamwar.inventory.*; -import de.steamwar.schematicsystem.CheckSchemType; +import de.steamwar.schematicsystem.CheckSchemTypeManager; import de.steamwar.schematicsystem.SafeSchematicNode; import de.steamwar.schematicsystem.SchematicSystem; import de.steamwar.schematicsystem.autocheck.AutoChecker; @@ -245,7 +245,7 @@ public class GUI { Clipboard finalClipboard = clipboard; List types = SchematicType.values().parallelStream() .filter(SchematicType::isAssignable) - .filter(type -> finalClipboard == null || CheckSchemType.get(type) == null || AutoChecker.sizeCheck(finalClipboard, CheckSchemType.get(type)).fastOk()) + .filter(type -> finalClipboard == null || CheckSchemTypeManager.get(type) == null || AutoChecker.sizeCheck(finalClipboard, CheckSchemTypeManager.get(type)).fastOk()) .collect(Collectors.toList()); List> items = types.stream() diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommand.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommand.java index 0b9f0c1d..5b9add07 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommand.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommand.java @@ -19,20 +19,25 @@ package de.steamwar.schematicsystem.commands.schematiccommand; -import com.sk89q.worldedit.*; +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.clipboard.Clipboard; -import de.steamwar.command.*; +import de.steamwar.command.AbstractSWCommand; +import de.steamwar.command.SWCommand; +import de.steamwar.command.TypeMapper; +import de.steamwar.command.TypeValidator; import de.steamwar.core.VersionDependent; +import de.steamwar.data.GameModeConfig; import de.steamwar.linkage.Linked; -import de.steamwar.schematicsystem.CheckSchemType; import de.steamwar.schematicsystem.SchematicSystem; import de.steamwar.schematicsystem.autocheck.AutoCheckerResult; import de.steamwar.sql.*; +import org.bukkit.Material; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import static de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandHelp.*; -import static de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils.*; +import static de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils.togglePublic; @SuppressWarnings("unused") @Linked @@ -107,9 +112,9 @@ public class SchematicCommand extends SWCommand { return SchematicMapper.nodeTypeMapper(); } - @ClassMapper(value = CheckSchemType.class, local = true) - public static TypeMapper checkSchemTypeTypeMapper() { - return SchematicMapper.checkSchemTypeTypeMapper(); + @ClassMapper(value = GameModeConfig.class, local = true) + public static TypeMapper> gameModeConfigTypeMapper() { + return SchematicMapper.gameModeConfigTypeMapper(); } @Override @@ -145,7 +150,7 @@ public class SchematicCommand extends SWCommand { public static final ISchematicCommand impl = VersionDependent.getVersionImpl(SchematicSystem.getInstance()); public interface ISchematicCommand { - Clipboard fixClipboard(Clipboard clipboard, AutoCheckerResult result, CheckSchemType type) throws Exception; + Clipboard fixClipboard(Clipboard clipboard, AutoCheckerResult result, GameModeConfig type) throws Exception; void createCopy(EditSession editSession, Clipboard clipboard) throws WorldEditException; } } diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java index b86b2c88..9cccc0b6 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java @@ -20,12 +20,13 @@ package de.steamwar.schematicsystem.commands.schematiccommand; import com.sk89q.worldedit.extent.clipboard.Clipboard; +import de.steamwar.data.GameModeConfig; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import de.steamwar.network.NetworkSender; import de.steamwar.network.packets.client.PrepareSchemPacket; import de.steamwar.providers.BauServerInfo; -import de.steamwar.schematicsystem.CheckSchemType; +import de.steamwar.schematicsystem.CheckSchemTypeManager; import de.steamwar.schematicsystem.SchematicSystem; import de.steamwar.schematicsystem.autocheck.AutoChecker; import de.steamwar.schematicsystem.autocheck.AutoCheckerResult; @@ -40,6 +41,7 @@ import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.entity.Player; import java.io.IOException; @@ -311,7 +313,7 @@ public class SchematicCommandUtils { } } - public static void check(Player player, Clipboard clipboard, CheckSchemType type, String schemName, boolean gui) { + public static void check(Player player, Clipboard clipboard, GameModeConfig type, String schemName, boolean gui) { AutoCheckerResult result = AutoChecker.check(clipboard, type); if(!result.isOk()) { result.sendErrorMessage(player, schemName); @@ -454,9 +456,9 @@ public class SchematicCommandUtils { return; } - CheckSchemType checkSchemType = CheckSchemType.get(type); + GameModeConfig checkSchemType = CheckSchemTypeManager.get(type); if (checkSchemType.isAfterDeadline()) { - SchematicSystem.MESSAGE.send("UTIL_TYPE_AFTER_DEADLINE", player, checkSchemType.getDeadline()); + SchematicSystem.MESSAGE.send("UTIL_TYPE_AFTER_DEADLINE", player, checkSchemType.Deadline); return; } diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicMapper.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicMapper.java index 80d02e90..b3f23092 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicMapper.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicMapper.java @@ -20,11 +20,13 @@ package de.steamwar.schematicsystem.commands.schematiccommand; import de.steamwar.command.TypeMapper; -import de.steamwar.schematicsystem.CheckSchemType; +import de.steamwar.data.GameModeConfig; +import de.steamwar.schematicsystem.CheckSchemTypeManager; import de.steamwar.sql.NodeMember; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicType; import de.steamwar.sql.SteamwarUser; +import org.bukkit.Material; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -175,16 +177,16 @@ public class SchematicMapper { }; } - public static TypeMapper checkSchemTypeTypeMapper() { - return new TypeMapper() { + public static TypeMapper> gameModeConfigTypeMapper() { + return new TypeMapper>() { @Override public Collection tabCompletes(CommandSender commandSender, String[] strings, String s) { - return SchematicType.values().stream().filter(type -> CheckSchemType.get(type) != null).map(SchematicType::name).collect(Collectors.toList()); + return SchematicType.values().stream().filter(type -> CheckSchemTypeManager.get(type) != null).map(SchematicType::name).collect(Collectors.toList()); } @Override - public CheckSchemType map(CommandSender commandSender, String[] previousArguments, String s) { - return SchematicType.values().stream().filter(type -> type.name().equalsIgnoreCase(s)).map(CheckSchemType::get).findAny().orElse(null); + public GameModeConfig map(CommandSender commandSender, String[] previousArguments, String s) { + return SchematicType.values().stream().filter(type -> type.name().equalsIgnoreCase(s)).map(CheckSchemTypeManager::get).findAny().orElse(null); } }; } diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicValidator.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicValidator.java index 8a798fc8..bd02c3d2 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicValidator.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicValidator.java @@ -19,7 +19,6 @@ package de.steamwar.schematicsystem.commands.schematiccommand; -import de.steamwar.command.AbstractSWCommand; import de.steamwar.command.AbstractValidator; import de.steamwar.command.TypeValidator; import de.steamwar.sql.SchematicNode; diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/CheckPart.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/CheckPart.java index 878b72b3..bf0f0c8e 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/CheckPart.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/CheckPart.java @@ -28,21 +28,23 @@ import com.sk89q.worldedit.session.ClipboardHolder; import de.steamwar.command.AbstractSWCommand; import de.steamwar.command.SWCommand; import de.steamwar.core.Core; +import de.steamwar.data.GameModeConfig; import de.steamwar.linkage.Linked; -import de.steamwar.schematicsystem.CheckSchemType; import de.steamwar.schematicsystem.SchematicSystem; import de.steamwar.schematicsystem.autocheck.AutoChecker; import de.steamwar.schematicsystem.autocheck.AutoCheckerResult; import de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommand; import de.steamwar.sql.SchematicData; import de.steamwar.sql.SchematicNode; +import de.steamwar.sql.SchematicType; +import org.bukkit.Material; import org.bukkit.entity.Player; import java.io.IOException; import java.util.logging.Level; -import static de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils.check; import static de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommand.impl; +import static de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils.check; @AbstractSWCommand.PartOf(SchematicCommand.class) @Linked @@ -52,7 +54,7 @@ public class CheckPart extends SWCommand { } @Register("check") - public void checkCommand(Player player, @Validator("isOwnerSchematicValidator") SchematicNode node, CheckSchemType type) { + public void checkCommand(Player player, @Validator("isOwnerSchematicValidator") SchematicNode node, GameModeConfig type) { try { check(player, new SchematicData(node).load(), type, node.getName(), false); } catch (IOException e) { @@ -61,7 +63,7 @@ public class CheckPart extends SWCommand { } @Register(value = {"check", "clipboard"}) - public void checkClipboardCommand(Player player, @ErrorMessage("UTIL_CHECK_TYPE_NOT_FOUND") CheckSchemType type) { + public void checkClipboardCommand(Player player, @ErrorMessage("UTIL_CHECK_TYPE_NOT_FOUND") GameModeConfig type) { try { check(player, WorldEdit.getInstance().getSessionManager().findByName(player.getName()).getClipboard().getClipboard(), type, "clipboard", false); } catch (EmptyClipboardException e) { @@ -70,7 +72,7 @@ public class CheckPart extends SWCommand { } @Register(value = {"check", "selection"}) - public void checkSelectionCommand(Player player, @ErrorMessage("UTIL_CHECK_TYPE_NOT_FOUND") CheckSchemType type) { + public void checkSelectionCommand(Player player, @ErrorMessage("UTIL_CHECK_TYPE_NOT_FOUND") GameModeConfig type) { try { Clipboard clipboard = new BlockArrayClipboard(WorldEdit.getInstance().getSessionManager().findByName(player.getName()).getSelection(new BukkitWorld(player.getWorld()))); EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(player.getWorld()), -1); @@ -86,7 +88,7 @@ public class CheckPart extends SWCommand { } @Register("fix") - public void fixSchematicCommand(Player player, @ErrorMessage("UTIL_CHECK_TYPE_NOT_FOUND") CheckSchemType type) { + public void fixSchematicCommand(Player player, @ErrorMessage("UTIL_CHECK_TYPE_NOT_FOUND") GameModeConfig type) { if(Core.getVersion() < 15) { SchematicSystem.MESSAGE.send("COMMAND_FIX_WRONG_VERSION", player); return; diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/ModifyPart.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/ModifyPart.java index 3387e855..58645331 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/ModifyPart.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/ModifyPart.java @@ -23,7 +23,7 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard; import de.steamwar.command.AbstractSWCommand; import de.steamwar.command.SWCommand; import de.steamwar.linkage.Linked; -import de.steamwar.schematicsystem.CheckSchemType; +import de.steamwar.schematicsystem.CheckSchemTypeManager; import de.steamwar.schematicsystem.SafeSchematicNode; import de.steamwar.schematicsystem.SchematicSystem; import de.steamwar.schematicsystem.autocheck.AutoChecker; @@ -63,7 +63,7 @@ public class ModifyPart extends SWCommand { SchematicType.values().parallelStream() .filter(SchematicType::isAssignable) - .filter(type -> finalClipboard == null || CheckSchemType.get(type) == null || AutoChecker.sizeCheck(finalClipboard, CheckSchemType.get(type)).fastOk()) + .filter(type -> finalClipboard == null || CheckSchemTypeManager.get(type) == null || AutoChecker.sizeCheck(finalClipboard, CheckSchemTypeManager.get(type)).fastOk()) .forEach(type -> { TextComponent component = new TextComponent(type.name() + " "); component.setColor(ChatColor.GRAY); diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/SearchPart.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/SearchPart.java index 81db6aba..d6834468 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/SearchPart.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/SearchPart.java @@ -22,8 +22,8 @@ package de.steamwar.schematicsystem.commands.schematiccommand.parts; import de.steamwar.command.*; import de.steamwar.linkage.Linked; import de.steamwar.schematicsystem.SchematicSystem; -import de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils; import de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommand; +import de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicType; import de.steamwar.sql.SteamwarUser; diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/data/YMLWrapperImpl.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/data/YMLWrapperImpl.java new file mode 100644 index 00000000..78a050a6 --- /dev/null +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/data/YMLWrapperImpl.java @@ -0,0 +1,154 @@ +/* + * 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 String getString(String path, String defaultValue) { + if (config == null) return defaultValue; + return config.getString(pathPrefix + path, defaultValue); + } + + @Override + public int getInt(String path, int defaultValue) { + if (config == null) return defaultValue; + return config.getInt(pathPrefix + path, defaultValue); + } + + @Override + public double getDouble(String path, double defaultValue) { + if (config == null) return defaultValue; + return config.getDouble(pathPrefix + path, defaultValue); + } + + @Override + public boolean getBoolean(String path, boolean defaultValue) { + if (config == null) return defaultValue; + return config.getBoolean(pathPrefix + path, defaultValue); + } + + @Override + public List getStringList(String path) { + if (config == null) return Collections.emptyList(); + List list = config.getStringList(pathPrefix + path); + if (list.isEmpty()) { + return Collections.emptyList(); + } else { + return Collections.unmodifiableList(list); + } + } + + @Override + public List getIntList(String path) { + if (config == null) return Collections.emptyList(); + List list = config.getIntegerList(pathPrefix + path); + if (list.isEmpty()) { + return Collections.emptyList(); + } else { + return Collections.unmodifiableList(list); + } + } + + @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/sql/SQLWrapperImpl.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SQLWrapperImpl.java index fff456d3..2d11fdec 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SQLWrapperImpl.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SQLWrapperImpl.java @@ -20,9 +20,10 @@ package de.steamwar.sql; import de.steamwar.core.Core; +import de.steamwar.data.GameModeConfig; +import de.steamwar.data.YMLWrapperImpl; import org.bukkit.Bukkit; import org.bukkit.World; -import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import java.io.File; @@ -36,33 +37,30 @@ 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()) { - for(File configFile : Arrays.stream(folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))).sorted().collect(Collectors.toList())) { - YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile); - if(!config.isConfigurationSection("Schematic")) - continue; + 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)); + if (!gameModeConfig.Schematic.loaded) continue; + String type = gameModeConfig.Schematic.Type; + assert type != null; + String shortcut = gameModeConfig.Schematic.Shortcut; + if (tmpFromDB.containsKey(type.toLowerCase())) + continue; - String type = config.getString("Schematic.Type"); - assert type != null; - String shortcut = config.getString("Schematic.Shortcut"); - if(tmpFromDB.containsKey(type.toLowerCase())) - continue; + SchematicType checktype = null; + String material = gameModeConfig.Schematic.Material; - SchematicType checktype = null; - String material = config.getString("Schematic.Material", "STONE_BUTTON"); - - if(!config.getStringList("CheckQuestions").isEmpty()) { - checktype = new SchematicType("C" + type, "C" + shortcut, SchematicType.Type.CHECK_TYPE, null, material, true); - tmpTypes.add(checktype); - tmpFromDB.put(checktype.toDB(), checktype); - } - - boolean manualCheck = config.getBoolean("Schematic.ManualCheck", true); - - SchematicType current = new SchematicType(type, shortcut, config.isConfigurationSection("Server") ? SchematicType.Type.FIGHT_TYPE : SchematicType.Type.NORMAL, checktype, material, manualCheck); - tmpTypes.add(current); - tmpFromDB.put(type.toLowerCase(), current); + 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); } + + boolean manualCheck = gameModeConfig.Schematic.ManualCheck; + + SchematicType current = new SchematicType(type, shortcut, gameModeConfig.Server.loaded ? SchematicType.Type.FIGHT_TYPE : SchematicType.Type.NORMAL, checktype, material, manualCheck); + tmpTypes.add(current); + tmpFromDB.put(type.toLowerCase(), current); } } @@ -71,10 +69,10 @@ public class SQLWrapperImpl implements SQLWrapper { @Override public void additionalExceptionMetadata(StringBuilder builder) { builder.append("\nPlayers: "); - for(Player player : Bukkit.getOnlinePlayers()) + for (Player player : Bukkit.getOnlinePlayers()) builder.append(player.getName()).append(" "); builder.append("\nWorlds: "); - for(World world : Bukkit.getWorlds()) + for (World world : Bukkit.getWorlds()) builder.append(world.getName()).append(" "); builder.append("\nServer: ").append(SERVER_VERSION); } diff --git a/VelocityCore/src/de/steamwar/data/YMLWrapperImpl.java b/VelocityCore/src/de/steamwar/data/YMLWrapperImpl.java new file mode 100644 index 00000000..272b018d --- /dev/null +++ b/VelocityCore/src/de/steamwar/data/YMLWrapperImpl.java @@ -0,0 +1,159 @@ +/* + * 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 String getString(String path, String defaultValue) { + Object value = this.document.get(path); + if (value instanceof String) { + return (String) value; + } else { + return defaultValue; + } + } + + @Override + public int getInt(String path, int defaultValue) { + Object value = this.document.get(path); + if (value instanceof Integer) { + return (Integer) value; + } else { + return defaultValue; + } + } + + @Override + public double getDouble(String path, double defaultValue) { + Object value = this.document.get(path); + if (value instanceof Double) { + return (Double) value; + } else { + return defaultValue; + } + } + + @Override + public boolean getBoolean(String path, boolean defaultValue) { + Object value = this.document.get(path); + if (value instanceof Boolean) { + return (Boolean) value; + } else { + return defaultValue; + } + } + + @Override + public List getStringList(String path) { + Object value = this.document.get(path); + if (value instanceof List) { + return Collections.unmodifiableList((List) value); + } else { + return Collections.emptyList(); + } + } + + @Override + public List getIntList(String path) { + Object value = this.document.get(path); + if (value instanceof List) { + return Collections.unmodifiableList((List) value); + } else { + 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 60212547..8f4328a1 100644 --- a/VelocityCore/src/de/steamwar/sql/SQLWrapperImpl.java +++ b/VelocityCore/src/de/steamwar/sql/SQLWrapperImpl.java @@ -21,52 +21,46 @@ package de.steamwar.sql; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.server.RegisteredServer; -import de.steamwar.velocitycore.GameModeConfig; +import de.steamwar.data.GameModeConfig; +import de.steamwar.data.YMLWrapperImpl; import de.steamwar.velocitycore.VelocityCore; import de.steamwar.velocitycore.commands.CheckCommand; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; +import java.io.File; +import java.util.Arrays; import java.util.List; import java.util.Map; public class SQLWrapperImpl implements SQLWrapper { - private static final SimpleDateFormat deadlineFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm"); - private static Date parseDeadline(String deadline) { - if(deadline == null) - return null; - - try { - return deadlineFormat.parse(deadline); - } catch (ParseException e) { - throw new SecurityException(e.getMessage(), e); - } - } @Override public void loadSchemTypes(List tmpTypes, Map tmpFromDB) { - GameModeConfig.loadAll(GameModeConfig.class, (file, config) -> { - if(config.getSchematic() == null || tmpFromDB.containsKey(config.getSchemType().toLowerCase())) - return; + File folder = new File(VelocityCore.get().getDataDirectory().getParent().toFile(), "FightSystem"); + if(!folder.exists()) + return; - String shortcut = config.getSchematic().getShortcut(); - String material = config.getSchematic().getMaterial(); + 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)); + 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(!config.getCheckQuestions().isEmpty()) { - checktype = new SchematicType("C" + config.getSchemType(), "C" + shortcut, SchematicType.Type.CHECK_TYPE, null, material, true); + 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, config.getCheckQuestions()); + CheckCommand.setCheckQuestions(checktype, gameModeConfig.CheckQuestions); } - SchematicType current = new SchematicType(config.getSchemType(), shortcut, config.getServer() != null ? SchematicType.Type.FIGHT_TYPE : SchematicType.Type.NORMAL, checktype, material, parseDeadline(config.getDeadline()), config.getSchematic().isManualCheck()); + 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(config.getSchemType().toLowerCase(), current); + tmpFromDB.put(gameModeConfig.Schematic.Type.toLowerCase(), current); if(checktype != null) CheckCommand.addFightType(checktype, current); - }); + } } @Override diff --git a/VelocityCore/src/de/steamwar/velocitycore/ArenaMode.java b/VelocityCore/src/de/steamwar/velocitycore/ArenaMode.java index 2db21ea9..7b94c584 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/ArenaMode.java +++ b/VelocityCore/src/de/steamwar/velocitycore/ArenaMode.java @@ -19,21 +19,23 @@ package de.steamwar.velocitycore; +import de.steamwar.data.GameModeConfig; +import de.steamwar.data.YMLWrapperImpl; import de.steamwar.sql.SchematicType; import lombok.Getter; +import lombok.experimental.UtilityClass; -import java.time.LocalDateTime; +import java.io.File; import java.util.*; -public class ArenaMode extends GameModeConfig { +@UtilityClass +public class ArenaMode { - private static final Random random = new Random(); - - private static final Map byChat = new HashMap<>(); - private static final Map byInternal = new HashMap<>(); - private static final Map bySchemType = new HashMap<>(); + private static final Map> byChat = new HashMap<>(); + private static final Map> byInternal = new HashMap<>(); + private static final Map> bySchemType = new HashMap<>(); @Getter - private static final List allModes = new LinkedList<>(); + private static final List> allModes = new LinkedList<>(); static { init(); @@ -45,90 +47,43 @@ public class ArenaMode extends GameModeConfig { bySchemType.clear(); allModes.clear(); - GameModeConfig.loadAll(ArenaMode.class, (file, mode) -> { - if(mode.getServer() == null) - return; + File folder = new File(VelocityCore.get().getDataDirectory().getParent().toFile(), "FightSystem"); + if(!folder.exists()) + return; - mode.config = file.getName(); - mode.internalName = file.getName().replace(".yml", ""); - mode.getMaps().forEach(map -> mode.lowerToRealMapNames.put(map.toLowerCase(), map)); - if(mode.getGameName() == null) - mode.setGameName(mode.internalName); + 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)); + if (!gameModeConfig.Server.loaded) continue; - allModes.add(mode); - byInternal.put(mode.internalName, mode); - for(String name : mode.getServer().getChatNames()){ - byChat.put(name.toLowerCase(), mode); + allModes.add(gameModeConfig); + byInternal.put(file.getName().replace(".yml", ""), gameModeConfig); + for (String name : gameModeConfig.Server.ChatNames) { + byChat.put(name.toLowerCase(), gameModeConfig); } - - if(mode.getSchematic() != null && mode.getSchemType() != null) - bySchemType.put(SchematicType.fromDB(mode.getSchemType()), mode); - }); + if (gameModeConfig.Schematic.loaded && gameModeConfig.Schematic.Type != SchematicType.Normal) { + bySchemType.put(gameModeConfig.Schematic.Type, gameModeConfig); + } + } } - public static ArenaMode getByChat(String name){ + public static GameModeConfig getByChat(String name){ return byChat.get(name.toLowerCase()); } - public static ArenaMode getByInternal(String name){ + public static GameModeConfig getByInternal(String name){ return byInternal.get(name); } public static List getAllChatNames(boolean historic) { List chatNames = new LinkedList<>(); - for(ArenaMode mode : byInternal.values()){ - if(mode.isActive() && historic == mode.isHistoric()) - chatNames.addAll(mode.getServer().getChatNames()); + for(GameModeConfig mode : byInternal.values()){ + if(mode.isActive() && historic == mode.Server.Historic) + chatNames.addAll(mode.Server.ChatNames); } return chatNames; } - public static ArenaMode getBySchemType(SchematicType schemType){ + public static GameModeConfig getBySchemType(SchematicType schemType){ return bySchemType.get(schemType); } - - - private final Map lowerToRealMapNames = new HashMap<>(); - - @Getter - private String internalName; - @Getter - private String config; - - @Getter - private List ActiveMonths = Collections.emptyList(); - - public String hasMap(String map){ - for(String m : getMaps()) { - if(m.equalsIgnoreCase(map)) - return m; - } - return null; - } - - public String getRandomMap(){ - return getMaps().get(random.nextInt(getMaps().size())); - } - - public String convertToRealMapName(String map){ - return lowerToRealMapNames.get(map.toLowerCase()); - } - - public String getChatName(){ - return getServer().getChatNames().get(0); - } - - public boolean isActive() { - if (getServer().getChatNames().isEmpty()) return false; - if (ActiveMonths.isEmpty()) return true; - return ActiveMonths.contains(LocalDateTime.now().getMonth().getValue()); - } - - public String getSchemTypeOrInternalName() { - Schematic schematic = getSchematic(); - if (schematic == null) { - return internalName; - } - return schematic.getType(); - } } diff --git a/VelocityCore/src/de/steamwar/velocitycore/GameModeConfig.java b/VelocityCore/src/de/steamwar/velocitycore/GameModeConfig.java deleted file mode 100644 index fdb7c6a2..00000000 --- a/VelocityCore/src/de/steamwar/velocitycore/GameModeConfig.java +++ /dev/null @@ -1,98 +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.velocitycore; - -import lombok.Getter; -import lombok.Setter; - -import java.io.File; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.function.BiConsumer; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -@Getter -public class GameModeConfig { - - private static final Pattern terminatingNumber = Pattern.compile("(\\d+)$"); - - public static void loadAll(Class config, BiConsumer consumer) { - File folder = new File(VelocityCore.get().getDataDirectory().getParent().toFile(), "FightSystem"); - if(!folder.exists()) - return; - - for(File file : Arrays.stream(folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))).sorted().toList()) { - consumer.accept(file, Config.load(config, file, description -> {})); - } - } - - private Server Server = null; - private List CheckQuestions = Collections.emptyList(); - private String deadline = null; - private Schematic Schematic = null; - @Setter - private String GameName; - - @Getter - public static class Server { - private String Folder; - private List ChatNames = Collections.emptyList(); - private List Maps; - private boolean Spigot = false; - private boolean Ranked = false; - private boolean Historic = false; - } - - @Getter - public static class Schematic { - private String Type; - private String Shortcut; - private String Material; - private boolean ManualCheck = true; - } - - public ServerVersion getVersion() { - Matcher matcher = terminatingNumber.matcher(getServer().getFolder()); - matcher.find(); - return ServerVersion.valueOf((getServer().isSpigot() ? "SPIGOT_" : "PAPER_") + matcher.group(1)); - } - - public String getFolder() { - return getServer().getFolder(); - } - - public List getMaps() { - return getServer().getMaps(); - } - - public boolean isHistoric() { - return getServer().isHistoric(); - } - - public boolean isRanked() { - return getServer().isRanked(); - } - - public String getSchemType() { - return getSchematic().getType(); - } -} diff --git a/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java b/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java index d48d2c2b..31f73773 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java +++ b/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java @@ -22,6 +22,7 @@ package de.steamwar.velocitycore; import com.velocitypowered.api.proxy.Player; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.velocity.platform.VelocityViaConfig; +import de.steamwar.data.GameModeConfig; import de.steamwar.messages.Chatter; import de.steamwar.persistent.Arenaserver; import de.steamwar.persistent.Bauserver; @@ -79,16 +80,16 @@ public class ServerStarter { private final Set playersToSend = new HashSet<>(); private final Map arguments = new HashMap<>(); - public ServerStarter arena(ArenaMode mode, String map) { + public ServerStarter arena(GameModeConfig mode, String map) { portrange = ARENA_PORTS; - serverNameProvider = port -> mode.getGameName() + (port - portrange.start); - version = mode.getVersion(); + serverNameProvider = port -> mode.GameName + (port - portrange.start); + version = ServerVersion.from(mode); allowMerge = true; fightMap = map; - gameMode = mode.getInternalName(); - directory = new File(SERVER_PATH, mode.getFolder()); - arguments.put("config", mode.getConfig()); - tempWorld(SERVER_PATH + mode.getFolder() + "/arenas/" + map); + gameMode = mode.configFile.getName().replace(".yml", ""); + directory = new File(SERVER_PATH, mode.Server.Folder); + arguments.put("config", mode.configFile.getName()); + tempWorld(SERVER_PATH + mode.Server.Folder + "/arenas/" + map); startCondition = () -> { if(playersToSend.stream().anyMatch(player -> Subserver.isArena(Subserver.getSubserver(player)))) { playersToSend.forEach(player -> Chatter.of(player).system("FIGHT_IN_ARENA")); @@ -115,7 +116,7 @@ public class ServerStarter { return this; } - public ServerStarter test(ArenaMode mode, String map, Player owner) { + public ServerStarter test(GameModeConfig mode, String map, Player owner) { arena(mode, map); buildWithTemp(owner); portrange = BAU_PORTS; diff --git a/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java b/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java index 86068c5b..260bbec6 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java +++ b/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java @@ -20,6 +20,8 @@ package de.steamwar.velocitycore; import com.velocitypowered.api.network.ProtocolVersion; +import de.steamwar.data.GameModeConfig; +import de.steamwar.sql.SchematicType; import lombok.AllArgsConstructor; import lombok.Getter; @@ -27,6 +29,8 @@ import java.io.File; import java.util.HashMap; import java.util.Map; import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; @Getter @AllArgsConstructor @@ -108,4 +112,12 @@ public enum ServerVersion { public File getServerDirectory(String base) { return new File(ServerStarter.SERVER_PATH, base + versionSuffix); } + + private static final Pattern terminatingNumber = Pattern.compile("(\\d+)$"); + + public static ServerVersion from(GameModeConfig type) { + Matcher matcher = terminatingNumber.matcher(type.Server.Folder); + matcher.find(); + return ServerVersion.valueOf((type.Server.Spigot ? "SPIGOT_" : "PAPER_") + matcher.group(1)); + } } diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/BauCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/BauCommand.java index 183e5414..48ab4d05 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/BauCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/BauCommand.java @@ -23,6 +23,7 @@ import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeValidator; +import de.steamwar.data.GameModeConfig; import de.steamwar.linkage.EventMode; import de.steamwar.linkage.Linked; import de.steamwar.linkage.LinkedInstance; @@ -32,6 +33,7 @@ import de.steamwar.messages.PlayerChatter; import de.steamwar.network.packets.server.BaumemberUpdatePacket; import de.steamwar.persistent.Bauserver; import de.steamwar.sql.BauweltMember; +import de.steamwar.sql.SchematicType; import de.steamwar.sql.SteamwarUser; import de.steamwar.velocitycore.*; import de.steamwar.velocitycore.inventory.SWInventory; @@ -238,7 +240,7 @@ public class BauCommand extends SWCommand { @Register("test") @Register("testarena") - public void testarena(PlayerChatter sender, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { + public void testarena(PlayerChatter sender, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull GameModeConfig arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { FightCommand.createArena(sender, "/bau testarena ", false, arenaMode, map, false, (chatter, mode, m) -> new ServerStarter().test(mode, m, sender.getPlayer()).start() ); diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/BuilderCloudCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/BuilderCloudCommand.java index 6d7a916b..6dc12264 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/BuilderCloudCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/BuilderCloudCommand.java @@ -19,7 +19,9 @@ package de.steamwar.velocitycore.commands; +import de.steamwar.data.GameModeConfig; import de.steamwar.linkage.Linked; +import de.steamwar.sql.SchematicType; import de.steamwar.velocitycore.ArenaMode; import de.steamwar.velocitycore.ServerStarter; import de.steamwar.velocitycore.ServerVersion; @@ -85,14 +87,14 @@ public class BuilderCloudCommand extends SWCommand { } @Register(value = "deploy", description = "BUILDERCLOUD_DEPLOY_USAGE") - public void deploy(Chatter sender, @Mapper("nonHistoricArenaMode") ArenaMode arenaMode, @ErrorMessage("BUILDERCLOUD_VERSION") ServerVersion version, @Mapper("map") String map) { + public void deploy(Chatter sender, @Mapper("nonHistoricArenaMode") GameModeConfig arenaMode, @ErrorMessage("BUILDERCLOUD_VERSION") ServerVersion version, @Mapper("map") String map) { if(!mapFile(version, map).exists()) { sender.system("BUILDERCLOUD_UNKNOWN_MAP"); return; } VelocityCore.schedule(() -> { - VelocityCore.local.execute("deployarena.py", arenaMode.getConfig(), Integer.toString(version.getVersionSuffix()), map); + VelocityCore.local.execute("deployarena.py", arenaMode.configFile.getName(), Integer.toString(version.getVersionSuffix()), map); ArenaMode.init(); sender.system("BUILDERCLOUD_DEPLOY_FINISHED"); }).schedule(); diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/ChallengeCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/ChallengeCommand.java index 10e13c9c..024d4de4 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/ChallengeCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/ChallengeCommand.java @@ -22,6 +22,7 @@ package de.steamwar.velocitycore.commands; import com.velocitypowered.api.proxy.Player; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeValidator; +import de.steamwar.data.GameModeConfig; import de.steamwar.linkage.EventMode; import de.steamwar.linkage.Linked; import de.steamwar.messages.Chatter; @@ -29,6 +30,7 @@ import de.steamwar.messages.Message; import de.steamwar.messages.PlayerChatter; import de.steamwar.persistent.Subserver; import de.steamwar.sql.IgnoreSystem; +import de.steamwar.sql.SchematicType; import de.steamwar.velocitycore.ArenaMode; import de.steamwar.velocitycore.ServerStarter; import net.kyori.adventure.text.event.ClickEvent; @@ -46,7 +48,7 @@ public class ChallengeCommand extends SWCommand { } @Register(description = "CHALLENGE_USAGE") - public void challenge(@Validator("arenaPlayer") PlayerChatter sender, @Validator("target") Player target, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { + public void challenge(@Validator("arenaPlayer") PlayerChatter sender, @Validator("target") Player target, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull GameModeConfig arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { FightCommand.createArena(sender, "/challenge " + target.getUsername() + " ", false, arenaMode, map, false, (chatter, mode, m) -> { Player p = sender.getPlayer(); if(challenges.containsKey(target) && challenges.get(target).contains(p)){ @@ -54,7 +56,7 @@ public class ChallengeCommand extends SWCommand { challenges.remove(p); new ServerStarter().arena(mode, map).blueLeader(sender.getPlayer()).redLeader(target).callback( - arena -> Chatter.broadcast().system("CHALLENGE_BROADCAST", new Message("CHALLENGE_BROADCAST_HOVER"), ClickEvent.runCommand("/arena " + arena.getServer().getName()), mode.getGameName(), p, target) + arena -> Chatter.broadcast().system("CHALLENGE_BROADCAST", new Message("CHALLENGE_BROADCAST_HOVER"), ClickEvent.runCommand("/arena " + arena.getServer().getName()), mode.GameName, p, target) ).start(); }else{ if(!challenges.containsKey(p)){ @@ -63,8 +65,8 @@ public class ChallengeCommand extends SWCommand { challenges.get(p).add(target); - sender.system("CHALLENGE_CHALLENGED", target, mode.getGameName()); - Chatter.of(target).system("CHALLENGE_CHALLENGED_TARGET", p, mode.getGameName(), mode.getMaps().size() != 1 ? new Message("CHALLENGE_CHALLENGED_MAP", m) : ""); + sender.system("CHALLENGE_CHALLENGED", target, mode.GameName); + Chatter.of(target).system("CHALLENGE_CHALLENGED_TARGET", p, mode.GameName, mode.Server.Maps.size() != 1 ? new Message("CHALLENGE_CHALLENGED_MAP", m) : ""); Chatter.of(target).system("CHALLENGE_ACCEPT", new Message("CHALLENGE_ACCEPT_HOVER"), ClickEvent.runCommand("/challenge " + p.getUsername() + " " + mode.getChatName() + " " + m)); } diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand.java index 2effbdcf..335e3201 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand.java @@ -21,6 +21,7 @@ package de.steamwar.velocitycore.commands; import com.velocitypowered.api.proxy.Player; import de.steamwar.command.SWCommand; +import de.steamwar.data.GameModeConfig; import de.steamwar.linkage.Linked; import de.steamwar.messages.Chatter; import de.steamwar.messages.Message; @@ -39,8 +40,8 @@ import net.kyori.adventure.text.format.NamedTextColor; import java.awt.*; import java.sql.Timestamp; import java.time.Instant; -import java.util.List; import java.util.*; +import java.util.List; import java.util.concurrent.TimeUnit; import java.util.function.BooleanSupplier; import java.util.logging.Level; @@ -220,7 +221,7 @@ public class CheckCommand extends SWCommand { this.startTime = Timestamp.from(Instant.now()); this.checkList = checkQuestions.get(schematic.getSchemtype()).listIterator(); - ArenaMode mode = ArenaMode.getBySchemType(fightTypes.get(schematic.getSchemtype())); + GameModeConfig mode = ArenaMode.getBySchemType(fightTypes.get(schematic.getSchemtype())); new ServerStarter().test(mode, mode.getRandomMap(), checker.getPlayer()).check(schematic.getId()).callback(subserver -> { currentCheckers.put(checker.user().getUUID(), this); currentSchems.put(schematic.getId(), this); diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/FightCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/FightCommand.java index 95be0879..86ff28cd 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/FightCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/FightCommand.java @@ -21,6 +21,7 @@ package de.steamwar.velocitycore.commands; import com.velocitypowered.api.proxy.Player; import de.steamwar.command.SWCommand; +import de.steamwar.data.GameModeConfig; import de.steamwar.linkage.EventMode; import de.steamwar.linkage.Linked; import de.steamwar.messages.Chatter; @@ -28,6 +29,7 @@ import de.steamwar.messages.Message; import de.steamwar.messages.PlayerChatter; import de.steamwar.persistent.Arenaserver; import de.steamwar.persistent.Subserver; +import de.steamwar.sql.SchematicType; import de.steamwar.velocitycore.ArenaMode; import de.steamwar.velocitycore.ServerStarter; import de.steamwar.velocitycore.inventory.SWInventory; @@ -48,8 +50,8 @@ public class FightCommand extends SWCommand { private static void getModes(Chatter sender, String precommand, boolean historic){ Component start = Component.empty(); - for(ArenaMode mode : ArenaMode.getAllModes()){ - if (!mode.isActive() || mode.isHistoric() != historic) + for(GameModeConfig mode : ArenaMode.getAllModes()){ + if (!mode.isActive() || mode.Server.Historic != historic) continue; String command = precommand + mode.getChatName(); @@ -64,7 +66,7 @@ public class FightCommand extends SWCommand { sender.sendMessage(start); } - static void createArena(PlayerChatter sender, String precommand, boolean allowMerging, ArenaMode arenaMode, String map, boolean historic, FightCallback callback) { + static void createArena(PlayerChatter sender, String precommand, boolean allowMerging, GameModeConfig arenaMode, String map, boolean historic, FightCallback callback) { if (arenaMode == null) { getModes(sender, precommand, historic); return; @@ -80,12 +82,12 @@ public class FightCommand extends SWCommand { } } - private static void suggestMerging(PlayerChatter sender, ArenaMode mode, String map, FightCallback declineMerge) { + private static void suggestMerging(PlayerChatter sender, GameModeConfig mode, String map, FightCallback declineMerge) { Arenaserver mergable = null; synchronized (Subserver.getServerList()) { for (Subserver subserver : Subserver.getServerList()) { if(subserver instanceof Arenaserver arenaserver && - (mode.getInternalName().equals(arenaserver.getMode()) && arenaserver.isAllowMerge() && arenaserver.getRegisteredServer().getPlayersConnected().size() == 1)) { + (mode.configFile.getName().replace(".yml", "").equals(arenaserver.getMode()) && arenaserver.isAllowMerge() && arenaserver.getRegisteredServer().getPlayersConnected().size() == 1)) { mergable = arenaserver; break; } @@ -103,7 +105,7 @@ public class FightCommand extends SWCommand { declineMerge.run(sender, mode, map); }); Arenaserver finalMergable = mergable; - SWItem item = new SWItem(new Message("FIGHT_MERGE_INFO", mode.getGameName(), finalMergable.getMap()), 11); + SWItem item = new SWItem(new Message("FIGHT_MERGE_INFO", mode.GameName, finalMergable.getMap()), 11); item.addLore(new Message("FIGHT_MERGE_INFO_LORE_1", finalMergable.getRegisteredServer().getPlayersConnected().toArray(new Player[1])[0].getUsername())); inventory.addItem(4, item, click -> {}); inventory.addItem(8, new SWItem(new Message("FIGHT_MERGE_ACCEPT"), 10), click -> { @@ -118,15 +120,15 @@ public class FightCommand extends SWCommand { } @Register - public void fight(@Validator("arenaPlayer") PlayerChatter sender, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { + public void fight(@Validator("arenaPlayer") PlayerChatter sender, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull GameModeConfig arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { createArena(sender, "/fight ", true, arenaMode, map, false, (p, mode, m) -> new ServerStarter().arena(mode, m).blueLeader(p.getPlayer()).callback( - arena -> Chatter.broadcast().system("FIGHT_BROADCAST", new Message("FIGHT_BROADCAST_HOVER", p.getPlayer().getUsername()), ClickEvent.runCommand("/arena " + arena.getServer().getName()), mode.getGameName(), p.getPlayer().getUsername()) + arena -> Chatter.broadcast().system("FIGHT_BROADCAST", new Message("FIGHT_BROADCAST_HOVER", p.getPlayer().getUsername()), ClickEvent.runCommand("/arena " + arena.getServer().getName()), mode.GameName, p.getPlayer().getUsername()) ).start() ); } public interface FightCallback { - void run(PlayerChatter player, ArenaMode mode, String map); + void run(PlayerChatter player, GameModeConfig mode, String map); } } diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/HistoricCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/HistoricCommand.java index d45f80f3..cfee955d 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/HistoricCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/HistoricCommand.java @@ -20,11 +20,13 @@ package de.steamwar.velocitycore.commands; import de.steamwar.command.SWCommand; +import de.steamwar.data.GameModeConfig; import de.steamwar.linkage.EventMode; import de.steamwar.linkage.Linked; import de.steamwar.messages.Chatter; import de.steamwar.messages.Message; import de.steamwar.messages.PlayerChatter; +import de.steamwar.sql.SchematicType; import de.steamwar.velocitycore.ArenaMode; import de.steamwar.velocitycore.ServerStarter; import net.kyori.adventure.text.event.ClickEvent; @@ -37,9 +39,9 @@ public class HistoricCommand extends SWCommand { } @Register - public void historic(@Validator("arenaPlayer") PlayerChatter player, @Mapper("historicArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { + public void historic(@Validator("arenaPlayer") PlayerChatter player, @Mapper("historicArenaMode") @OptionalValue("") @AllowNull GameModeConfig arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { FightCommand.createArena(player, "/historic ", true, arenaMode, map, true, (p, mode, m) -> new ServerStarter().arena(mode, m).blueLeader(p.getPlayer()).callback( - arena -> Chatter.broadcast().system("HISTORIC_BROADCAST", new Message("HISTORIC_BROADCAST_HOVER", p), ClickEvent.runCommand("/arena " + arena.getServer().getName()), mode.getGameName(), p.getPlayer()) + arena -> Chatter.broadcast().system("HISTORIC_BROADCAST", new Message("HISTORIC_BROADCAST_HOVER", p), ClickEvent.runCommand("/arena " + arena.getServer().getName()), mode.GameName, p.getPlayer()) ).start()); } } diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/RankCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/RankCommand.java index fa072871..128cf5ea 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/RankCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/RankCommand.java @@ -20,9 +20,11 @@ package de.steamwar.velocitycore.commands; import de.steamwar.command.SWCommand; +import de.steamwar.data.GameModeConfig; import de.steamwar.linkage.Linked; import de.steamwar.messages.Chatter; import de.steamwar.messages.Message; +import de.steamwar.sql.SchematicType; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.UserElo; import de.steamwar.velocitycore.ArenaMode; @@ -46,8 +48,8 @@ public class RankCommand extends SWCommand { if (!sender.user().equals(user)) sender.prefixless("RANK_PLAYER_FOUND", user); - for(ArenaMode mode : ArenaMode.getAllModes()) { - if (!mode.isRanked()) + for(GameModeConfig mode : ArenaMode.getAllModes()) { + if (!mode.Server.Ranked) continue; Optional elo = UserElo.getElo(user.getId(), mode.getSchemTypeOrInternalName()); diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/ReplayCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/ReplayCommand.java index b817a0fe..72b12c4c 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/ReplayCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/ReplayCommand.java @@ -19,17 +19,18 @@ package de.steamwar.velocitycore.commands; +import de.steamwar.command.SWCommand; +import de.steamwar.data.GameModeConfig; import de.steamwar.linkage.EventMode; import de.steamwar.linkage.Linked; -import de.steamwar.velocitycore.ArenaMode; import de.steamwar.messages.Message; +import de.steamwar.messages.PlayerChatter; +import de.steamwar.sql.*; +import de.steamwar.velocitycore.ArenaMode; import de.steamwar.velocitycore.ServerStarter; import de.steamwar.velocitycore.inventory.SWItem; import de.steamwar.velocitycore.inventory.SWListInv; import de.steamwar.velocitycore.inventory.SWStreamInv; -import de.steamwar.command.SWCommand; -import de.steamwar.messages.PlayerChatter; -import de.steamwar.sql.*; import java.util.ArrayList; import java.util.List; @@ -68,7 +69,7 @@ public class ReplayCommand extends SWCommand { if (PunishmentCommand.isPunishedWithMessage(sender, Punishment.PunishmentType.NoFightServer)) return; - ArenaMode mode = ArenaMode.getBySchemType(fight.getSchemType()); + GameModeConfig mode = ArenaMode.getBySchemType(fight.getSchemType()); ServerStarter starter = new ServerStarter().replay(fight.getFightID()).blueLeader(sender.getPlayer()); String map = mode.getRandomMap(); diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/TypeMappers.java b/VelocityCore/src/de/steamwar/velocitycore/commands/TypeMappers.java index 8c2d6c66..001b2b61 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/TypeMappers.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/TypeMappers.java @@ -19,14 +19,16 @@ package de.steamwar.velocitycore.commands; -import de.steamwar.velocitycore.ArenaMode; import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommandUtils; import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeValidator; +import de.steamwar.data.GameModeConfig; import de.steamwar.messages.Chatter; import de.steamwar.messages.PlayerChatter; import de.steamwar.sql.Punishment; +import de.steamwar.sql.SchematicType; +import de.steamwar.velocitycore.ArenaMode; import lombok.experimental.UtilityClass; import java.util.Collection; @@ -45,13 +47,13 @@ public class TypeMappers { return (sender, player, messageSender) -> !PunishmentCommand.isPunishedWithMessage(player, Punishment.PunishmentType.NoFightServer); } - private static TypeMapper arenaModeTypeMapper(boolean historic) { + private static TypeMapper> arenaModeTypeMapper(boolean historic) { return new TypeMapper<>() { @Override - public ArenaMode map(Chatter sender, PreviousArguments previousArguments, String s) { - ArenaMode arenaMode = ArenaMode.getByChat(s); + public GameModeConfig map(Chatter sender, PreviousArguments previousArguments, String s) { + GameModeConfig arenaMode = ArenaMode.getByChat(s); if (arenaMode == null) return null; - if (arenaMode.isHistoric() != historic) return null; + if (arenaMode.Server.Historic != historic) return null; if (!arenaMode.isActive()) return null; return arenaMode; } @@ -74,9 +76,9 @@ public class TypeMappers { @Override public Collection tabCompletes(Chatter sender, PreviousArguments previousArguments, String s) { if (previousArguments.userArgs.length == 0) return null; - ArenaMode arenaMode = ArenaMode.getByChat(previousArguments.userArgs[previousArguments.userArgs.length - 1]); + GameModeConfig arenaMode = ArenaMode.getByChat(previousArguments.userArgs[previousArguments.userArgs.length - 1]); if (arenaMode == null) return null; - return arenaMode.getMaps(); + return arenaMode.Server.Maps; } }; } diff --git a/VelocityCore/src/de/steamwar/velocitycore/listeners/ChatListener.java b/VelocityCore/src/de/steamwar/velocitycore/listeners/ChatListener.java index 407041f2..5b3ccff9 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/listeners/ChatListener.java +++ b/VelocityCore/src/de/steamwar/velocitycore/listeners/ChatListener.java @@ -29,6 +29,7 @@ import com.velocitypowered.api.proxy.ConsoleCommandSource; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.ServerConnection; import com.velocitypowered.api.proxy.server.ServerInfo; +import de.steamwar.data.GameModeConfig; import de.steamwar.linkage.Linked; import de.steamwar.messages.Chatter; import de.steamwar.messages.ChatterGroup; @@ -56,7 +57,7 @@ public class ChatListener extends BasicListener { private static final Logger cmdLogger = Logger.getLogger("Command logger"); - private static final List rankedModes = ArenaMode.getAllModes().stream().filter(ArenaMode::isRanked).map(ArenaMode::getSchemTypeOrInternalName).toList(); + private static final List rankedModes = ArenaMode.getAllModes().stream().filter(gameModeConfig -> gameModeConfig.Server.Ranked).map(GameModeConfig::getSchemTypeOrInternalName).toList(); private static final Set noLogCommands = Set.of("webpw", "webpassword", "web"); diff --git a/VelocityCore/src/de/steamwar/velocitycore/network/handlers/EloPlayerHandler.java b/VelocityCore/src/de/steamwar/velocitycore/network/handlers/EloPlayerHandler.java index f3d4268e..69b13b22 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/network/handlers/EloPlayerHandler.java +++ b/VelocityCore/src/de/steamwar/velocitycore/network/handlers/EloPlayerHandler.java @@ -20,7 +20,7 @@ package de.steamwar.velocitycore.network.handlers; import com.velocitypowered.api.proxy.Player; -import de.steamwar.linkage.EventMode; +import de.steamwar.data.GameModeConfig; import de.steamwar.linkage.Linked; import de.steamwar.messages.Chatter; import de.steamwar.network.packets.PacketHandler; @@ -56,14 +56,14 @@ public class EloPlayerHandler extends PacketHandler { @Handler public void handle(FightEndsPacket fightEndsPacket) { SchematicType schematicType = SchematicType.fromDB(fightEndsPacket.getGameMode()); - ArenaMode arenaMode; + GameModeConfig arenaMode; if (schematicType == null) { arenaMode = ArenaMode.getByInternal(fightEndsPacket.getGameMode()); } else { arenaMode = ArenaMode.getBySchemType(schematicType); } if (arenaMode == null) return; - if (!arenaMode.isRanked()) return; + if (!arenaMode.Server.Ranked) return; if (EloSchemHandler.publicVsPrivate(fightEndsPacket)) return; diff --git a/VelocityCore/src/de/steamwar/velocitycore/network/handlers/EloSchemHandler.java b/VelocityCore/src/de/steamwar/velocitycore/network/handlers/EloSchemHandler.java index 1c718c03..036a6b2d 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/network/handlers/EloSchemHandler.java +++ b/VelocityCore/src/de/steamwar/velocitycore/network/handlers/EloSchemHandler.java @@ -19,6 +19,7 @@ package de.steamwar.velocitycore.network.handlers; +import de.steamwar.data.GameModeConfig; import de.steamwar.linkage.Linked; import de.steamwar.network.packets.PacketHandler; import de.steamwar.network.packets.common.FightEndsPacket; @@ -45,8 +46,8 @@ public class EloSchemHandler extends PacketHandler { public void handle(FightEndsPacket fightEndsPacket) { SchematicType type = SchematicType.fromDB(fightEndsPacket.getGameMode()); if (type == null) return; - ArenaMode arenaMode = ArenaMode.getBySchemType(type); - if (!arenaMode.isRanked()) return; + GameModeConfig arenaMode = ArenaMode.getBySchemType(type); + if (!arenaMode.Server.Ranked) return; if (publicVsPrivate(fightEndsPacket)) return; diff --git a/VelocityCore/src/de/steamwar/velocitycore/network/handlers/PrepareSchemHandler.java b/VelocityCore/src/de/steamwar/velocitycore/network/handlers/PrepareSchemHandler.java index 790d691b..da91ea50 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/network/handlers/PrepareSchemHandler.java +++ b/VelocityCore/src/de/steamwar/velocitycore/network/handlers/PrepareSchemHandler.java @@ -20,14 +20,15 @@ package de.steamwar.velocitycore.network.handlers; import com.velocitypowered.api.proxy.Player; +import de.steamwar.data.GameModeConfig; import de.steamwar.linkage.Linked; -import de.steamwar.velocitycore.ArenaMode; -import de.steamwar.velocitycore.ServerStarter; -import de.steamwar.velocitycore.VelocityCore; import de.steamwar.network.packets.PacketHandler; import de.steamwar.network.packets.client.PrepareSchemPacket; import de.steamwar.sql.SchematicType; import de.steamwar.sql.SteamwarUser; +import de.steamwar.velocitycore.ArenaMode; +import de.steamwar.velocitycore.ServerStarter; +import de.steamwar.velocitycore.VelocityCore; @Linked public class PrepareSchemHandler extends PacketHandler { @@ -36,7 +37,7 @@ public class PrepareSchemHandler extends PacketHandler { public void handle(PrepareSchemPacket packet) { Player player = VelocityCore.getProxy().getPlayer(SteamwarUser.get(packet.getPlayer()).getUUID()).orElse(null); int schematicID = packet.getSchem(); - ArenaMode mode = ArenaMode.getBySchemType(SchematicType.fromDB(packet.getSchemType())); + GameModeConfig mode = ArenaMode.getBySchemType(SchematicType.fromDB(packet.getSchemType())); new ServerStarter().test(mode, mode.getRandomMap(), player).prepare(schematicID).start(); } From e6dea7202434dcf751d56eed57190029516dd1bc Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sat, 25 Oct 2025 22:03:32 +0200 Subject: [PATCH 02/16] Improve YMLWrapper --- .../Data/src/de/steamwar/data/YMLWrapper.java | 19 +++++++-- .../CheckSchemTypeManager.java | 1 - .../src/de/steamwar/data/YMLWrapperImpl.java | 26 +++---------- .../src/de/steamwar/data/YMLWrapperImpl.java | 39 +++---------------- 4 files changed, 26 insertions(+), 59 deletions(-) diff --git a/CommonCore/Data/src/de/steamwar/data/YMLWrapper.java b/CommonCore/Data/src/de/steamwar/data/YMLWrapper.java index 7e9df6b4..9ccf0700 100644 --- a/CommonCore/Data/src/de/steamwar/data/YMLWrapper.java +++ b/CommonCore/Data/src/de/steamwar/data/YMLWrapper.java @@ -25,6 +25,7 @@ import java.io.File; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.function.Function; import java.util.stream.Collectors; @@ -55,13 +56,23 @@ public abstract class YMLWrapper { public abstract String getDefaultGameName(); - public abstract String getString(String path, String defaultValue); + public abstract T get(String path, T defaultValue, Function mapper); - public abstract int getInt(String path, int defaultValue); + public String getString(String path, String defaultValue) { + return get(path, defaultValue, Objects::toString); + } - public abstract double getDouble(String path, double defaultValue); + public int getInt(String path, int defaultValue) { + return get(path, defaultValue, Integer.class::cast); + } - public abstract boolean getBoolean(String path, boolean defaultValue); + public double getDouble(String path, double defaultValue) { + return get(path, defaultValue, Double.class::cast); + } + + public boolean getBoolean(String path, boolean defaultValue) { + return get(path, defaultValue, Boolean.class::cast); + } public final ST getSchematicType(String path, String defaultValue) { String schematicType = getString(path, defaultValue); diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemTypeManager.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemTypeManager.java index 2b0e8317..f881ce51 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemTypeManager.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemTypeManager.java @@ -36,7 +36,6 @@ public class CheckSchemTypeManager { static { 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)); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/data/YMLWrapperImpl.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/data/YMLWrapperImpl.java index 78a050a6..2f07b6b2 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/data/YMLWrapperImpl.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/data/YMLWrapperImpl.java @@ -101,27 +101,13 @@ public class YMLWrapperImpl extends YMLWrapper { } @Override - public String getString(String path, String defaultValue) { + public T get(String path, T defaultValue, Function mapper) { if (config == null) return defaultValue; - return config.getString(pathPrefix + path, defaultValue); - } - - @Override - public int getInt(String path, int defaultValue) { - if (config == null) return defaultValue; - return config.getInt(pathPrefix + path, defaultValue); - } - - @Override - public double getDouble(String path, double defaultValue) { - if (config == null) return defaultValue; - return config.getDouble(pathPrefix + path, defaultValue); - } - - @Override - public boolean getBoolean(String path, boolean defaultValue) { - if (config == null) return defaultValue; - return config.getBoolean(pathPrefix + path, defaultValue); + try { + return mapper.apply(config.get(path, defaultValue)); + } catch (ClassCastException e) { + return defaultValue; + } } @Override diff --git a/VelocityCore/src/de/steamwar/data/YMLWrapperImpl.java b/VelocityCore/src/de/steamwar/data/YMLWrapperImpl.java index 272b018d..c58c4708 100644 --- a/VelocityCore/src/de/steamwar/data/YMLWrapperImpl.java +++ b/VelocityCore/src/de/steamwar/data/YMLWrapperImpl.java @@ -88,41 +88,12 @@ public class YMLWrapperImpl extends YMLWrapper { } @Override - public String getString(String path, String defaultValue) { + public T get(String path, T defaultValue, Function mapper) { Object value = this.document.get(path); - if (value instanceof String) { - return (String) value; - } else { - return defaultValue; - } - } - - @Override - public int getInt(String path, int defaultValue) { - Object value = this.document.get(path); - if (value instanceof Integer) { - return (Integer) value; - } else { - return defaultValue; - } - } - - @Override - public double getDouble(String path, double defaultValue) { - Object value = this.document.get(path); - if (value instanceof Double) { - return (Double) value; - } else { - return defaultValue; - } - } - - @Override - public boolean getBoolean(String path, boolean defaultValue) { - Object value = this.document.get(path); - if (value instanceof Boolean) { - return (Boolean) value; - } else { + if (value == null) return defaultValue; + try { + return mapper.apply(value); + } catch (ClassCastException e) { return defaultValue; } } From 4405d9c25d5108ef3452f2d76eeba99cb67035b3 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sat, 25 Oct 2025 22:08:58 +0200 Subject: [PATCH 03/16] Improve YMLWrapper --- .../Data/src/de/steamwar/data/YMLWrapper.java | 10 ++++++++-- .../src/de/steamwar/data/YMLWrapperImpl.java | 20 ++++++------------- .../src/de/steamwar/data/YMLWrapperImpl.java | 19 +++++------------- 3 files changed, 19 insertions(+), 30 deletions(-) diff --git a/CommonCore/Data/src/de/steamwar/data/YMLWrapper.java b/CommonCore/Data/src/de/steamwar/data/YMLWrapper.java index 9ccf0700..c7813b12 100644 --- a/CommonCore/Data/src/de/steamwar/data/YMLWrapper.java +++ b/CommonCore/Data/src/de/steamwar/data/YMLWrapper.java @@ -83,9 +83,15 @@ public abstract class YMLWrapper { return materialMapper.apply(getString(path, defaultValue).toUpperCase()); } - public abstract List getStringList(String path); + public abstract List get(String path, Function> mapper); - public abstract List getIntList(String path); + public List getStringList(String path) { + return get(path, o -> (List) o); + } + + public List getIntList(String path) { + return get(path, o -> (List) o); + } public final List getSchematicTypeList(String path) { List list = getStringList(path); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/data/YMLWrapperImpl.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/data/YMLWrapperImpl.java index 2f07b6b2..55b749bb 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/data/YMLWrapperImpl.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/data/YMLWrapperImpl.java @@ -111,24 +111,16 @@ public class YMLWrapperImpl extends YMLWrapper { } @Override - public List getStringList(String path) { + public List get(String path, Function> mapper) { if (config == null) return Collections.emptyList(); - List list = config.getStringList(pathPrefix + path); - if (list.isEmpty()) { + List list = config.getList(pathPrefix + path); + if (list == null || list.isEmpty()) { return Collections.emptyList(); - } else { - return Collections.unmodifiableList(list); } - } - - @Override - public List getIntList(String path) { - if (config == null) return Collections.emptyList(); - List list = config.getIntegerList(pathPrefix + path); - if (list.isEmpty()) { + try { + return Collections.unmodifiableList(mapper.apply(list)); + } catch (ClassCastException e) { return Collections.emptyList(); - } else { - return Collections.unmodifiableList(list); } } diff --git a/VelocityCore/src/de/steamwar/data/YMLWrapperImpl.java b/VelocityCore/src/de/steamwar/data/YMLWrapperImpl.java index c58c4708..b5dc7a60 100644 --- a/VelocityCore/src/de/steamwar/data/YMLWrapperImpl.java +++ b/VelocityCore/src/de/steamwar/data/YMLWrapperImpl.java @@ -99,21 +99,12 @@ public class YMLWrapperImpl extends YMLWrapper { } @Override - public List getStringList(String path) { + public List get(String path, Function> mapper) { Object value = this.document.get(path); - if (value instanceof List) { - return Collections.unmodifiableList((List) value); - } else { - return Collections.emptyList(); - } - } - - @Override - public List getIntList(String path) { - Object value = this.document.get(path); - if (value instanceof List) { - return Collections.unmodifiableList((List) value); - } else { + if (value == null) return Collections.emptyList(); + try { + return Collections.unmodifiableList(mapper.apply(value)); + } catch (ClassCastException e) { return Collections.emptyList(); } } From aec03e41a176ede4b9aa1b6d260e3e3b662b0817 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 26 Oct 2025 09:14:34 +0100 Subject: [PATCH 04/16] Improve YMLWrapper --- .../region/fixed/FixedGlobalRegion.java | 5 +- .../bausystem/region/fixed/FixedRegion.java | 5 +- CommonCore/Data/build.gradle.kts | 2 + .../src/de/steamwar/data/GameModeConfig.java | 9 +- .../Data/src/de/steamwar/data/YMLWrapper.java | 97 ++++++++++--- .../src/de/steamwar/fightsystem/Config.java | 5 +- .../CheckSchemTypeManager.java | 5 +- .../src/de/steamwar/data/YMLWrapperImpl.java | 132 ------------------ .../src/de/steamwar/data/YMLWrapperUtils.java | 41 ++++++ .../src/de/steamwar/sql/SQLWrapperImpl.java | 8 +- .../src/de/steamwar/data/YMLWrapperImpl.java | 121 ---------------- .../src/de/steamwar/sql/SQLWrapperImpl.java | 4 +- .../de/steamwar/velocitycore/ArenaMode.java | 4 +- .../src/de/steamwar/sql/SQLWrapperImpl.kt | 39 +++--- 14 files changed, 163 insertions(+), 314 deletions(-) delete mode 100644 SpigotCore/SpigotCore_Main/src/de/steamwar/data/YMLWrapperImpl.java create mode 100644 SpigotCore/SpigotCore_Main/src/de/steamwar/data/YMLWrapperUtils.java delete mode 100644 VelocityCore/src/de/steamwar/data/YMLWrapperImpl.java 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) } } } From d216aac2c4c0c00474f55bca8c4ce934b1848df9 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 26 Oct 2025 09:22:48 +0100 Subject: [PATCH 05/16] Improve YMLWrapper --- .../bausystem/region/fixed/FixedGlobalRegion.java | 5 ++--- .../bausystem/region/fixed/FixedRegion.java | 5 ++--- .../Data/src/de/steamwar/data/GameModeConfig.java | 6 +++++- .../Data/src/de/steamwar/data/YMLWrapper.java | 14 ++------------ .../src/de/steamwar/fightsystem/Config.java | 5 ++--- .../schematicsystem/CheckSchemTypeManager.java | 5 ++--- ...LWrapperUtils.java => GameModeConfigUtils.java} | 2 +- .../src/de/steamwar/sql/SQLWrapperImpl.java | 3 +-- .../src/de/steamwar/sql/SQLWrapperImpl.java | 3 +-- .../src/de/steamwar/velocitycore/ArenaMode.java | 3 +-- .../src/de/steamwar/sql/SQLWrapperImpl.kt | 3 +-- 11 files changed, 20 insertions(+), 34 deletions(-) rename SpigotCore/SpigotCore_Main/src/de/steamwar/data/{YMLWrapperUtils.java => GameModeConfigUtils.java} (97%) 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 af08c4ae..1bf07d5a 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,8 +23,7 @@ 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.YMLWrapper; -import de.steamwar.data.YMLWrapperUtils; +import de.steamwar.data.GameModeConfigUtils; import de.steamwar.sql.SchematicType; import lombok.NonNull; import lombok.Setter; @@ -95,7 +94,7 @@ public final class FixedGlobalRegion implements Region { } }; - private static final GameModeConfig GLOBAL_CONFIG = new GameModeConfig<>(null, YMLWrapperUtils.ToMaterial, YMLWrapper.ToSchematicType, YMLWrapper.ToString, YMLWrapper.ToStaticWarGear); + private static final GameModeConfig GLOBAL_CONFIG = new GameModeConfig<>(null, GameModeConfigUtils.ToMaterial, GameModeConfig.ToSchematicType, GameModeConfig.ToString, GameModeConfig.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 399c5aba..1eb0ab62 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,8 +29,7 @@ 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.YMLWrapper; -import de.steamwar.data.YMLWrapperUtils; +import de.steamwar.data.GameModeConfigUtils; import de.steamwar.sql.SchematicType; import lombok.NonNull; import org.bukkit.Bukkit; @@ -340,7 +339,7 @@ public class FixedRegion implements Region { break; } } - this.gameModeConfig = new GameModeConfig<>(found, YMLWrapperUtils.ToMaterial, YMLWrapper.ToSchematicType, YMLWrapper.ToString, YMLWrapper.ToStaticWarGear); + this.gameModeConfig = new GameModeConfig<>(found, GameModeConfigUtils.ToMaterial, GameModeConfig.ToSchematicType, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear); this.regionData = new RegionData.RegionDataImpl(regionData, WorldData::write); } diff --git a/CommonCore/Data/src/de/steamwar/data/GameModeConfig.java b/CommonCore/Data/src/de/steamwar/data/GameModeConfig.java index ed405522..b9c8919b 100644 --- a/CommonCore/Data/src/de/steamwar/data/GameModeConfig.java +++ b/CommonCore/Data/src/de/steamwar/data/GameModeConfig.java @@ -34,8 +34,12 @@ import java.util.stream.Collectors; @ToString public final class GameModeConfig { - private static final Random random = new Random(); + public static final Function ToString = Function.identity(); + public static final Function ToSchematicType = SchematicType::fromDB; + public static final Function ToStaticWarGear = __ -> "WarGear"; + public static final Function ToInternalName = file -> file.getName().replace(".yml", ""); public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yyyy HH:mm"); + private static final Random random = new Random(); public final boolean loaded; public final File configFile; diff --git a/CommonCore/Data/src/de/steamwar/data/YMLWrapper.java b/CommonCore/Data/src/de/steamwar/data/YMLWrapper.java index 644a8c13..30d6d9ae 100644 --- a/CommonCore/Data/src/de/steamwar/data/YMLWrapper.java +++ b/CommonCore/Data/src/de/steamwar/data/YMLWrapper.java @@ -19,7 +19,6 @@ package de.steamwar.data; -import de.steamwar.sql.SchematicType; import org.yaml.snakeyaml.Yaml; import java.io.File; @@ -32,15 +31,8 @@ import java.util.Objects; import java.util.function.Function; import java.util.stream.Collectors; -public final class YMLWrapper { +final class YMLWrapper { - public static final Function ToString = Function.identity(); - public static final Function ToSchematicType = SchematicType::fromDB; - - public static final Function ToStaticWarGear = __ -> "WarGear"; - public static final Function ToInternalName = file -> file.getName().replace(".yml", ""); - - private final File file; final Function materialMapper; final Function schematicTypeMapper; final Function winconditionMapper; @@ -48,8 +40,7 @@ public final class YMLWrapper { private final boolean canLoad; private final Map document; - public YMLWrapper(File file, Function materialMapper, Function schematicTypeMapper, Function winconditionMapper) { - this.file = file; + YMLWrapper(File file, Function materialMapper, Function schematicTypeMapper, Function winconditionMapper) { this.materialMapper = materialMapper; this.schematicTypeMapper = schematicTypeMapper; this.winconditionMapper = winconditionMapper; @@ -70,7 +61,6 @@ public final class YMLWrapper { } private YMLWrapper(boolean canLoad, Map document, Function materialMapper, Function schematicTypeMapper, Function winconditionMapper) { - this.file = null; this.materialMapper = materialMapper; this.schematicTypeMapper = schematicTypeMapper; this.winconditionMapper = winconditionMapper; diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java index f8e18d4f..93f263bb 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java @@ -20,8 +20,7 @@ package de.steamwar.fightsystem; import de.steamwar.data.GameModeConfig; -import de.steamwar.data.YMLWrapper; -import de.steamwar.data.YMLWrapperUtils; +import de.steamwar.data.GameModeConfigUtils; import de.steamwar.fightsystem.utils.Region; import de.steamwar.fightsystem.winconditions.Winconditions; import de.steamwar.sql.*; @@ -110,7 +109,7 @@ public class Config { Bukkit.getLogger().log(Level.SEVERE, "Arenaconfig fehlt!"); Bukkit.shutdown(); } - GameModeConfig = new GameModeConfig<>(new File(FightSystem.getPlugin().getDataFolder(), configFile), YMLWrapperUtils.ToMaterial, YMLWrapper.ToSchematicType, Winconditions::valueOf, YMLWrapper.ToStaticWarGear); + GameModeConfig = new GameModeConfig<>(new File(FightSystem.getPlugin().getDataFolder(), configFile), GameModeConfigUtils.ToMaterial, de.steamwar.data.GameModeConfig.ToSchematicType, Winconditions::valueOf, de.steamwar.data.GameModeConfig.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 48bd8859..dc9c4ae4 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemTypeManager.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemTypeManager.java @@ -20,8 +20,7 @@ package de.steamwar.schematicsystem; import de.steamwar.data.GameModeConfig; -import de.steamwar.data.YMLWrapper; -import de.steamwar.data.YMLWrapperUtils; +import de.steamwar.data.GameModeConfigUtils; import de.steamwar.sql.SchematicType; import lombok.experimental.UtilityClass; import org.bukkit.Material; @@ -39,7 +38,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<>(configFile, YMLWrapperUtils.ToMaterial, YMLWrapper.ToSchematicType, YMLWrapper.ToString, YMLWrapper.ToStaticWarGear); + GameModeConfig gameModeConfig = new GameModeConfig<>(configFile, GameModeConfigUtils.ToMaterial, GameModeConfig.ToSchematicType, GameModeConfig.ToString, GameModeConfig.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/YMLWrapperUtils.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/data/GameModeConfigUtils.java similarity index 97% rename from SpigotCore/SpigotCore_Main/src/de/steamwar/data/YMLWrapperUtils.java rename to SpigotCore/SpigotCore_Main/src/de/steamwar/data/GameModeConfigUtils.java index 15433cfc..a14aa31e 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/data/YMLWrapperUtils.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/data/GameModeConfigUtils.java @@ -25,7 +25,7 @@ import org.bukkit.Material; import java.util.function.Function; @UtilityClass -public class YMLWrapperUtils { +public class GameModeConfigUtils { public static final Function ToMaterial = material -> { Material mat = Material.getMaterial(material); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SQLWrapperImpl.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SQLWrapperImpl.java index 340daf47..e25e4bb6 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SQLWrapperImpl.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SQLWrapperImpl.java @@ -21,7 +21,6 @@ package de.steamwar.sql; import de.steamwar.core.Core; import de.steamwar.data.GameModeConfig; -import de.steamwar.data.YMLWrapper; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.entity.Player; @@ -39,7 +38,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<>(configFile, YMLWrapper.ToString, YMLWrapper.ToString, YMLWrapper.ToString, YMLWrapper.ToStaticWarGear); + 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; diff --git a/VelocityCore/src/de/steamwar/sql/SQLWrapperImpl.java b/VelocityCore/src/de/steamwar/sql/SQLWrapperImpl.java index cde15d01..156c45e9 100644 --- a/VelocityCore/src/de/steamwar/sql/SQLWrapperImpl.java +++ b/VelocityCore/src/de/steamwar/sql/SQLWrapperImpl.java @@ -22,7 +22,6 @@ 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.YMLWrapper; import de.steamwar.velocitycore.VelocityCore; import de.steamwar.velocitycore.commands.CheckCommand; @@ -40,7 +39,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<>(file, YMLWrapper.ToString, YMLWrapper.ToString, YMLWrapper.ToString, YMLWrapper.ToInternalName); + 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; diff --git a/VelocityCore/src/de/steamwar/velocitycore/ArenaMode.java b/VelocityCore/src/de/steamwar/velocitycore/ArenaMode.java index 53a2e0b0..63c0187e 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/ArenaMode.java +++ b/VelocityCore/src/de/steamwar/velocitycore/ArenaMode.java @@ -20,7 +20,6 @@ package de.steamwar.velocitycore; import de.steamwar.data.GameModeConfig; -import de.steamwar.data.YMLWrapper; import de.steamwar.sql.SchematicType; import lombok.Getter; import lombok.experimental.UtilityClass; @@ -52,7 +51,7 @@ public class ArenaMode { return; for(File file : Arrays.stream(folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))).sorted().toList()) { - GameModeConfig gameModeConfig = new GameModeConfig<>(file, YMLWrapper.ToString, YMLWrapper.ToSchematicType, YMLWrapper.ToString, YMLWrapper.ToInternalName); + GameModeConfig gameModeConfig = new GameModeConfig<>(file, GameModeConfig.ToString, GameModeConfig.ToSchematicType, GameModeConfig.ToString, GameModeConfig.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 714e34d4..f00c4dbd 100644 --- a/WebsiteBackend/src/de/steamwar/sql/SQLWrapperImpl.kt +++ b/WebsiteBackend/src/de/steamwar/sql/SQLWrapperImpl.kt @@ -20,7 +20,6 @@ package de.steamwar.sql import de.steamwar.data.GameModeConfig -import de.steamwar.data.YMLWrapper import java.io.File import java.util.* import java.util.stream.Collectors @@ -30,7 +29,7 @@ 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 gameModeConfig = GameModeConfig(configFile, YMLWrapper.ToString, YMLWrapper.ToString, YMLWrapper.ToString, YMLWrapper.ToStaticWarGear) + val gameModeConfig = GameModeConfig(configFile, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear) if (!gameModeConfig.Schematic.loaded) continue val type = gameModeConfig.Schematic.Type From ef81626e02ee368b9df7f9e903892db6d386729d Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 26 Oct 2025 09:28:24 +0100 Subject: [PATCH 06/16] Remove CheckSchemTypeManager --- .../CheckSchemTypeManager.java | 55 ------------------- .../schematicsystem/SchematicSystem.java | 27 +++++++++ .../commands/schematiccommand/GUI.java | 3 +- .../SchematicCommandUtils.java | 3 +- .../schematiccommand/SchematicMapper.java | 6 +- .../schematiccommand/parts/ModifyPart.java | 3 +- 6 files changed, 33 insertions(+), 64 deletions(-) delete mode 100644 SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemTypeManager.java diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemTypeManager.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemTypeManager.java deleted file mode 100644 index dc9c4ae4..00000000 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemTypeManager.java +++ /dev/null @@ -1,55 +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.schematicsystem; - -import de.steamwar.data.GameModeConfig; -import de.steamwar.data.GameModeConfigUtils; -import de.steamwar.sql.SchematicType; -import lombok.experimental.UtilityClass; -import org.bukkit.Material; - -import java.io.File; -import java.util.HashMap; -import java.util.Map; - -@UtilityClass -public class CheckSchemTypeManager { - - private static final Map> types = new HashMap<>(); - - static { - 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<>(configFile, GameModeConfigUtils.ToMaterial, GameModeConfig.ToSchematicType, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear); - if (gameModeConfig.CheckQuestions.isEmpty() && gameModeConfig.Schematic.ManualCheck) - continue; - types.put(gameModeConfig.Schematic.Type, gameModeConfig); - if (gameModeConfig.Schematic.Type.checkType() != null) { - types.put(gameModeConfig.Schematic.Type.checkType(), gameModeConfig); - } - } - } - } - - public static GameModeConfig get(SchematicType type){ - return types.get(type); - } -} diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/SchematicSystem.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/SchematicSystem.java index 8245209b..a5826c70 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/SchematicSystem.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/SchematicSystem.java @@ -19,21 +19,48 @@ package de.steamwar.schematicsystem; +import de.steamwar.data.GameModeConfig; +import de.steamwar.data.GameModeConfigUtils; import de.steamwar.linkage.AbstractLinker; import de.steamwar.linkage.SpigotLinker; import de.steamwar.message.Message; +import de.steamwar.sql.SchematicType; import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.plugin.java.JavaPlugin; +import java.io.File; +import java.util.HashMap; +import java.util.Map; + public class SchematicSystem extends JavaPlugin { public static final Message MESSAGE = new Message("SchematicSystem", SchematicSystem.class.getClassLoader()); private static SchematicSystem instance; + private static final Map> types = new HashMap<>(); + + public static GameModeConfig getGameModeConfig(SchematicType type){ + return types.get(type); + } + @Override public void onEnable() { instance = this; + File folder = new File(this.getDataFolder().getParentFile(), "FightSystem"); + if(folder.exists()) { + for(File configFile : folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))) { + GameModeConfig gameModeConfig = new GameModeConfig<>(configFile, GameModeConfigUtils.ToMaterial, GameModeConfig.ToSchematicType, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear); + if (gameModeConfig.CheckQuestions.isEmpty() && gameModeConfig.Schematic.ManualCheck) + continue; + types.put(gameModeConfig.Schematic.Type, gameModeConfig); + if (gameModeConfig.Schematic.Type.checkType() != null) { + types.put(gameModeConfig.Schematic.Type.checkType(), gameModeConfig); + } + } + } + SpigotLinker spigotLinker = new SpigotLinker(this, MESSAGE); try { spigotLinker.link(); diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/GUI.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/GUI.java index ece48694..d5428118 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/GUI.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/GUI.java @@ -23,7 +23,6 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard; import de.steamwar.core.Core; import de.steamwar.data.CMDs; import de.steamwar.inventory.*; -import de.steamwar.schematicsystem.CheckSchemTypeManager; import de.steamwar.schematicsystem.SafeSchematicNode; import de.steamwar.schematicsystem.SchematicSystem; import de.steamwar.schematicsystem.autocheck.AutoChecker; @@ -245,7 +244,7 @@ public class GUI { Clipboard finalClipboard = clipboard; List types = SchematicType.values().parallelStream() .filter(SchematicType::isAssignable) - .filter(type -> finalClipboard == null || CheckSchemTypeManager.get(type) == null || AutoChecker.sizeCheck(finalClipboard, CheckSchemTypeManager.get(type)).fastOk()) + .filter(type -> finalClipboard == null || SchematicSystem.getGameModeConfig(type) == null || AutoChecker.sizeCheck(finalClipboard, SchematicSystem.getGameModeConfig(type)).fastOk()) .collect(Collectors.toList()); List> items = types.stream() diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java index 9cccc0b6..03f2f328 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java @@ -26,7 +26,6 @@ import de.steamwar.inventory.SWItem; import de.steamwar.network.NetworkSender; import de.steamwar.network.packets.client.PrepareSchemPacket; import de.steamwar.providers.BauServerInfo; -import de.steamwar.schematicsystem.CheckSchemTypeManager; import de.steamwar.schematicsystem.SchematicSystem; import de.steamwar.schematicsystem.autocheck.AutoChecker; import de.steamwar.schematicsystem.autocheck.AutoCheckerResult; @@ -456,7 +455,7 @@ public class SchematicCommandUtils { return; } - GameModeConfig checkSchemType = CheckSchemTypeManager.get(type); + GameModeConfig checkSchemType = SchematicSystem.getGameModeConfig(type); if (checkSchemType.isAfterDeadline()) { SchematicSystem.MESSAGE.send("UTIL_TYPE_AFTER_DEADLINE", player, checkSchemType.Deadline); return; diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicMapper.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicMapper.java index b3f23092..a7f50dd7 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicMapper.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicMapper.java @@ -21,7 +21,7 @@ package de.steamwar.schematicsystem.commands.schematiccommand; import de.steamwar.command.TypeMapper; import de.steamwar.data.GameModeConfig; -import de.steamwar.schematicsystem.CheckSchemTypeManager; +import de.steamwar.schematicsystem.SchematicSystem; import de.steamwar.sql.NodeMember; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicType; @@ -181,12 +181,12 @@ public class SchematicMapper { return new TypeMapper>() { @Override public Collection tabCompletes(CommandSender commandSender, String[] strings, String s) { - return SchematicType.values().stream().filter(type -> CheckSchemTypeManager.get(type) != null).map(SchematicType::name).collect(Collectors.toList()); + return SchematicType.values().stream().filter(type -> SchematicSystem.getGameModeConfig(type) != null).map(SchematicType::name).collect(Collectors.toList()); } @Override public GameModeConfig map(CommandSender commandSender, String[] previousArguments, String s) { - return SchematicType.values().stream().filter(type -> type.name().equalsIgnoreCase(s)).map(CheckSchemTypeManager::get).findAny().orElse(null); + return SchematicType.values().stream().filter(type -> type.name().equalsIgnoreCase(s)).map(SchematicSystem::getGameModeConfig).findAny().orElse(null); } }; } diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/ModifyPart.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/ModifyPart.java index 58645331..99006559 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/ModifyPart.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/ModifyPart.java @@ -23,7 +23,6 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard; import de.steamwar.command.AbstractSWCommand; import de.steamwar.command.SWCommand; import de.steamwar.linkage.Linked; -import de.steamwar.schematicsystem.CheckSchemTypeManager; import de.steamwar.schematicsystem.SafeSchematicNode; import de.steamwar.schematicsystem.SchematicSystem; import de.steamwar.schematicsystem.autocheck.AutoChecker; @@ -63,7 +62,7 @@ public class ModifyPart extends SWCommand { SchematicType.values().parallelStream() .filter(SchematicType::isAssignable) - .filter(type -> finalClipboard == null || CheckSchemTypeManager.get(type) == null || AutoChecker.sizeCheck(finalClipboard, CheckSchemTypeManager.get(type)).fastOk()) + .filter(type -> finalClipboard == null || SchematicSystem.getGameModeConfig(type) == null || AutoChecker.sizeCheck(finalClipboard, SchematicSystem.getGameModeConfig(type)).fastOk()) .forEach(type -> { TextComponent component = new TextComponent(type.name() + " "); component.setColor(ChatColor.GRAY); From 167a6b6dc4803c51ef2e921335688ed91595de3a Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 26 Oct 2025 09:36:44 +0100 Subject: [PATCH 07/16] Unify SchematicType loading --- CommonCore/Data/build.gradle.kts | 3 -- CommonCore/SQL/build.gradle.kts | 2 + .../src/de/steamwar/data/GameModeConfig.java | 0 .../src/de/steamwar/data/YMLWrapper.java | 0 .../SQL/src/de/steamwar/sql/SQLWrapper.java | 9 +++-- .../src/de/steamwar/sql/SchematicType.java | 31 ++++++++++++++- .../src/de/steamwar/sql/SQLWrapperImpl.java | 32 +--------------- .../src/de/steamwar/sql/SQLWrapperImpl.java | 38 +++++-------------- .../src/de/steamwar/sql/SQLWrapperImpl.kt | 36 ++---------------- 9 files changed, 53 insertions(+), 98 deletions(-) rename CommonCore/{Data => SQL}/src/de/steamwar/data/GameModeConfig.java (100%) rename CommonCore/{Data => SQL}/src/de/steamwar/data/YMLWrapper.java (100%) 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") From 184bd12cb1db98e6bef4c7c8212afb2280672943 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 26 Oct 2025 09:39:17 +0100 Subject: [PATCH 08/16] Improve SQLWrapperImpl --- VelocityCore/src/de/steamwar/sql/SQLWrapperImpl.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/VelocityCore/src/de/steamwar/sql/SQLWrapperImpl.java b/VelocityCore/src/de/steamwar/sql/SQLWrapperImpl.java index 73a1d393..0c2aa004 100644 --- a/VelocityCore/src/de/steamwar/sql/SQLWrapperImpl.java +++ b/VelocityCore/src/de/steamwar/sql/SQLWrapperImpl.java @@ -36,10 +36,8 @@ public class SQLWrapperImpl implements SQLWrapper { @Override public void processSchematicType(GameModeConfig gameModeConfig, SchematicType type) { - if (!gameModeConfig.CheckQuestions.isEmpty()) { - CheckCommand.setCheckQuestions(type.checkType(), gameModeConfig.CheckQuestions); - } if (type.checkType() != null) { + CheckCommand.setCheckQuestions(type.checkType(), gameModeConfig.CheckQuestions); CheckCommand.addFightType(type.checkType(), type); } } From 3e918d031d719610f3181e4c9b7f7a816e6f3cf9 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 26 Oct 2025 09:42:55 +0100 Subject: [PATCH 09/16] Fix compilation --- WebsiteBackend/src/de/steamwar/routes/Data.kt | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/WebsiteBackend/src/de/steamwar/routes/Data.kt b/WebsiteBackend/src/de/steamwar/routes/Data.kt index 4770e250..669737fa 100644 --- a/WebsiteBackend/src/de/steamwar/routes/Data.kt +++ b/WebsiteBackend/src/de/steamwar/routes/Data.kt @@ -27,7 +27,6 @@ import de.steamwar.sql.SchematicType import de.steamwar.sql.SteamwarUser import de.steamwar.sql.Team import de.steamwar.sql.UserPerm -import de.steamwar.sql.loadSchematicTypes import de.steamwar.util.fetchData import io.ktor.http.* import io.ktor.server.application.* @@ -38,7 +37,7 @@ import kotlinx.serialization.Serializable import org.bspfsystems.yamlconfiguration.file.YamlConfiguration import java.io.File import java.net.InetSocketAddress -import java.util.UUID +import java.util.* @Serializable data class ResponseSchematicType(val name: String, val db: String) @@ -82,9 +81,7 @@ fun Route.configureDataRoutes() { call.respond(Team.getAll().map { ResponseTeam(it) }) } get("/schematicTypes") { - val types = mutableListOf() - loadSchematicTypes(types, mutableMapOf()) - call.respond(types.filter { !it.check() }.map { ResponseSchematicType(it.name(), it.toDB()) }) + call.respond(SchematicType.values().filter { !it.check() }.map { ResponseSchematicType(it.name(), it.toDB()) }) } get("/gamemodes") { call.respond( From c6dbece55056b21672327524fd1b753413a48d65 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 26 Oct 2025 12:34:16 +0100 Subject: [PATCH 10/16] Improve GameModeConfig --- .../de/steamwar/bausystem/region/Region.java | 4 +- .../region/fixed/FixedGlobalRegion.java | 5 +- .../bausystem/region/fixed/FixedRegion.java | 6 +- .../{data => sql}/GameModeConfig.java | 157 ++++++++++-------- .../SQL/src/de/steamwar/sql/SQLWrapper.java | 3 +- .../src/de/steamwar/sql/SchematicType.java | 30 ++-- .../de/steamwar/{data => sql}/YMLWrapper.java | 31 ++-- .../src/de/steamwar/fightsystem/Config.java | 6 +- .../autocheck/AutoChecker15.java | 6 +- .../schematiccommand/SchematicCommand15.java | 4 +- .../autocheck/AutoChecker8.java | 6 +- .../schematiccommand/SchematicCommand8.java | 4 +- .../schematicsystem/SchematicSystem.java | 8 +- .../autocheck/AutoChecker.java | 10 +- .../autocheck/AutoCheckerResult.java | 4 +- .../schematiccommand/SchematicCommand.java | 6 +- .../SchematicCommandUtils.java | 6 +- .../schematiccommand/SchematicMapper.java | 8 +- .../schematiccommand/parts/CheckPart.java | 10 +- .../src/de/steamwar/sql/SQLWrapperImpl.java | 4 +- .../de/steamwar/velocitycore/ArenaMode.java | 20 +-- .../steamwar/velocitycore/ServerStarter.java | 6 +- .../steamwar/velocitycore/ServerVersion.java | 4 +- .../velocitycore/commands/BauCommand.java | 4 +- .../commands/BuilderCloudCommand.java | 4 +- .../commands/ChallengeCommand.java | 5 +- .../velocitycore/commands/CheckCommand.java | 4 +- .../velocitycore/commands/FightCommand.java | 12 +- .../commands/HistoricCommand.java | 5 +- .../velocitycore/commands/RankCommand.java | 4 +- .../velocitycore/commands/ReplayCommand.java | 4 +- .../velocitycore/commands/TypeMappers.java | 10 +- .../velocitycore/listeners/ChatListener.java | 2 +- .../network/handlers/EloPlayerHandler.java | 4 +- .../network/handlers/EloSchemHandler.java | 4 +- .../network/handlers/PrepareSchemHandler.java | 4 +- 36 files changed, 212 insertions(+), 202 deletions(-) rename CommonCore/SQL/src/de/steamwar/{data => sql}/GameModeConfig.java (82%) rename CommonCore/SQL/src/de/steamwar/{data => sql}/YMLWrapper.java (84%) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java index 4b98caf1..0a022cfe 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java @@ -22,7 +22,7 @@ package de.steamwar.bausystem.region; import com.sk89q.worldedit.extent.clipboard.Clipboard; import de.steamwar.bausystem.utils.FlatteningWrapper; import de.steamwar.bausystem.utils.PasteBuilder; -import de.steamwar.data.GameModeConfig; +import de.steamwar.sql.GameModeConfig; import de.steamwar.sql.SchematicType; import lombok.NonNull; import org.bukkit.Location; @@ -67,7 +67,7 @@ public interface Region { Area getTestblockArea(); @NonNull - GameModeConfig getGameModeConfig(); + GameModeConfig getGameModeConfig(); @NonNull RegionHistory getHistory(); 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 1bf07d5a..cac519e0 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 @@ -22,9 +22,8 @@ package de.steamwar.bausystem.region.fixed; 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.GameModeConfigUtils; -import de.steamwar.sql.SchematicType; +import de.steamwar.sql.GameModeConfig; import lombok.NonNull; import lombok.Setter; import org.bukkit.Location; @@ -94,7 +93,7 @@ public final class FixedGlobalRegion implements Region { } }; - private static final GameModeConfig GLOBAL_CONFIG = new GameModeConfig<>(null, GameModeConfigUtils.ToMaterial, GameModeConfig.ToSchematicType, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear); + private static final GameModeConfig GLOBAL_CONFIG = new GameModeConfig<>(null, GameModeConfigUtils.ToMaterial, GameModeConfig.ToString, GameModeConfig.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 1eb0ab62..ce48b5b6 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 @@ -28,8 +28,8 @@ import de.steamwar.bausystem.utils.FlatteningWrapper; 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.GameModeConfigUtils; +import de.steamwar.sql.GameModeConfig; import de.steamwar.sql.SchematicType; import lombok.NonNull; import org.bukkit.Bukkit; @@ -60,7 +60,7 @@ public class FixedRegion implements Region { private final Area testblock; private final int floorLevel; private final int waterLevel; - private final GameModeConfig gameModeConfig; + private final GameModeConfig gameModeConfig; private final RegionData regionData; private final RegionHistory regionHistory = new RegionHistory.Impl(20); @@ -339,7 +339,7 @@ public class FixedRegion implements Region { break; } } - this.gameModeConfig = new GameModeConfig<>(found, GameModeConfigUtils.ToMaterial, GameModeConfig.ToSchematicType, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear); + this.gameModeConfig = new GameModeConfig<>(found, GameModeConfigUtils.ToMaterial, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear); this.regionData = new RegionData.RegionDataImpl(regionData, WorldData::write); } diff --git a/CommonCore/SQL/src/de/steamwar/data/GameModeConfig.java b/CommonCore/SQL/src/de/steamwar/sql/GameModeConfig.java similarity index 82% rename from CommonCore/SQL/src/de/steamwar/data/GameModeConfig.java rename to CommonCore/SQL/src/de/steamwar/sql/GameModeConfig.java index b9c8919b..942df6d1 100644 --- a/CommonCore/SQL/src/de/steamwar/data/GameModeConfig.java +++ b/CommonCore/SQL/src/de/steamwar/sql/GameModeConfig.java @@ -17,12 +17,12 @@ * along with this program. If not, see . */ -package de.steamwar.data; +package de.steamwar.sql; -import de.steamwar.sql.SchematicType; import lombok.ToString; import java.io.File; +import java.lang.reflect.Field; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.Instant; @@ -32,10 +32,9 @@ import java.util.function.Function; import java.util.stream.Collectors; @ToString -public final class GameModeConfig { +public final class GameModeConfig { public static final Function ToString = Function.identity(); - public static final Function ToSchematicType = SchematicType::fromDB; public static final Function ToStaticWarGear = __ -> "WarGear"; public static final Function ToInternalName = file -> file.getName().replace(".yml", ""); public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yyyy HH:mm"); @@ -44,10 +43,11 @@ public final class GameModeConfig { public final boolean loaded; public final File configFile; - public final Server Server; + public final ServerConfig Server; /** * Submission deadline for schematics in 'dd.MM.yyyy HH:mm' format + * * @implSpec {@code null} by default */ public final Date Deadline; @@ -58,9 +58,9 @@ public final class GameModeConfig { * @implSpec Disables check schem type if missing */ public final List CheckQuestions; - public final Times Times; - public final Arena Arena; - public final Schematic Schematic; + public final TimesConfig Times; + public final ArenaConfig Arena; + public final SchematicConfig Schematic; /** * The name of the game mode presented to the players @@ -83,28 +83,39 @@ public final class GameModeConfig { * @implSpec {@code +} by default */ public final String TeamChatPrefix; - public final Blue Blue; - public final Red Red; + public final BlueConfig Blue; + public final RedConfig Red; /** * The list of active win conditions */ public final List WinConditions; - public final WinConditionParams WinConditionParams; - public final Kits Kits; + public final WinConditionParamsConfig WinConditionParams; + public final KitsConfig Kits; /** * A list of integers containing the waiting time of this enter stage in the fight */ public final List EnterStages; - public final Techhider Techhider; + public final TechhiderConfig Techhider; - public GameModeConfig(File file, Function materialMapper, Function schematicTypeMapper, Function winconditionMapper, Function defaultGameName) { - YMLWrapper loader = new YMLWrapper<>(file, materialMapper, schematicTypeMapper, winconditionMapper); + private static final Field Schematic_TypeField; + + static { + try { + Schematic_TypeField = SchematicConfig.class.getDeclaredField("Type"); + Schematic_TypeField.setAccessible(true); + } catch (NoSuchFieldException e) { + throw new SecurityException(e.getMessage(), e); + } + } + + public GameModeConfig(File file, Function materialMapper, Function winconditionMapper, Function defaultGameName) { + YMLWrapper loader = new YMLWrapper<>(file, materialMapper, winconditionMapper); configFile = file; loaded = loader.canLoad(); - Server = new Server(loader.with("Server")); + Server = new ServerConfig(loader.with("Server")); String deadlineString = loader.getString("Deadline", null); if (deadlineString != null) { @@ -120,25 +131,44 @@ public final class GameModeConfig { } CheckQuestions = loader.getStringList("CheckQuestions"); - Times = new Times(loader.with("Times")); + Times = new TimesConfig(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")); + Schematic = new SchematicConfig<>(loader.with("Schematic")); GameName = loader.getString("GameName", defaultGameName.apply(file)); ActiveMonths = loader.getIntList("ActiveMonths"); TeamChatPrefix = loader.getString("TeamChatPrefix", "+"); - Blue = new Blue(loader.with("Blue")); - Red = new Red(loader.with("Red")); + Blue = new BlueConfig(loader.with("Blue")); + Red = new RedConfig(loader.with("Red")); WinConditions = Collections.unmodifiableList(loader.getStringList("WinConditions").stream().map(loader.winconditionMapper).collect(Collectors.toList())); - WinConditionParams = new WinConditionParams<>(loader.with("WinConditionParams")); - Kits = new Kits<>(loader.with("Kits")); + WinConditionParams = new WinConditionParamsConfig<>(loader.with("WinConditionParams")); + Kits = new KitsConfig<>(loader.with("Kits")); EnterStages = loader.getIntList("EnterStages"); - Techhider = new Techhider<>(loader.with("Techhider")); + Techhider = new TechhiderConfig<>(loader.with("Techhider")); - Arena = new Arena(loader.with("Arena"), Schematic.Size, EnterStages); + Arena = new ArenaConfig(loader.with("Arena"), Schematic.Size, EnterStages); + + if (Schematic.Type != null) return; + if (!Schematic.loaded) return; + String Schematic_Type = loader.with("Schematic").getString("Type", "Normal"); + if (Schematic_Type.equals("Normal")) return; + String Schematic_Shortcut = Schematic.Shortcut; + + SchematicType checktype = null; + String material = loader.with("Schematic").getString("Material", "STONE_BUTTON"); + + if (!CheckQuestions.isEmpty()) { + checktype = new SchematicType("C" + Schematic_Type, "C" + Schematic_Shortcut, SchematicType.Type.CHECK_TYPE, null, material, true); + } + SchematicType current = new SchematicType(Schematic_Type, Schematic_Shortcut, Server.loaded ? SchematicType.Type.FIGHT_TYPE : SchematicType.Type.NORMAL, checktype, material, Deadline, Schematic.ManualCheck); + try { + Schematic_TypeField.set(Schematic, current); + } catch (IllegalAccessException e) { + throw new SecurityException(e.getMessage(), e); + } } @ToString - public static final class Server { + public static final class ServerConfig { public final boolean loaded; @@ -183,7 +213,7 @@ public final class GameModeConfig { */ public final boolean Ranked; - private Server(YMLWrapper loader) { + private ServerConfig(YMLWrapper loader) { loaded = loader.canLoad(); Folder = loader.getString("Folder", null); ServerJar = loader.getString("ServerJar", null); @@ -196,7 +226,7 @@ public final class GameModeConfig { } @ToString - public static final class Times { + public static final class TimesConfig { public final boolean loaded; /** @@ -234,7 +264,7 @@ public final class GameModeConfig { */ public final int SpectatorDuration; - private Times(YMLWrapper loader) { + private TimesConfig(YMLWrapper loader) { loaded = loader.canLoad(); NoPlayersOnlineDuration = loader.getInt("NoPlayersOnlineDuration", 300); PreSchemPasteDuration = loader.getInt("PreSchemPasteDuration", 120); @@ -245,7 +275,7 @@ public final class GameModeConfig { } @ToString - public static final class Arena { + public static final class ArenaConfig { public final boolean loaded; @@ -259,12 +289,12 @@ public final class GameModeConfig { /** * The outer border of the arena, measured in blocks around the schematic areas */ - public final Schem2Border Schem2Border; + public final Schem2BorderConfig Schem2Border; /** * The offset the teams spawn relative to the center of their area */ - public final SpawnOffset SpawnOffset; + public final SpawnOffsetConfig SpawnOffset; /** * The size of the team areas are expanded around the schematics @@ -308,11 +338,11 @@ public final class GameModeConfig { */ public final boolean NoFloor; - private Arena(YMLWrapper loader, Schematic.Size Size, List EnterStages) { + private ArenaConfig(YMLWrapper loader, SchematicConfig.SizeConfig Size, List EnterStages) { loaded = loader.canLoad(); WaterDepth = loader.getInt("WaterDepth", 0); - Schem2Border = new Schem2Border(loader.with("Schem2Border")); - SpawnOffset = new SpawnOffset(loader.with("SpawnOffset"), Size); + Schem2Border = new Schem2BorderConfig(loader.with("Schem2Border")); + SpawnOffset = new SpawnOffsetConfig(loader.with("SpawnOffset"), Size); BorderFromSchematic = loader.getInt("BorderFromSchematic", 21); GroundWalkable = loader.getBoolean("GroundWalkable", true); DisableSnowMelt = loader.getBoolean("DisableSnowMelt", false); @@ -322,7 +352,7 @@ public final class GameModeConfig { } @ToString - public static final class Schem2Border { + public static final class Schem2BorderConfig { public final boolean loaded; @@ -336,7 +366,7 @@ public final class GameModeConfig { */ public final int z; - private Schem2Border(YMLWrapper loader) { + private Schem2BorderConfig(YMLWrapper loader) { loaded = loader.canLoad(); x = loader.getInt("x", 24); z = loader.getInt("z", 24); @@ -344,7 +374,7 @@ public final class GameModeConfig { } @ToString - public static final class SpawnOffset { + public static final class SpawnOffsetConfig { public final boolean loaded; @@ -363,7 +393,7 @@ public final class GameModeConfig { */ public final double z; - private SpawnOffset(YMLWrapper loader, Schematic.Size Size) { + private SpawnOffsetConfig(YMLWrapper loader, SchematicConfig.SizeConfig Size) { loaded = loader.canLoad(); x = loader.getDouble("x", 0); y = loader.getDouble("y", Size.y); @@ -373,31 +403,31 @@ public final class GameModeConfig { } @ToString - public static final class Schematic { + public static final class SchematicConfig { public final boolean loaded; /** * The size of the schematics */ - public final Size Size; + public final SizeConfig Size; /** * Used for GameModes with a technic area */ - public final Inset Inset; + public final InsetConfig Inset; /** * The schematic type that can be chosen in this arena * * @implSpec {@code Normal} by default */ - public final ST Type; + public final SchematicType Type; /** * The schematic types that are also allowed to be chosen in this arena */ - public final List SubTypes; + public final List SubTypes; /** * Shortcut of the schematic type @@ -496,10 +526,10 @@ public final class GameModeConfig { */ public final Map, Integer> Limited; - private Schematic(YMLWrapper loader) { + private SchematicConfig(YMLWrapper loader) { loaded = loader.canLoad(); - Size = new Size(loader.with("Size")); - Inset = new Inset(loader.with("Inset")); + Size = new SizeConfig(loader.with("Size")); + Inset = new InsetConfig(loader.with("Inset")); Type = loader.getSchematicType("Type", "Normal"); SubTypes = loader.getSchematicTypeList("SubTypes"); Shortcut = loader.getString("Shortcut", ""); @@ -532,7 +562,7 @@ public final class GameModeConfig { } @ToString - public static final class Size { + public static final class SizeConfig { public final boolean loaded; @@ -551,7 +581,7 @@ public final class GameModeConfig { */ public final int z; - private Size(YMLWrapper loader) { + private SizeConfig(YMLWrapper loader) { loaded = loader.canLoad(); x = loader.getInt("x", 0); y = loader.getInt("y", 0); @@ -560,7 +590,7 @@ public final class GameModeConfig { } @ToString - public static final class Inset { + public static final class InsetConfig { public final boolean loaded; @@ -584,7 +614,7 @@ public final class GameModeConfig { */ public final int bottom; - private Inset(YMLWrapper loader) { + private InsetConfig(YMLWrapper loader) { loaded = loader.canLoad(); x = loader.getInt("x", 0); z = loader.getInt("z", 0); @@ -595,7 +625,7 @@ public final class GameModeConfig { } @ToString - public static final class Blue { + public static final class BlueConfig { public final boolean loaded; @@ -609,7 +639,7 @@ public final class GameModeConfig { */ public final String Prefix; - private Blue(YMLWrapper loader) { + private BlueConfig(YMLWrapper loader) { loaded = loader.canLoad(); Name = loader.getString("Name", "Blau"); Prefix = loader.getString("Prefix", "§3"); @@ -617,7 +647,7 @@ public final class GameModeConfig { } @ToString - public static final class Red { + public static final class RedConfig { public final boolean loaded; @@ -631,7 +661,7 @@ public final class GameModeConfig { */ public final String Prefix; - private Red(YMLWrapper loader) { + private RedConfig(YMLWrapper loader) { loaded = loader.canLoad(); Name = loader.getString("Name", "Rot"); Prefix = loader.getString("Prefix", "§c"); @@ -639,7 +669,7 @@ public final class GameModeConfig { } @ToString - public static final class WinConditionParams { + public static final class WinConditionParamsConfig { public final boolean loaded; @@ -683,7 +713,7 @@ public final class GameModeConfig { */ public final int TechKoTime; - private WinConditionParams(YMLWrapper loader) { + private WinConditionParamsConfig(YMLWrapper loader) { loaded = loader.canLoad(); TimeoutTime = loader.getInt("TimeoutTime", 1200); PercentWin = loader.getDouble("PercentWin", 7.0); @@ -695,7 +725,7 @@ public final class GameModeConfig { } @ToString - public static final class Kits { + public static final class KitsConfig { public final boolean loaded; @@ -732,7 +762,7 @@ public final class GameModeConfig { */ public final List ForbiddenItems; - private Kits(YMLWrapper loader) { + private KitsConfig(YMLWrapper loader) { loaded = loader.canLoad(); File = loader.getString("File", "kits.yml"); MemberDefault = loader.getString("MemberDefault", "default"); @@ -743,7 +773,7 @@ public final class GameModeConfig { } @ToString - public static final class Techhider { + public static final class TechhiderConfig { public final boolean loaded; @@ -771,7 +801,7 @@ public final class GameModeConfig { */ public final Set HiddenBlockEntities; - private Techhider(YMLWrapper loader) { + private TechhiderConfig(YMLWrapper loader) { loaded = loader.canLoad(); Active = loader.getBoolean("Active", false); ObfuscateWith = loader.getMaterial("ObfuscateWith", "end_stone"); @@ -816,12 +846,7 @@ public final class GameModeConfig { public String getSchemTypeOrInternalName() { if (Schematic.loaded) { - ST type = Schematic.Type; - if (type instanceof SchematicType) { - return ((SchematicType) type).toDB(); - } else if (type instanceof String) { - return (String) type; - } + return Schematic.Type.toDB(); } return configFile.getName().replace(".yml", ""); } diff --git a/CommonCore/SQL/src/de/steamwar/sql/SQLWrapper.java b/CommonCore/SQL/src/de/steamwar/sql/SQLWrapper.java index ac1424f0..0dbdde69 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/SQLWrapper.java +++ b/CommonCore/SQL/src/de/steamwar/sql/SQLWrapper.java @@ -20,7 +20,6 @@ package de.steamwar.sql; import de.steamwar.ImplementationProvider; -import de.steamwar.data.GameModeConfig; import java.io.File; @@ -29,7 +28,7 @@ public interface SQLWrapper { File getSchemTypesFolder(); - default void processSchematicType(GameModeConfig gameModeConfig, SchematicType type) { + default void processSchematicType(GameModeConfig gameModeConfig) { } 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 3cab7f0a..04af18ef 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/SchematicType.java +++ b/CommonCore/SQL/src/de/steamwar/sql/SchematicType.java @@ -19,7 +19,6 @@ package de.steamwar.sql; -import de.steamwar.data.GameModeConfig; import de.steamwar.sql.internal.SqlTypeMapper; import lombok.Getter; import lombok.extern.slf4j.Slf4j; @@ -47,28 +46,18 @@ public class SchematicType { 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; - + GameModeConfig gameModeConfig = new GameModeConfig<>(configFile, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear); + if (gameModeConfig.Schematic.Type == null) continue; + if (tmpFromDB.containsKey(gameModeConfig.Schematic.Type.toDB())) continue; + SchematicType current = gameModeConfig.Schematic.Type; 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 checkType = current.checkType; + 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); + tmpFromDB.put(current.toDB(), current); + SQLWrapper.impl.processSchematicType(gameModeConfig); } } time = System.currentTimeMillis() - time; @@ -143,6 +132,7 @@ public class SchematicType { } public static SchematicType fromDB(String input) { + if (fromDB == null) return null; return fromDB.get(input.toLowerCase()); } diff --git a/CommonCore/SQL/src/de/steamwar/data/YMLWrapper.java b/CommonCore/SQL/src/de/steamwar/sql/YMLWrapper.java similarity index 84% rename from CommonCore/SQL/src/de/steamwar/data/YMLWrapper.java rename to CommonCore/SQL/src/de/steamwar/sql/YMLWrapper.java index 30d6d9ae..d7afa5e6 100644 --- a/CommonCore/SQL/src/de/steamwar/data/YMLWrapper.java +++ b/CommonCore/SQL/src/de/steamwar/sql/YMLWrapper.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package de.steamwar.data; +package de.steamwar.sql; import org.yaml.snakeyaml.Yaml; @@ -31,18 +31,16 @@ import java.util.Objects; import java.util.function.Function; import java.util.stream.Collectors; -final class YMLWrapper { +final class YMLWrapper { final Function materialMapper; - final Function schematicTypeMapper; final Function winconditionMapper; private final boolean canLoad; private final Map document; - YMLWrapper(File file, Function materialMapper, Function schematicTypeMapper, Function winconditionMapper) { + YMLWrapper(File file, Function materialMapper, Function winconditionMapper) { this.materialMapper = materialMapper; - this.schematicTypeMapper = schematicTypeMapper; this.winconditionMapper = winconditionMapper; Yaml yaml = new Yaml(); @@ -60,9 +58,8 @@ final class YMLWrapper { this.canLoad = canLoad; } - private YMLWrapper(boolean canLoad, Map document, Function materialMapper, Function schematicTypeMapper, Function winconditionMapper) { + private YMLWrapper(boolean canLoad, Map document, Function materialMapper, Function winconditionMapper) { this.materialMapper = materialMapper; - this.schematicTypeMapper = schematicTypeMapper; this.winconditionMapper = winconditionMapper; this.canLoad = canLoad; this.document = document; @@ -72,24 +69,26 @@ final class YMLWrapper { return canLoad; } - public 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<>(true, (Map) value, materialMapper, winconditionMapper); } } - return new YMLWrapper<>(false, Collections.emptyMap(), materialMapper, schematicTypeMapper, winconditionMapper); + return new YMLWrapper<>(false, Collections.emptyMap(), materialMapper, winconditionMapper); } 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); + T mapped = mapper.apply(value); + if (mapped != null) return mapped; } catch (ClassCastException e) { - return defaultValue; + // Ignore exception } + return defaultValue; } public String getString(String path, String defaultValue) { @@ -108,9 +107,9 @@ final class YMLWrapper { return get(path, defaultValue, Boolean.class::cast); } - public ST getSchematicType(String path, String defaultValue) { + public SchematicType getSchematicType(String path, String defaultValue) { String schematicType = getString(path, defaultValue); - return schematicTypeMapper.apply(schematicType); + return SchematicType.fromDB(schematicType); } public M getMaterial(String path, String defaultValue) { @@ -135,12 +134,12 @@ final class YMLWrapper { return get(path, o -> (List) o); } - public List getSchematicTypeList(String path) { + public List getSchematicTypeList(String path) { List list = getStringList(path); if (list.isEmpty()) { return Collections.emptyList(); } else { - return Collections.unmodifiableList(list.stream().map(schematicTypeMapper).collect(Collectors.toList())); + return Collections.unmodifiableList(list.stream().map(SchematicType::fromDB).collect(Collectors.toList())); } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java index 93f263bb..3b8d2378 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java @@ -19,7 +19,7 @@ package de.steamwar.fightsystem; -import de.steamwar.data.GameModeConfig; +import de.steamwar.sql.GameModeConfig; import de.steamwar.data.GameModeConfigUtils; import de.steamwar.fightsystem.utils.Region; import de.steamwar.fightsystem.winconditions.Winconditions; @@ -45,7 +45,7 @@ public class Config { public static final World world = Bukkit.getWorlds().get(0); - public static final GameModeConfig GameModeConfig; + public static final GameModeConfig GameModeConfig; //arena parameter public static final Region BluePasteRegion; @@ -109,7 +109,7 @@ public class Config { Bukkit.getLogger().log(Level.SEVERE, "Arenaconfig fehlt!"); Bukkit.shutdown(); } - GameModeConfig = new GameModeConfig<>(new File(FightSystem.getPlugin().getDataFolder(), configFile), GameModeConfigUtils.ToMaterial, de.steamwar.data.GameModeConfig.ToSchematicType, Winconditions::valueOf, de.steamwar.data.GameModeConfig.ToStaticWarGear); + GameModeConfig = new GameModeConfig<>(new File(FightSystem.getPlugin().getDataFolder(), configFile), GameModeConfigUtils.ToMaterial, Winconditions::valueOf, de.steamwar.sql.GameModeConfig.ToStaticWarGear); File worldConfigFile = new File(world.getWorldFolder(), "config.yml"); if(!worldConfigFile.exists()) { diff --git a/SchematicSystem/SchematicSystem_15/src/de/steamwar/schematicsystem/autocheck/AutoChecker15.java b/SchematicSystem/SchematicSystem_15/src/de/steamwar/schematicsystem/autocheck/AutoChecker15.java index d77f615c..97cf6de3 100644 --- a/SchematicSystem/SchematicSystem_15/src/de/steamwar/schematicsystem/autocheck/AutoChecker15.java +++ b/SchematicSystem/SchematicSystem_15/src/de/steamwar/schematicsystem/autocheck/AutoChecker15.java @@ -24,7 +24,7 @@ import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BaseBlock; -import de.steamwar.data.GameModeConfig; +import de.steamwar.sql.GameModeConfig; import de.steamwar.sql.SchematicType; import org.bukkit.Material; @@ -119,7 +119,7 @@ public class AutoChecker15 implements AutoChecker.IAutoChecker { } @Override - public AutoCheckerResult check(Clipboard clipboard, GameModeConfig type) { + public AutoCheckerResult check(Clipboard clipboard, GameModeConfig type) { return AutoCheckerResult.builder() .type(type) .height(clipboard.getDimensions().getBlockY()) @@ -131,7 +131,7 @@ public class AutoChecker15 implements AutoChecker.IAutoChecker { } @Override - public AutoCheckerResult sizeCheck(Clipboard clipboard, GameModeConfig type) { + public AutoCheckerResult sizeCheck(Clipboard clipboard, GameModeConfig type) { return AutoCheckerResult.builder() .type(type) .height(clipboard.getDimensions().getBlockY()) diff --git a/SchematicSystem/SchematicSystem_15/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommand15.java b/SchematicSystem/SchematicSystem_15/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommand15.java index 1a7f8a97..62fa611e 100644 --- a/SchematicSystem/SchematicSystem_15/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommand15.java +++ b/SchematicSystem/SchematicSystem_15/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommand15.java @@ -31,7 +31,7 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypes; -import de.steamwar.data.GameModeConfig; +import de.steamwar.sql.GameModeConfig; import de.steamwar.schematicsystem.autocheck.AutoCheckerResult; import de.steamwar.schematicsystem.autocheck.BlockPos; import de.steamwar.sql.SchematicType; @@ -42,7 +42,7 @@ import java.util.stream.Collectors; public class SchematicCommand15 implements SchematicCommand.ISchematicCommand { @Override - public Clipboard fixClipboard(Clipboard clipboard, AutoCheckerResult result, GameModeConfig type) throws Exception { + public Clipboard fixClipboard(Clipboard clipboard, AutoCheckerResult result, GameModeConfig type) throws Exception { for (BlockPos blockPos : result.getBlockScanResult().getRecords()) { BlockVector3 vector = BlockVector3.at(blockPos.getX(), blockPos.getY(), blockPos.getZ()); clipboard.setBlock(vector, clipboard.getFullBlock(vector).toBaseBlock(new CompoundTag(Collections.emptyMap()))); diff --git a/SchematicSystem/SchematicSystem_8/src/de/steamwar/schematicsystem/autocheck/AutoChecker8.java b/SchematicSystem/SchematicSystem_8/src/de/steamwar/schematicsystem/autocheck/AutoChecker8.java index cf457f62..c98b136a 100644 --- a/SchematicSystem/SchematicSystem_8/src/de/steamwar/schematicsystem/autocheck/AutoChecker8.java +++ b/SchematicSystem/SchematicSystem_8/src/de/steamwar/schematicsystem/autocheck/AutoChecker8.java @@ -25,7 +25,7 @@ import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.regions.Region; -import de.steamwar.data.GameModeConfig; +import de.steamwar.sql.GameModeConfig; import de.steamwar.sql.SchematicType; import org.bukkit.Material; @@ -149,7 +149,7 @@ public class AutoChecker8 implements AutoChecker.IAutoChecker { } @Override - public AutoCheckerResult check(Clipboard clipboard, GameModeConfig type) { + public AutoCheckerResult check(Clipboard clipboard, GameModeConfig type) { AutoChecker.BlockScanResult blockScanResult = new AutoChecker.BlockScanResult(); scan(blockScanResult, clipboard); @@ -164,7 +164,7 @@ public class AutoChecker8 implements AutoChecker.IAutoChecker { } @Override - public AutoCheckerResult sizeCheck(Clipboard clipboard, GameModeConfig type) { + public AutoCheckerResult sizeCheck(Clipboard clipboard, GameModeConfig type) { return AutoCheckerResult.builder() .type(type) .height(clipboard.getDimensions().getBlockY()) diff --git a/SchematicSystem/SchematicSystem_8/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommand8.java b/SchematicSystem/SchematicSystem_8/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommand8.java index 58c334cd..e873ea49 100644 --- a/SchematicSystem/SchematicSystem_8/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommand8.java +++ b/SchematicSystem/SchematicSystem_8/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommand8.java @@ -24,7 +24,7 @@ import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.function.operation.ForwardExtentCopy; import com.sk89q.worldedit.function.operation.Operations; -import de.steamwar.data.GameModeConfig; +import de.steamwar.sql.GameModeConfig; import de.steamwar.schematicsystem.autocheck.AutoCheckerResult; import de.steamwar.sql.SchematicType; import org.bukkit.Material; @@ -32,7 +32,7 @@ import org.bukkit.Material; public class SchematicCommand8 implements SchematicCommand.ISchematicCommand { @Override - public Clipboard fixClipboard(Clipboard clipboard, AutoCheckerResult result, GameModeConfig type) throws Exception { + public Clipboard fixClipboard(Clipboard clipboard, AutoCheckerResult result, GameModeConfig type) throws Exception { return null; } diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/SchematicSystem.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/SchematicSystem.java index a5826c70..b75ddbdf 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/SchematicSystem.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/SchematicSystem.java @@ -19,7 +19,7 @@ package de.steamwar.schematicsystem; -import de.steamwar.data.GameModeConfig; +import de.steamwar.sql.GameModeConfig; import de.steamwar.data.GameModeConfigUtils; import de.steamwar.linkage.AbstractLinker; import de.steamwar.linkage.SpigotLinker; @@ -38,9 +38,9 @@ public class SchematicSystem extends JavaPlugin { private static SchematicSystem instance; - private static final Map> types = new HashMap<>(); + private static final Map> types = new HashMap<>(); - public static GameModeConfig getGameModeConfig(SchematicType type){ + public static GameModeConfig getGameModeConfig(SchematicType type){ return types.get(type); } @@ -51,7 +51,7 @@ public class SchematicSystem extends JavaPlugin { File folder = new File(this.getDataFolder().getParentFile(), "FightSystem"); if(folder.exists()) { for(File configFile : folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))) { - GameModeConfig gameModeConfig = new GameModeConfig<>(configFile, GameModeConfigUtils.ToMaterial, GameModeConfig.ToSchematicType, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear); + GameModeConfig gameModeConfig = new GameModeConfig<>(configFile, GameModeConfigUtils.ToMaterial, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear); if (gameModeConfig.CheckQuestions.isEmpty() && gameModeConfig.Schematic.ManualCheck) continue; types.put(gameModeConfig.Schematic.Type, gameModeConfig); diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/autocheck/AutoChecker.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/autocheck/AutoChecker.java index ac4220fe..eb464553 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/autocheck/AutoChecker.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/autocheck/AutoChecker.java @@ -21,7 +21,7 @@ package de.steamwar.schematicsystem.autocheck; import com.sk89q.worldedit.extent.clipboard.Clipboard; import de.steamwar.core.VersionDependent; -import de.steamwar.data.GameModeConfig; +import de.steamwar.sql.GameModeConfig; import de.steamwar.schematicsystem.SchematicSystem; import de.steamwar.sql.SchematicType; import lombok.Getter; @@ -32,19 +32,19 @@ import java.util.*; public class AutoChecker { - public static AutoCheckerResult check(Clipboard clipboard, GameModeConfig type) { + public static AutoCheckerResult check(Clipboard clipboard, GameModeConfig type) { return impl.check(clipboard, type); } - public static AutoCheckerResult sizeCheck(Clipboard clipboard, GameModeConfig type) { + public static AutoCheckerResult sizeCheck(Clipboard clipboard, GameModeConfig type) { return impl.sizeCheck(clipboard, type); } private static final IAutoChecker impl = VersionDependent.getVersionImpl(SchematicSystem.getInstance()); public interface IAutoChecker { - AutoCheckerResult check(Clipboard clipboard, GameModeConfig type); - AutoCheckerResult sizeCheck(Clipboard clipboard, GameModeConfig type); + AutoCheckerResult check(Clipboard clipboard, GameModeConfig type); + AutoCheckerResult sizeCheck(Clipboard clipboard, GameModeConfig type); } @Getter diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/autocheck/AutoCheckerResult.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/autocheck/AutoCheckerResult.java index 9aad0edb..60ab9070 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/autocheck/AutoCheckerResult.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/autocheck/AutoCheckerResult.java @@ -20,7 +20,7 @@ package de.steamwar.schematicsystem.autocheck; import de.steamwar.core.Core; -import de.steamwar.data.GameModeConfig; +import de.steamwar.sql.GameModeConfig; import de.steamwar.schematicsystem.SchematicSystem; import de.steamwar.sql.SchematicType; import lombok.Builder; @@ -38,7 +38,7 @@ import java.util.Map; @Getter @ToString public class AutoCheckerResult { - private final GameModeConfig type; + private final GameModeConfig type; private final int width; private final int height; private final int depth; diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommand.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommand.java index 5b9add07..90c6d3c7 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommand.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommand.java @@ -27,7 +27,7 @@ import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeValidator; import de.steamwar.core.VersionDependent; -import de.steamwar.data.GameModeConfig; +import de.steamwar.sql.GameModeConfig; import de.steamwar.linkage.Linked; import de.steamwar.schematicsystem.SchematicSystem; import de.steamwar.schematicsystem.autocheck.AutoCheckerResult; @@ -113,7 +113,7 @@ public class SchematicCommand extends SWCommand { } @ClassMapper(value = GameModeConfig.class, local = true) - public static TypeMapper> gameModeConfigTypeMapper() { + public static TypeMapper> gameModeConfigTypeMapper() { return SchematicMapper.gameModeConfigTypeMapper(); } @@ -150,7 +150,7 @@ public class SchematicCommand extends SWCommand { public static final ISchematicCommand impl = VersionDependent.getVersionImpl(SchematicSystem.getInstance()); public interface ISchematicCommand { - Clipboard fixClipboard(Clipboard clipboard, AutoCheckerResult result, GameModeConfig type) throws Exception; + Clipboard fixClipboard(Clipboard clipboard, AutoCheckerResult result, GameModeConfig type) throws Exception; void createCopy(EditSession editSession, Clipboard clipboard) throws WorldEditException; } } diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java index 03f2f328..cea1122c 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java @@ -20,7 +20,7 @@ package de.steamwar.schematicsystem.commands.schematiccommand; import com.sk89q.worldedit.extent.clipboard.Clipboard; -import de.steamwar.data.GameModeConfig; +import de.steamwar.sql.GameModeConfig; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import de.steamwar.network.NetworkSender; @@ -312,7 +312,7 @@ public class SchematicCommandUtils { } } - public static void check(Player player, Clipboard clipboard, GameModeConfig type, String schemName, boolean gui) { + public static void check(Player player, Clipboard clipboard, GameModeConfig type, String schemName, boolean gui) { AutoCheckerResult result = AutoChecker.check(clipboard, type); if(!result.isOk()) { result.sendErrorMessage(player, schemName); @@ -455,7 +455,7 @@ public class SchematicCommandUtils { return; } - GameModeConfig checkSchemType = SchematicSystem.getGameModeConfig(type); + GameModeConfig checkSchemType = SchematicSystem.getGameModeConfig(type); if (checkSchemType.isAfterDeadline()) { SchematicSystem.MESSAGE.send("UTIL_TYPE_AFTER_DEADLINE", player, checkSchemType.Deadline); return; diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicMapper.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicMapper.java index a7f50dd7..157e8d2d 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicMapper.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicMapper.java @@ -20,7 +20,7 @@ package de.steamwar.schematicsystem.commands.schematiccommand; import de.steamwar.command.TypeMapper; -import de.steamwar.data.GameModeConfig; +import de.steamwar.sql.GameModeConfig; import de.steamwar.schematicsystem.SchematicSystem; import de.steamwar.sql.NodeMember; import de.steamwar.sql.SchematicNode; @@ -177,15 +177,15 @@ public class SchematicMapper { }; } - public static TypeMapper> gameModeConfigTypeMapper() { - return new TypeMapper>() { + public static TypeMapper> gameModeConfigTypeMapper() { + return new TypeMapper>() { @Override public Collection tabCompletes(CommandSender commandSender, String[] strings, String s) { return SchematicType.values().stream().filter(type -> SchematicSystem.getGameModeConfig(type) != null).map(SchematicType::name).collect(Collectors.toList()); } @Override - public GameModeConfig map(CommandSender commandSender, String[] previousArguments, String s) { + public GameModeConfig map(CommandSender commandSender, String[] previousArguments, String s) { return SchematicType.values().stream().filter(type -> type.name().equalsIgnoreCase(s)).map(SchematicSystem::getGameModeConfig).findAny().orElse(null); } }; diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/CheckPart.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/CheckPart.java index bf0f0c8e..9e3be830 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/CheckPart.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/CheckPart.java @@ -28,7 +28,7 @@ import com.sk89q.worldedit.session.ClipboardHolder; import de.steamwar.command.AbstractSWCommand; import de.steamwar.command.SWCommand; import de.steamwar.core.Core; -import de.steamwar.data.GameModeConfig; +import de.steamwar.sql.GameModeConfig; import de.steamwar.linkage.Linked; import de.steamwar.schematicsystem.SchematicSystem; import de.steamwar.schematicsystem.autocheck.AutoChecker; @@ -54,7 +54,7 @@ public class CheckPart extends SWCommand { } @Register("check") - public void checkCommand(Player player, @Validator("isOwnerSchematicValidator") SchematicNode node, GameModeConfig type) { + public void checkCommand(Player player, @Validator("isOwnerSchematicValidator") SchematicNode node, GameModeConfig type) { try { check(player, new SchematicData(node).load(), type, node.getName(), false); } catch (IOException e) { @@ -63,7 +63,7 @@ public class CheckPart extends SWCommand { } @Register(value = {"check", "clipboard"}) - public void checkClipboardCommand(Player player, @ErrorMessage("UTIL_CHECK_TYPE_NOT_FOUND") GameModeConfig type) { + public void checkClipboardCommand(Player player, @ErrorMessage("UTIL_CHECK_TYPE_NOT_FOUND") GameModeConfig type) { try { check(player, WorldEdit.getInstance().getSessionManager().findByName(player.getName()).getClipboard().getClipboard(), type, "clipboard", false); } catch (EmptyClipboardException e) { @@ -72,7 +72,7 @@ public class CheckPart extends SWCommand { } @Register(value = {"check", "selection"}) - public void checkSelectionCommand(Player player, @ErrorMessage("UTIL_CHECK_TYPE_NOT_FOUND") GameModeConfig type) { + public void checkSelectionCommand(Player player, @ErrorMessage("UTIL_CHECK_TYPE_NOT_FOUND") GameModeConfig type) { try { Clipboard clipboard = new BlockArrayClipboard(WorldEdit.getInstance().getSessionManager().findByName(player.getName()).getSelection(new BukkitWorld(player.getWorld()))); EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(player.getWorld()), -1); @@ -88,7 +88,7 @@ public class CheckPart extends SWCommand { } @Register("fix") - public void fixSchematicCommand(Player player, @ErrorMessage("UTIL_CHECK_TYPE_NOT_FOUND") GameModeConfig type) { + public void fixSchematicCommand(Player player, @ErrorMessage("UTIL_CHECK_TYPE_NOT_FOUND") GameModeConfig type) { if(Core.getVersion() < 15) { SchematicSystem.MESSAGE.send("COMMAND_FIX_WRONG_VERSION", player); return; diff --git a/VelocityCore/src/de/steamwar/sql/SQLWrapperImpl.java b/VelocityCore/src/de/steamwar/sql/SQLWrapperImpl.java index 0c2aa004..1868fd9f 100644 --- a/VelocityCore/src/de/steamwar/sql/SQLWrapperImpl.java +++ b/VelocityCore/src/de/steamwar/sql/SQLWrapperImpl.java @@ -21,7 +21,6 @@ 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.velocitycore.VelocityCore; import de.steamwar.velocitycore.commands.CheckCommand; @@ -35,7 +34,8 @@ public class SQLWrapperImpl implements SQLWrapper { } @Override - public void processSchematicType(GameModeConfig gameModeConfig, SchematicType type) { + public void processSchematicType(GameModeConfig gameModeConfig) { + SchematicType type = gameModeConfig.Schematic.Type; if (type.checkType() != null) { CheckCommand.setCheckQuestions(type.checkType(), gameModeConfig.CheckQuestions); CheckCommand.addFightType(type.checkType(), type); diff --git a/VelocityCore/src/de/steamwar/velocitycore/ArenaMode.java b/VelocityCore/src/de/steamwar/velocitycore/ArenaMode.java index 63c0187e..9707bdd9 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/ArenaMode.java +++ b/VelocityCore/src/de/steamwar/velocitycore/ArenaMode.java @@ -19,7 +19,7 @@ package de.steamwar.velocitycore; -import de.steamwar.data.GameModeConfig; +import de.steamwar.sql.GameModeConfig; import de.steamwar.sql.SchematicType; import lombok.Getter; import lombok.experimental.UtilityClass; @@ -30,11 +30,11 @@ import java.util.*; @UtilityClass public class ArenaMode { - private static final Map> byChat = new HashMap<>(); - private static final Map> byInternal = new HashMap<>(); - private static final Map> bySchemType = new HashMap<>(); + private static final Map> byChat = new HashMap<>(); + private static final Map> byInternal = new HashMap<>(); + private static final Map> bySchemType = new HashMap<>(); @Getter - private static final List> allModes = new LinkedList<>(); + private static final List> allModes = new LinkedList<>(); static { init(); @@ -51,7 +51,7 @@ public class ArenaMode { return; 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.ToSchematicType, GameModeConfig.ToString, GameModeConfig.ToInternalName); + GameModeConfig gameModeConfig = new GameModeConfig<>(file, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToInternalName); if (!gameModeConfig.Server.loaded) continue; allModes.add(gameModeConfig); @@ -65,24 +65,24 @@ public class ArenaMode { } } - public static GameModeConfig getByChat(String name){ + public static GameModeConfig getByChat(String name){ return byChat.get(name.toLowerCase()); } - public static GameModeConfig getByInternal(String name){ + public static GameModeConfig getByInternal(String name){ return byInternal.get(name); } public static List getAllChatNames(boolean historic) { List chatNames = new LinkedList<>(); - for(GameModeConfig mode : byInternal.values()){ + for(GameModeConfig mode : byInternal.values()){ if(mode.isActive() && historic == mode.Server.Historic) chatNames.addAll(mode.Server.ChatNames); } return chatNames; } - public static GameModeConfig getBySchemType(SchematicType schemType){ + public static GameModeConfig getBySchemType(SchematicType schemType){ return bySchemType.get(schemType); } } diff --git a/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java b/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java index 31f73773..3b56256a 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java +++ b/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java @@ -22,7 +22,7 @@ package de.steamwar.velocitycore; import com.velocitypowered.api.proxy.Player; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.velocity.platform.VelocityViaConfig; -import de.steamwar.data.GameModeConfig; +import de.steamwar.sql.GameModeConfig; import de.steamwar.messages.Chatter; import de.steamwar.persistent.Arenaserver; import de.steamwar.persistent.Bauserver; @@ -80,7 +80,7 @@ public class ServerStarter { private final Set playersToSend = new HashSet<>(); private final Map arguments = new HashMap<>(); - public ServerStarter arena(GameModeConfig mode, String map) { + public ServerStarter arena(GameModeConfig mode, String map) { portrange = ARENA_PORTS; serverNameProvider = port -> mode.GameName + (port - portrange.start); version = ServerVersion.from(mode); @@ -116,7 +116,7 @@ public class ServerStarter { return this; } - public ServerStarter test(GameModeConfig mode, String map, Player owner) { + public ServerStarter test(GameModeConfig mode, String map, Player owner) { arena(mode, map); buildWithTemp(owner); portrange = BAU_PORTS; diff --git a/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java b/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java index 260bbec6..5d3689f9 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java +++ b/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java @@ -20,7 +20,7 @@ package de.steamwar.velocitycore; import com.velocitypowered.api.network.ProtocolVersion; -import de.steamwar.data.GameModeConfig; +import de.steamwar.sql.GameModeConfig; import de.steamwar.sql.SchematicType; import lombok.AllArgsConstructor; import lombok.Getter; @@ -115,7 +115,7 @@ public enum ServerVersion { private static final Pattern terminatingNumber = Pattern.compile("(\\d+)$"); - public static ServerVersion from(GameModeConfig type) { + public static ServerVersion from(GameModeConfig type) { Matcher matcher = terminatingNumber.matcher(type.Server.Folder); matcher.find(); return ServerVersion.valueOf((type.Server.Spigot ? "SPIGOT_" : "PAPER_") + matcher.group(1)); diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/BauCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/BauCommand.java index 48ab4d05..0d679ca9 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/BauCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/BauCommand.java @@ -23,7 +23,7 @@ import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeValidator; -import de.steamwar.data.GameModeConfig; +import de.steamwar.sql.GameModeConfig; import de.steamwar.linkage.EventMode; import de.steamwar.linkage.Linked; import de.steamwar.linkage.LinkedInstance; @@ -240,7 +240,7 @@ public class BauCommand extends SWCommand { @Register("test") @Register("testarena") - public void testarena(PlayerChatter sender, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull GameModeConfig arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { + public void testarena(PlayerChatter sender, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull GameModeConfig arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { FightCommand.createArena(sender, "/bau testarena ", false, arenaMode, map, false, (chatter, mode, m) -> new ServerStarter().test(mode, m, sender.getPlayer()).start() ); diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/BuilderCloudCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/BuilderCloudCommand.java index 6dc12264..5ae01fe7 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/BuilderCloudCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/BuilderCloudCommand.java @@ -19,7 +19,7 @@ package de.steamwar.velocitycore.commands; -import de.steamwar.data.GameModeConfig; +import de.steamwar.sql.GameModeConfig; import de.steamwar.linkage.Linked; import de.steamwar.sql.SchematicType; import de.steamwar.velocitycore.ArenaMode; @@ -87,7 +87,7 @@ public class BuilderCloudCommand extends SWCommand { } @Register(value = "deploy", description = "BUILDERCLOUD_DEPLOY_USAGE") - public void deploy(Chatter sender, @Mapper("nonHistoricArenaMode") GameModeConfig arenaMode, @ErrorMessage("BUILDERCLOUD_VERSION") ServerVersion version, @Mapper("map") String map) { + public void deploy(Chatter sender, @Mapper("nonHistoricArenaMode") GameModeConfig arenaMode, @ErrorMessage("BUILDERCLOUD_VERSION") ServerVersion version, @Mapper("map") String map) { if(!mapFile(version, map).exists()) { sender.system("BUILDERCLOUD_UNKNOWN_MAP"); return; diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/ChallengeCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/ChallengeCommand.java index 024d4de4..c9ab1f84 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/ChallengeCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/ChallengeCommand.java @@ -22,7 +22,7 @@ package de.steamwar.velocitycore.commands; import com.velocitypowered.api.proxy.Player; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeValidator; -import de.steamwar.data.GameModeConfig; +import de.steamwar.sql.GameModeConfig; import de.steamwar.linkage.EventMode; import de.steamwar.linkage.Linked; import de.steamwar.messages.Chatter; @@ -31,7 +31,6 @@ import de.steamwar.messages.PlayerChatter; import de.steamwar.persistent.Subserver; import de.steamwar.sql.IgnoreSystem; import de.steamwar.sql.SchematicType; -import de.steamwar.velocitycore.ArenaMode; import de.steamwar.velocitycore.ServerStarter; import net.kyori.adventure.text.event.ClickEvent; @@ -48,7 +47,7 @@ public class ChallengeCommand extends SWCommand { } @Register(description = "CHALLENGE_USAGE") - public void challenge(@Validator("arenaPlayer") PlayerChatter sender, @Validator("target") Player target, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull GameModeConfig arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { + public void challenge(@Validator("arenaPlayer") PlayerChatter sender, @Validator("target") Player target, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull GameModeConfig arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { FightCommand.createArena(sender, "/challenge " + target.getUsername() + " ", false, arenaMode, map, false, (chatter, mode, m) -> { Player p = sender.getPlayer(); if(challenges.containsKey(target) && challenges.get(target).contains(p)){ diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand.java index 335e3201..218028bd 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand.java @@ -21,7 +21,7 @@ package de.steamwar.velocitycore.commands; import com.velocitypowered.api.proxy.Player; import de.steamwar.command.SWCommand; -import de.steamwar.data.GameModeConfig; +import de.steamwar.sql.GameModeConfig; import de.steamwar.linkage.Linked; import de.steamwar.messages.Chatter; import de.steamwar.messages.Message; @@ -221,7 +221,7 @@ public class CheckCommand extends SWCommand { this.startTime = Timestamp.from(Instant.now()); this.checkList = checkQuestions.get(schematic.getSchemtype()).listIterator(); - GameModeConfig mode = ArenaMode.getBySchemType(fightTypes.get(schematic.getSchemtype())); + GameModeConfig mode = ArenaMode.getBySchemType(fightTypes.get(schematic.getSchemtype())); new ServerStarter().test(mode, mode.getRandomMap(), checker.getPlayer()).check(schematic.getId()).callback(subserver -> { currentCheckers.put(checker.user().getUUID(), this); currentSchems.put(schematic.getId(), this); diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/FightCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/FightCommand.java index 86ff28cd..1c1d8bd2 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/FightCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/FightCommand.java @@ -21,7 +21,7 @@ package de.steamwar.velocitycore.commands; import com.velocitypowered.api.proxy.Player; import de.steamwar.command.SWCommand; -import de.steamwar.data.GameModeConfig; +import de.steamwar.sql.GameModeConfig; import de.steamwar.linkage.EventMode; import de.steamwar.linkage.Linked; import de.steamwar.messages.Chatter; @@ -50,7 +50,7 @@ public class FightCommand extends SWCommand { private static void getModes(Chatter sender, String precommand, boolean historic){ Component start = Component.empty(); - for(GameModeConfig mode : ArenaMode.getAllModes()){ + for(GameModeConfig mode : ArenaMode.getAllModes()){ if (!mode.isActive() || mode.Server.Historic != historic) continue; @@ -66,7 +66,7 @@ public class FightCommand extends SWCommand { sender.sendMessage(start); } - static void createArena(PlayerChatter sender, String precommand, boolean allowMerging, GameModeConfig arenaMode, String map, boolean historic, FightCallback callback) { + static void createArena(PlayerChatter sender, String precommand, boolean allowMerging, GameModeConfig arenaMode, String map, boolean historic, FightCallback callback) { if (arenaMode == null) { getModes(sender, precommand, historic); return; @@ -82,7 +82,7 @@ public class FightCommand extends SWCommand { } } - private static void suggestMerging(PlayerChatter sender, GameModeConfig mode, String map, FightCallback declineMerge) { + private static void suggestMerging(PlayerChatter sender, GameModeConfig mode, String map, FightCallback declineMerge) { Arenaserver mergable = null; synchronized (Subserver.getServerList()) { for (Subserver subserver : Subserver.getServerList()) { @@ -120,7 +120,7 @@ public class FightCommand extends SWCommand { } @Register - public void fight(@Validator("arenaPlayer") PlayerChatter sender, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull GameModeConfig arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { + public void fight(@Validator("arenaPlayer") PlayerChatter sender, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull GameModeConfig arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { createArena(sender, "/fight ", true, arenaMode, map, false, (p, mode, m) -> new ServerStarter().arena(mode, m).blueLeader(p.getPlayer()).callback( arena -> Chatter.broadcast().system("FIGHT_BROADCAST", new Message("FIGHT_BROADCAST_HOVER", p.getPlayer().getUsername()), ClickEvent.runCommand("/arena " + arena.getServer().getName()), mode.GameName, p.getPlayer().getUsername()) @@ -129,6 +129,6 @@ public class FightCommand extends SWCommand { } public interface FightCallback { - void run(PlayerChatter player, GameModeConfig mode, String map); + void run(PlayerChatter player, GameModeConfig mode, String map); } } diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/HistoricCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/HistoricCommand.java index cfee955d..639b25f5 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/HistoricCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/HistoricCommand.java @@ -20,14 +20,13 @@ package de.steamwar.velocitycore.commands; import de.steamwar.command.SWCommand; -import de.steamwar.data.GameModeConfig; +import de.steamwar.sql.GameModeConfig; import de.steamwar.linkage.EventMode; import de.steamwar.linkage.Linked; import de.steamwar.messages.Chatter; import de.steamwar.messages.Message; import de.steamwar.messages.PlayerChatter; import de.steamwar.sql.SchematicType; -import de.steamwar.velocitycore.ArenaMode; import de.steamwar.velocitycore.ServerStarter; import net.kyori.adventure.text.event.ClickEvent; @@ -39,7 +38,7 @@ public class HistoricCommand extends SWCommand { } @Register - public void historic(@Validator("arenaPlayer") PlayerChatter player, @Mapper("historicArenaMode") @OptionalValue("") @AllowNull GameModeConfig arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { + public void historic(@Validator("arenaPlayer") PlayerChatter player, @Mapper("historicArenaMode") @OptionalValue("") @AllowNull GameModeConfig arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { FightCommand.createArena(player, "/historic ", true, arenaMode, map, true, (p, mode, m) -> new ServerStarter().arena(mode, m).blueLeader(p.getPlayer()).callback( arena -> Chatter.broadcast().system("HISTORIC_BROADCAST", new Message("HISTORIC_BROADCAST_HOVER", p), ClickEvent.runCommand("/arena " + arena.getServer().getName()), mode.GameName, p.getPlayer()) ).start()); diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/RankCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/RankCommand.java index 128cf5ea..b0b3e944 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/RankCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/RankCommand.java @@ -20,7 +20,7 @@ package de.steamwar.velocitycore.commands; import de.steamwar.command.SWCommand; -import de.steamwar.data.GameModeConfig; +import de.steamwar.sql.GameModeConfig; import de.steamwar.linkage.Linked; import de.steamwar.messages.Chatter; import de.steamwar.messages.Message; @@ -48,7 +48,7 @@ public class RankCommand extends SWCommand { if (!sender.user().equals(user)) sender.prefixless("RANK_PLAYER_FOUND", user); - for(GameModeConfig mode : ArenaMode.getAllModes()) { + for(GameModeConfig mode : ArenaMode.getAllModes()) { if (!mode.Server.Ranked) continue; diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/ReplayCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/ReplayCommand.java index 72b12c4c..e4d8b3e0 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/ReplayCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/ReplayCommand.java @@ -20,7 +20,7 @@ package de.steamwar.velocitycore.commands; import de.steamwar.command.SWCommand; -import de.steamwar.data.GameModeConfig; +import de.steamwar.sql.GameModeConfig; import de.steamwar.linkage.EventMode; import de.steamwar.linkage.Linked; import de.steamwar.messages.Message; @@ -69,7 +69,7 @@ public class ReplayCommand extends SWCommand { if (PunishmentCommand.isPunishedWithMessage(sender, Punishment.PunishmentType.NoFightServer)) return; - GameModeConfig mode = ArenaMode.getBySchemType(fight.getSchemType()); + GameModeConfig mode = ArenaMode.getBySchemType(fight.getSchemType()); ServerStarter starter = new ServerStarter().replay(fight.getFightID()).blueLeader(sender.getPlayer()); String map = mode.getRandomMap(); diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/TypeMappers.java b/VelocityCore/src/de/steamwar/velocitycore/commands/TypeMappers.java index 001b2b61..94c7f085 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/TypeMappers.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/TypeMappers.java @@ -23,7 +23,7 @@ import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommandUtils; import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeValidator; -import de.steamwar.data.GameModeConfig; +import de.steamwar.sql.GameModeConfig; import de.steamwar.messages.Chatter; import de.steamwar.messages.PlayerChatter; import de.steamwar.sql.Punishment; @@ -47,11 +47,11 @@ public class TypeMappers { return (sender, player, messageSender) -> !PunishmentCommand.isPunishedWithMessage(player, Punishment.PunishmentType.NoFightServer); } - private static TypeMapper> arenaModeTypeMapper(boolean historic) { + private static TypeMapper> arenaModeTypeMapper(boolean historic) { return new TypeMapper<>() { @Override - public GameModeConfig map(Chatter sender, PreviousArguments previousArguments, String s) { - GameModeConfig arenaMode = ArenaMode.getByChat(s); + public GameModeConfig map(Chatter sender, PreviousArguments previousArguments, String s) { + GameModeConfig arenaMode = ArenaMode.getByChat(s); if (arenaMode == null) return null; if (arenaMode.Server.Historic != historic) return null; if (!arenaMode.isActive()) return null; @@ -76,7 +76,7 @@ public class TypeMappers { @Override public Collection tabCompletes(Chatter sender, PreviousArguments previousArguments, String s) { if (previousArguments.userArgs.length == 0) return null; - GameModeConfig arenaMode = ArenaMode.getByChat(previousArguments.userArgs[previousArguments.userArgs.length - 1]); + GameModeConfig arenaMode = ArenaMode.getByChat(previousArguments.userArgs[previousArguments.userArgs.length - 1]); if (arenaMode == null) return null; return arenaMode.Server.Maps; } diff --git a/VelocityCore/src/de/steamwar/velocitycore/listeners/ChatListener.java b/VelocityCore/src/de/steamwar/velocitycore/listeners/ChatListener.java index 5b3ccff9..6b0c7059 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/listeners/ChatListener.java +++ b/VelocityCore/src/de/steamwar/velocitycore/listeners/ChatListener.java @@ -29,7 +29,7 @@ import com.velocitypowered.api.proxy.ConsoleCommandSource; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.ServerConnection; import com.velocitypowered.api.proxy.server.ServerInfo; -import de.steamwar.data.GameModeConfig; +import de.steamwar.sql.GameModeConfig; import de.steamwar.linkage.Linked; import de.steamwar.messages.Chatter; import de.steamwar.messages.ChatterGroup; diff --git a/VelocityCore/src/de/steamwar/velocitycore/network/handlers/EloPlayerHandler.java b/VelocityCore/src/de/steamwar/velocitycore/network/handlers/EloPlayerHandler.java index 69b13b22..df2bcca8 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/network/handlers/EloPlayerHandler.java +++ b/VelocityCore/src/de/steamwar/velocitycore/network/handlers/EloPlayerHandler.java @@ -20,7 +20,7 @@ package de.steamwar.velocitycore.network.handlers; import com.velocitypowered.api.proxy.Player; -import de.steamwar.data.GameModeConfig; +import de.steamwar.sql.GameModeConfig; import de.steamwar.linkage.Linked; import de.steamwar.messages.Chatter; import de.steamwar.network.packets.PacketHandler; @@ -56,7 +56,7 @@ public class EloPlayerHandler extends PacketHandler { @Handler public void handle(FightEndsPacket fightEndsPacket) { SchematicType schematicType = SchematicType.fromDB(fightEndsPacket.getGameMode()); - GameModeConfig arenaMode; + GameModeConfig arenaMode; if (schematicType == null) { arenaMode = ArenaMode.getByInternal(fightEndsPacket.getGameMode()); } else { diff --git a/VelocityCore/src/de/steamwar/velocitycore/network/handlers/EloSchemHandler.java b/VelocityCore/src/de/steamwar/velocitycore/network/handlers/EloSchemHandler.java index 036a6b2d..cd291de7 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/network/handlers/EloSchemHandler.java +++ b/VelocityCore/src/de/steamwar/velocitycore/network/handlers/EloSchemHandler.java @@ -19,7 +19,7 @@ package de.steamwar.velocitycore.network.handlers; -import de.steamwar.data.GameModeConfig; +import de.steamwar.sql.GameModeConfig; import de.steamwar.linkage.Linked; import de.steamwar.network.packets.PacketHandler; import de.steamwar.network.packets.common.FightEndsPacket; @@ -46,7 +46,7 @@ public class EloSchemHandler extends PacketHandler { public void handle(FightEndsPacket fightEndsPacket) { SchematicType type = SchematicType.fromDB(fightEndsPacket.getGameMode()); if (type == null) return; - GameModeConfig arenaMode = ArenaMode.getBySchemType(type); + GameModeConfig arenaMode = ArenaMode.getBySchemType(type); if (!arenaMode.Server.Ranked) return; if (publicVsPrivate(fightEndsPacket)) diff --git a/VelocityCore/src/de/steamwar/velocitycore/network/handlers/PrepareSchemHandler.java b/VelocityCore/src/de/steamwar/velocitycore/network/handlers/PrepareSchemHandler.java index da91ea50..e4c3c348 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/network/handlers/PrepareSchemHandler.java +++ b/VelocityCore/src/de/steamwar/velocitycore/network/handlers/PrepareSchemHandler.java @@ -20,7 +20,7 @@ package de.steamwar.velocitycore.network.handlers; import com.velocitypowered.api.proxy.Player; -import de.steamwar.data.GameModeConfig; +import de.steamwar.sql.GameModeConfig; import de.steamwar.linkage.Linked; import de.steamwar.network.packets.PacketHandler; import de.steamwar.network.packets.client.PrepareSchemPacket; @@ -37,7 +37,7 @@ public class PrepareSchemHandler extends PacketHandler { public void handle(PrepareSchemPacket packet) { Player player = VelocityCore.getProxy().getPlayer(SteamwarUser.get(packet.getPlayer()).getUUID()).orElse(null); int schematicID = packet.getSchem(); - GameModeConfig mode = ArenaMode.getBySchemType(SchematicType.fromDB(packet.getSchemType())); + GameModeConfig mode = ArenaMode.getBySchemType(SchematicType.fromDB(packet.getSchemType())); new ServerStarter().test(mode, mode.getRandomMap(), player).prepare(schematicID).start(); } From dfbeab7b90b53de061e983bff8bec4587627fc97 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 26 Oct 2025 12:55:17 +0100 Subject: [PATCH 11/16] Add JavaDoc to GameModeConfig --- .../src/de/steamwar/sql/GameModeConfig.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/CommonCore/SQL/src/de/steamwar/sql/GameModeConfig.java b/CommonCore/SQL/src/de/steamwar/sql/GameModeConfig.java index 942df6d1..071db180 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/GameModeConfig.java +++ b/CommonCore/SQL/src/de/steamwar/sql/GameModeConfig.java @@ -43,6 +43,9 @@ public final class GameModeConfig { public final boolean loaded; public final File configFile; + /** + * Bundle for server specific configuration values + */ public final ServerConfig Server; /** @@ -58,8 +61,20 @@ public final class GameModeConfig { * @implSpec Disables check schem type if missing */ public final List CheckQuestions; + + /** + * Bundle for countdowns during the fight + */ public final TimesConfig Times; + + /** + * Bundle for arena specific configurations. Primarily used by the FightSystem + */ public final ArenaConfig Arena; + + /** + * Bundle for schematic configurations + */ public final SchematicConfig Schematic; /** @@ -83,20 +98,40 @@ public final class GameModeConfig { * @implSpec {@code +} by default */ public final String TeamChatPrefix; + + /** + * Bundle for configurations for the Blue team + */ public final BlueConfig Blue; + + /** + * Bundle for configurations for the Red team + */ public final RedConfig Red; /** * The list of active win conditions */ public final List WinConditions; + + /** + * Bundle for configurations used by the Winconditions in the FightSystem + */ public final WinConditionParamsConfig WinConditionParams; + + /** + * Bundle for Kit specific configurations + */ public final KitsConfig Kits; /** * A list of integers containing the waiting time of this enter stage in the fight */ public final List EnterStages; + + /** + * Bundle for Techhider configurations + */ public final TechhiderConfig Techhider; private static final Field Schematic_TypeField; From 79ebdcea851f56a10124f512b187920af6a7e161 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 26 Oct 2025 13:14:11 +0100 Subject: [PATCH 12/16] Make SchematicType static init type safe --- CommonCore/SQL/src/de/steamwar/sql/SQLWrapper.java | 8 +++++--- CommonCore/SQL/src/de/steamwar/sql/SchematicType.java | 2 +- .../src/de/steamwar/sql/SQLWrapperImpl.java | 9 ++++++++- VelocityCore/src/de/steamwar/sql/SQLWrapperImpl.java | 9 +++++++-- WebsiteBackend/src/de/steamwar/sql/SQLWrapperImpl.kt | 8 ++++++-- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/SQLWrapper.java b/CommonCore/SQL/src/de/steamwar/sql/SQLWrapper.java index 0dbdde69..4fbe2541 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/SQLWrapper.java +++ b/CommonCore/SQL/src/de/steamwar/sql/SQLWrapper.java @@ -23,12 +23,14 @@ import de.steamwar.ImplementationProvider; import java.io.File; -public interface SQLWrapper { - SQLWrapper impl = ImplementationProvider.getImpl("de.steamwar.sql.SQLWrapperImpl"); +public interface SQLWrapper { + SQLWrapper impl = ImplementationProvider.getImpl("de.steamwar.sql.SQLWrapperImpl"); File getSchemTypesFolder(); - default void processSchematicType(GameModeConfig gameModeConfig) { + GameModeConfig loadGameModeConfig(File file); + + default void processSchematicType(GameModeConfig gameModeConfig) { } 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 04af18ef..c0d61bb2 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/SchematicType.java +++ b/CommonCore/SQL/src/de/steamwar/sql/SchematicType.java @@ -46,7 +46,7 @@ public class SchematicType { 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.ToStaticWarGear); + GameModeConfig gameModeConfig = SQLWrapper.impl.loadGameModeConfig(configFile); if (gameModeConfig.Schematic.Type == null) continue; if (tmpFromDB.containsKey(gameModeConfig.Schematic.Type.toDB())) continue; SchematicType current = gameModeConfig.Schematic.Type; diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SQLWrapperImpl.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SQLWrapperImpl.java index daf33a15..1aa3f7f5 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SQLWrapperImpl.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SQLWrapperImpl.java @@ -20,19 +20,26 @@ package de.steamwar.sql; import de.steamwar.core.Core; +import de.steamwar.data.GameModeConfigUtils; import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.World; import org.bukkit.entity.Player; import java.io.File; -public class SQLWrapperImpl implements SQLWrapper { +public class SQLWrapperImpl implements SQLWrapper { @Override public File getSchemTypesFolder() { return new File(Core.getInstance().getDataFolder().getParentFile(), "FightSystem"); } + @Override + public GameModeConfig loadGameModeConfig(File file) { + return new GameModeConfig<>(file, GameModeConfigUtils.ToMaterial, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear); + } + private static final String SERVER_VERSION = Bukkit.getServer().getVersion(); @Override diff --git a/VelocityCore/src/de/steamwar/sql/SQLWrapperImpl.java b/VelocityCore/src/de/steamwar/sql/SQLWrapperImpl.java index 1868fd9f..3ad15026 100644 --- a/VelocityCore/src/de/steamwar/sql/SQLWrapperImpl.java +++ b/VelocityCore/src/de/steamwar/sql/SQLWrapperImpl.java @@ -26,7 +26,7 @@ import de.steamwar.velocitycore.commands.CheckCommand; import java.io.File; -public class SQLWrapperImpl implements SQLWrapper { +public class SQLWrapperImpl implements SQLWrapper { @Override public File getSchemTypesFolder() { @@ -34,7 +34,12 @@ public class SQLWrapperImpl implements SQLWrapper { } @Override - public void processSchematicType(GameModeConfig gameModeConfig) { + public GameModeConfig loadGameModeConfig(File file) { + return new GameModeConfig<>(file, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToInternalName); + } + + @Override + public void processSchematicType(GameModeConfig gameModeConfig) { SchematicType type = gameModeConfig.Schematic.Type; if (type.checkType() != null) { CheckCommand.setCheckQuestions(type.checkType(), gameModeConfig.CheckQuestions); diff --git a/WebsiteBackend/src/de/steamwar/sql/SQLWrapperImpl.kt b/WebsiteBackend/src/de/steamwar/sql/SQLWrapperImpl.kt index be7ef20b..be41c8ab 100644 --- a/WebsiteBackend/src/de/steamwar/sql/SQLWrapperImpl.kt +++ b/WebsiteBackend/src/de/steamwar/sql/SQLWrapperImpl.kt @@ -21,11 +21,15 @@ package de.steamwar.sql import java.io.File -class SQLWrapperImpl: SQLWrapper { - override fun getSchemTypesFolder(): File? { +class SQLWrapperImpl: SQLWrapper { + override fun getSchemTypesFolder(): File { return File("/configs/GameModes") } + override fun loadGameModeConfig(file: File): GameModeConfig { + return GameModeConfig(file, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear) + } + override fun additionalExceptionMetadata(builder: StringBuilder) { builder.append("\n\nWebsiteApi") } From 5ab04d051873747d3f8a1b4a7e9834e519567caf Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 26 Oct 2025 13:34:25 +0100 Subject: [PATCH 13/16] Add cache for GameModeConfig --- .../region/fixed/FixedGlobalRegion.java | 7 +-- .../bausystem/region/fixed/FixedRegion.java | 9 ++-- .../src/de/steamwar/sql/GameModeConfig.java | 46 ++++++++++++++++++- .../src/de/steamwar/fightsystem/Config.java | 2 +- .../schematicsystem/SchematicSystem.java | 26 ++--------- .../src/de/steamwar/sql/SQLWrapperImpl.java | 2 +- .../src/de/steamwar/sql/SQLWrapperImpl.java | 2 +- .../de/steamwar/velocitycore/ArenaMode.java | 2 +- .../src/de/steamwar/sql/SQLWrapperImpl.kt | 2 +- 9 files changed, 61 insertions(+), 37 deletions(-) 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 cac519e0..b5da64f5 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 @@ -22,7 +22,6 @@ package de.steamwar.bausystem.region.fixed; import com.sk89q.worldedit.extent.clipboard.Clipboard; import de.steamwar.bausystem.region.*; import de.steamwar.bausystem.utils.PasteBuilder; -import de.steamwar.data.GameModeConfigUtils; import de.steamwar.sql.GameModeConfig; import lombok.NonNull; import lombok.Setter; @@ -93,8 +92,6 @@ public final class FixedGlobalRegion implements Region { } }; - private static final GameModeConfig GLOBAL_CONFIG = new GameModeConfig<>(null, GameModeConfigUtils.ToMaterial, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear); - private FixedGlobalRegion() { } @@ -129,8 +126,8 @@ public final class FixedGlobalRegion implements Region { } @Override - public @NonNull GameModeConfig getGameModeConfig() { - return GLOBAL_CONFIG; + public @NonNull GameModeConfig getGameModeConfig() { + return GameModeConfig.getDefaults(); } @Override 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 ce48b5b6..0d8c03f5 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 @@ -28,7 +28,6 @@ import de.steamwar.bausystem.utils.FlatteningWrapper; import de.steamwar.bausystem.utils.PasteBuilder; import de.steamwar.bausystem.worlddata.WorldData; import de.steamwar.core.Core; -import de.steamwar.data.GameModeConfigUtils; import de.steamwar.sql.GameModeConfig; import de.steamwar.sql.SchematicType; import lombok.NonNull; @@ -339,7 +338,11 @@ public class FixedRegion implements Region { break; } } - this.gameModeConfig = new GameModeConfig<>(found, GameModeConfigUtils.ToMaterial, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear); + if (found == null) { + this.gameModeConfig = GameModeConfig.getDefaults(); + } else { + this.gameModeConfig = GameModeConfig.getByFileName(found); + } this.regionData = new RegionData.RegionDataImpl(regionData, WorldData::write); } @@ -374,7 +377,7 @@ public class FixedRegion implements Region { } @Override - public @NonNull GameModeConfig getGameModeConfig() { + public @NonNull GameModeConfig getGameModeConfig() { return gameModeConfig; } diff --git a/CommonCore/SQL/src/de/steamwar/sql/GameModeConfig.java b/CommonCore/SQL/src/de/steamwar/sql/GameModeConfig.java index 071db180..2bef6599 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/GameModeConfig.java +++ b/CommonCore/SQL/src/de/steamwar/sql/GameModeConfig.java @@ -34,6 +34,28 @@ import java.util.stream.Collectors; @ToString public final class GameModeConfig { + private static final Map> byFileName = new HashMap<>(); + private static final Map> byGameName = new HashMap<>(); + private static final Map> bySchematicType = new HashMap<>(); + + public static GameModeConfig getByFileName(File file) { + return (GameModeConfig) byFileName.get(file.getName()); + } + + public static GameModeConfig getByGameName(String gameName) { + return (GameModeConfig) byGameName.get(gameName); + } + + public static GameModeConfig getBySchematicType(SchematicType schematicType) { + return (GameModeConfig) bySchematicType.get(schematicType); + } + + private static final GameModeConfig DEFAULTS = SQLWrapper.impl.loadGameModeConfig(null); + + public static GameModeConfig getDefaults() { + return (GameModeConfig) DEFAULTS; + } + public static final Function ToString = Function.identity(); public static final Function ToStaticWarGear = __ -> "WarGear"; public static final Function ToInternalName = file -> file.getName().replace(".yml", ""); @@ -145,7 +167,7 @@ public final class GameModeConfig { } } - public GameModeConfig(File file, Function materialMapper, Function winconditionMapper, Function defaultGameName) { + public GameModeConfig(File file, Function materialMapper, Function winconditionMapper, Function defaultGameName, boolean cacheInstance) { YMLWrapper loader = new YMLWrapper<>(file, materialMapper, winconditionMapper); configFile = file; @@ -182,7 +204,20 @@ public final class GameModeConfig { Arena = new ArenaConfig(loader.with("Arena"), Schematic.Size, EnterStages); - if (Schematic.Type != null) return; + if (cacheInstance) { + byFileName.put(configFile.getName(), (GameModeConfig) this); + byGameName.put(GameName, (GameModeConfig) this); + } + + if (Schematic.Type != null) { + if (cacheInstance) { + bySchematicType.put(Schematic.Type, (GameModeConfig) this); + if (Schematic.Type.checkType() != null) { + bySchematicType.put(Schematic.Type.checkType(), (GameModeConfig) this); + } + } + return; + } if (!Schematic.loaded) return; String Schematic_Type = loader.with("Schematic").getString("Type", "Normal"); if (Schematic_Type.equals("Normal")) return; @@ -197,6 +232,13 @@ public final class GameModeConfig { SchematicType current = new SchematicType(Schematic_Type, Schematic_Shortcut, Server.loaded ? SchematicType.Type.FIGHT_TYPE : SchematicType.Type.NORMAL, checktype, material, Deadline, Schematic.ManualCheck); try { Schematic_TypeField.set(Schematic, current); + + if (cacheInstance) { + bySchematicType.put(Schematic.Type, (GameModeConfig) this); + if (Schematic.Type.checkType() != null) { + bySchematicType.put(Schematic.Type.checkType(), (GameModeConfig) this); + } + } } catch (IllegalAccessException e) { throw new SecurityException(e.getMessage(), e); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java index 3b8d2378..a5c89bca 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java @@ -109,7 +109,7 @@ public class Config { Bukkit.getLogger().log(Level.SEVERE, "Arenaconfig fehlt!"); Bukkit.shutdown(); } - GameModeConfig = new GameModeConfig<>(new File(FightSystem.getPlugin().getDataFolder(), configFile), GameModeConfigUtils.ToMaterial, Winconditions::valueOf, de.steamwar.sql.GameModeConfig.ToStaticWarGear); + GameModeConfig = new GameModeConfig<>(new File(FightSystem.getPlugin().getDataFolder(), configFile), GameModeConfigUtils.ToMaterial, Winconditions::valueOf, de.steamwar.sql.GameModeConfig.ToStaticWarGear, false); File worldConfigFile = new File(world.getWorldFolder(), "config.yml"); if(!worldConfigFile.exists()) { diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/SchematicSystem.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/SchematicSystem.java index b75ddbdf..3687a52b 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/SchematicSystem.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/SchematicSystem.java @@ -19,48 +19,30 @@ package de.steamwar.schematicsystem; -import de.steamwar.sql.GameModeConfig; -import de.steamwar.data.GameModeConfigUtils; import de.steamwar.linkage.AbstractLinker; import de.steamwar.linkage.SpigotLinker; import de.steamwar.message.Message; +import de.steamwar.sql.GameModeConfig; import de.steamwar.sql.SchematicType; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.plugin.java.JavaPlugin; -import java.io.File; -import java.util.HashMap; -import java.util.Map; - public class SchematicSystem extends JavaPlugin { public static final Message MESSAGE = new Message("SchematicSystem", SchematicSystem.class.getClassLoader()); private static SchematicSystem instance; - private static final Map> types = new HashMap<>(); - public static GameModeConfig getGameModeConfig(SchematicType type){ - return types.get(type); + GameModeConfig gameModeConfig = GameModeConfig.getBySchematicType(type); + if (gameModeConfig.CheckQuestions.isEmpty() && gameModeConfig.Schematic.ManualCheck) return null; + return gameModeConfig; } @Override public void onEnable() { instance = this; - File folder = new File(this.getDataFolder().getParentFile(), "FightSystem"); - if(folder.exists()) { - for(File configFile : folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))) { - GameModeConfig gameModeConfig = new GameModeConfig<>(configFile, GameModeConfigUtils.ToMaterial, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear); - if (gameModeConfig.CheckQuestions.isEmpty() && gameModeConfig.Schematic.ManualCheck) - continue; - types.put(gameModeConfig.Schematic.Type, gameModeConfig); - if (gameModeConfig.Schematic.Type.checkType() != null) { - types.put(gameModeConfig.Schematic.Type.checkType(), gameModeConfig); - } - } - } - SpigotLinker spigotLinker = new SpigotLinker(this, MESSAGE); try { spigotLinker.link(); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SQLWrapperImpl.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SQLWrapperImpl.java index 1aa3f7f5..39e2cef6 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SQLWrapperImpl.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SQLWrapperImpl.java @@ -37,7 +37,7 @@ public class SQLWrapperImpl implements SQLWrapper { @Override public GameModeConfig loadGameModeConfig(File file) { - return new GameModeConfig<>(file, GameModeConfigUtils.ToMaterial, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear); + return new GameModeConfig<>(file, GameModeConfigUtils.ToMaterial, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear, true); } 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 3ad15026..8e469d20 100644 --- a/VelocityCore/src/de/steamwar/sql/SQLWrapperImpl.java +++ b/VelocityCore/src/de/steamwar/sql/SQLWrapperImpl.java @@ -35,7 +35,7 @@ public class SQLWrapperImpl implements SQLWrapper { @Override public GameModeConfig loadGameModeConfig(File file) { - return new GameModeConfig<>(file, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToInternalName); + return new GameModeConfig<>(file, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToInternalName, true); } @Override diff --git a/VelocityCore/src/de/steamwar/velocitycore/ArenaMode.java b/VelocityCore/src/de/steamwar/velocitycore/ArenaMode.java index 9707bdd9..87e2bf92 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/ArenaMode.java +++ b/VelocityCore/src/de/steamwar/velocitycore/ArenaMode.java @@ -51,7 +51,7 @@ public class ArenaMode { return; 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.ToInternalName); + GameModeConfig gameModeConfig = new GameModeConfig<>(file, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToInternalName, false); 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 be41c8ab..0e843c25 100644 --- a/WebsiteBackend/src/de/steamwar/sql/SQLWrapperImpl.kt +++ b/WebsiteBackend/src/de/steamwar/sql/SQLWrapperImpl.kt @@ -27,7 +27,7 @@ class SQLWrapperImpl: SQLWrapper { } override fun loadGameModeConfig(file: File): GameModeConfig { - return GameModeConfig(file, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear) + return GameModeConfig(file, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear, true) } override fun additionalExceptionMetadata(builder: StringBuilder) { From dd711be30b87897e57d35227a383f2ed0f3ab624 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 26 Oct 2025 13:40:17 +0100 Subject: [PATCH 14/16] Add cache for GameModeConfig --- .../src/de/steamwar/sql/GameModeConfig.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/GameModeConfig.java b/CommonCore/SQL/src/de/steamwar/sql/GameModeConfig.java index 2bef6599..305edbaa 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/GameModeConfig.java +++ b/CommonCore/SQL/src/de/steamwar/sql/GameModeConfig.java @@ -34,6 +34,16 @@ import java.util.stream.Collectors; @ToString public final class GameModeConfig { + public static final Function ToString = Function.identity(); + public static final Function ToStaticWarGear = __ -> "WarGear"; + public static final Function ToInternalName = file -> file.getName().replace(".yml", ""); + public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yyyy HH:mm"); + private static final Random random = new Random(); + + static { + SchematicType.values(); + } + private static final Map> byFileName = new HashMap<>(); private static final Map> byGameName = new HashMap<>(); private static final Map> bySchematicType = new HashMap<>(); @@ -56,12 +66,6 @@ public final class GameModeConfig { return (GameModeConfig) DEFAULTS; } - public static final Function ToString = Function.identity(); - public static final Function ToStaticWarGear = __ -> "WarGear"; - public static final Function ToInternalName = file -> file.getName().replace(".yml", ""); - public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yyyy HH:mm"); - private static final Random random = new Random(); - public final boolean loaded; public final File configFile; @@ -205,7 +209,9 @@ public final class GameModeConfig { Arena = new ArenaConfig(loader.with("Arena"), Schematic.Size, EnterStages); if (cacheInstance) { - byFileName.put(configFile.getName(), (GameModeConfig) this); + if (configFile != null) { + byFileName.put(configFile.getName(), (GameModeConfig) this); + } byGameName.put(GameName, (GameModeConfig) this); } From 11eb506f05c63b827492ec6b5b4bcd9364b6e4eb Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 26 Oct 2025 17:35:19 +0100 Subject: [PATCH 15/16] Use log of SchematicType --- CommonCore/SQL/src/de/steamwar/sql/SchematicType.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/SchematicType.java b/CommonCore/SQL/src/de/steamwar/sql/SchematicType.java index c0d61bb2..138b5eb7 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/SchematicType.java +++ b/CommonCore/SQL/src/de/steamwar/sql/SchematicType.java @@ -19,15 +19,15 @@ package de.steamwar.sql; +import de.steamwar.sql.internal.SQLConfig; import de.steamwar.sql.internal.SqlTypeMapper; import lombok.Getter; -import lombok.extern.slf4j.Slf4j; import java.io.File; import java.util.*; +import java.util.logging.Level; import java.util.stream.Collectors; -@Slf4j public class SchematicType { public static final SchematicType Normal = new SchematicType("Normal", "", Type.NORMAL, null, "STONE_BUTTON", false); @@ -61,7 +61,7 @@ public class SchematicType { } } time = System.currentTimeMillis() - time; - log.info("Loaded {} Schematic Types in {}ms", tmpTypes.size(), time); + SQLConfig.impl.getLogger().log(Level.INFO, "Loaded {} Schematic Types in {}ms", new Object[]{tmpTypes.size(), time}); fromDB = Collections.unmodifiableMap(tmpFromDB); types = Collections.unmodifiableList(tmpTypes); From 63069b7caa58524f0f1135e91d8b47a976f701d6 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 26 Oct 2025 17:36:48 +0100 Subject: [PATCH 16/16] Remove log in SchematicType --- CommonCore/SQL/src/de/steamwar/sql/SchematicType.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/SchematicType.java b/CommonCore/SQL/src/de/steamwar/sql/SchematicType.java index 138b5eb7..6abaffca 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/SchematicType.java +++ b/CommonCore/SQL/src/de/steamwar/sql/SchematicType.java @@ -19,13 +19,11 @@ package de.steamwar.sql; -import de.steamwar.sql.internal.SQLConfig; import de.steamwar.sql.internal.SqlTypeMapper; import lombok.Getter; import java.io.File; import java.util.*; -import java.util.logging.Level; import java.util.stream.Collectors; public class SchematicType { @@ -42,7 +40,6 @@ public class SchematicType { tmpTypes.add(Normal); tmpFromDB.put(Normal.name().toLowerCase(), Normal); - long time = System.currentTimeMillis(); 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())) { @@ -60,8 +57,6 @@ public class SchematicType { SQLWrapper.impl.processSchematicType(gameModeConfig); } } - time = System.currentTimeMillis() - time; - SQLConfig.impl.getLogger().log(Level.INFO, "Loaded {} Schematic Types in {}ms", new Object[]{tmpTypes.size(), time}); fromDB = Collections.unmodifiableMap(tmpFromDB); types = Collections.unmodifiableList(tmpTypes);