From ed51106d4a98bb8de1a828db02da6d0ed4e78486 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Fri, 6 Mar 2026 15:34:53 +0100 Subject: [PATCH] Fix WetRegion -> WetRegionData Fix DynamicRegionSystem.get Add Fallback.schem for PathArea --- .../region/DynamicRegionCommand.java | 32 +++++++++++-- .../bausystem/region/DynamicRegionSystem.java | 4 +- .../dynamic/DynamicRegionRepository.java | 30 +++++++------ .../region/dynamic/path/PathArea.java | 21 +++++---- .../region/dynamic/special/wet/WetRegion.java | 3 +- .../dynamic/special/wet/WetRegionData.java | 45 +++++++++++++++++++ 6 files changed, 107 insertions(+), 28 deletions(-) create mode 100644 BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/special/wet/WetRegionData.java diff --git a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/DynamicRegionCommand.java b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/DynamicRegionCommand.java index d0c5547b..94a231e5 100644 --- a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/DynamicRegionCommand.java +++ b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/DynamicRegionCommand.java @@ -21,13 +21,17 @@ package de.steamwar.bausystem.region; import de.steamwar.bausystem.features.region.RegionCommand; import de.steamwar.bausystem.region.dynamic.DynamicRegion; +import de.steamwar.bausystem.region.dynamic.DynamicRegionRepository; import de.steamwar.bausystem.region.dynamic.Tile; -import de.steamwar.bausystem.region.dynamic.path.PathRegion; import de.steamwar.bausystem.utils.PasteBuilder; import de.steamwar.command.AbstractSWCommand; +import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; +import de.steamwar.command.TypeMapper; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import java.util.Collection; import java.util.UUID; @AbstractSWCommand.PartOf(RegionCommand.class) @@ -38,16 +42,17 @@ public class DynamicRegionCommand extends SWCommand { } @Register({"dynamic", "place"}) - public void placeRegion(Player player) { + public void placeRegion(Player player, @Mapper("regionType") String regionType) { Region region = DynamicRegionSystem.INSTANCE.get(player.getLocation()); if (!region.getType().isGlobal()) return; Tile tile = Tile.fromLocation(player.getLocation()).orElse(null); if (tile == null) return; - // TODO: Replace! - PathRegion dynamicRegion = new PathRegion(UUID.randomUUID(), tile.getMinX(), tile.getMinZ()); + Class regionClass = DynamicRegionSystem.identifierDataMap.get(regionType); + DynamicRegion dynamicRegion = DynamicRegionRepository.constructRegion(regionClass, UUID.randomUUID(), tile.getMinX(), tile.getMinZ()); dynamicRegion.getArea().reset(new PasteBuilder(new PasteBuilder.FileProvider(dynamicRegion.getArea().getResetFile())), false); + // TODO: This here still has some kind of error!aww DynamicRegionSystem.INSTANCE.getNeighbours(dynamicRegion).forEach(r -> r.update(dynamicRegion)); } @@ -57,4 +62,23 @@ public class DynamicRegionCommand extends SWCommand { if (!region.getType().isDeletable()) return; ((DynamicRegion) region).delete(); } + + @Mapper("regionType") + private TypeMapper regionType() { + return new TypeMapper<>() { + @Override + public String map(CommandSender commandSender, String[] previousArguments, String s) { + if (DynamicRegionSystem.identifierDataMap.containsKey(s)) { + return s; + } else { + return null; + } + } + + @Override + public Collection tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) { + return DynamicRegionSystem.identifierDataMap.keySet(); + } + }; + } } diff --git a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/DynamicRegionSystem.java b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/DynamicRegionSystem.java index efd7490c..6f29503b 100644 --- a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/DynamicRegionSystem.java +++ b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/DynamicRegionSystem.java @@ -118,7 +118,9 @@ public class DynamicRegionSystem implements RegionSystem { .filter(rg -> rg.getArea().inRegion(x, z, false)) .findFirst() .orElseGet(this::getGlobalRegion); - regionCache.put(tile.getId(), region); + if (fastCache || regions.contains(region)) { + regionCache.put(tile.getId(), region); + } return region; } diff --git a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/DynamicRegionRepository.java b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/DynamicRegionRepository.java index 75929c87..5f52a37b 100644 --- a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/DynamicRegionRepository.java +++ b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/DynamicRegionRepository.java @@ -144,21 +144,25 @@ public class DynamicRegionRepository { continue; } Location minTileLocation = tile.getMinLocation(); + constructRegion(regionClass, regionUUID, minTileLocation.getBlockX(), minTileLocation.getBlockZ()); + } + } - Constructor regionConstructor; - try { - regionConstructor = regionClass.getConstructor(UUID.class, int.class, int.class); - } catch (NoSuchMethodException e) { - RegionSystem.LOGGER.log(Level.SEVERE, "Failed to read region metadata file (region constructor not found)"); - continue; - } + public static DynamicRegion constructRegion(Class clazz, UUID uuid, int minX, int minZ) { + Constructor regionConstructor; + try { + regionConstructor = clazz.getConstructor(UUID.class, int.class, int.class); + } catch (NoSuchMethodException e) { + RegionSystem.LOGGER.log(Level.SEVERE, "Failed to read region metadata file (region constructor not found)"); + return null; + } - try { - regionConstructor.newInstance(regionUUID, minTileLocation.getBlockX(), minTileLocation.getBlockZ()); - } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | - InvocationTargetException e) { - RegionSystem.LOGGER.log(Level.SEVERE, "Failed to read region metadata file (invalid data)"); - } + try { + return regionConstructor.newInstance(uuid, minX, minZ); + } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | + InvocationTargetException e) { + RegionSystem.LOGGER.log(Level.SEVERE, "Failed to read region metadata file (invalid data)"); + return null; } } diff --git a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/path/PathArea.java b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/path/PathArea.java index 7347005a..3e4cc9dc 100644 --- a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/path/PathArea.java +++ b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/path/PathArea.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.region.dynamic.path; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.DynamicRegionSystem; import de.steamwar.bausystem.region.Point; import de.steamwar.bausystem.region.Region; @@ -42,6 +43,7 @@ import static de.steamwar.bausystem.region.RegionType.ConnectionType.*; public class PathArea implements Region.Area { private static final File PATH_DIR = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "sections/path"); + private static final File FALLBACK_SCHEM = new File(PATH_DIR, "Fallback.schem"); private static final VariantSelector CENTER_NORMAL = VariantSelector.Get(new File(PATH_DIR, "center/normal")); private static final VariantSelector SIDE_GLOBAL = VariantSelector.Get(new File(PATH_DIR, "side/global")); @@ -151,10 +153,11 @@ public class PathArea implements Region.Area { for (Side side : Side.values()) { VariantSelector selector = SELECTOR_SIDE.Select(tile, side); - if (selector == null) continue; - - resetFile = selector.select(regionIdentifier, side.ordinal() + side.rotate).orElse(null); - if (resetFile == null) continue; + if (selector != null) resetFile = selector.select(regionIdentifier, side.ordinal() + side.rotate).orElse(null); + if (selector == null || resetFile == null) { + if (!BauSystem.DEV_SERVER) continue; + resetFile = FALLBACK_SCHEM; + } PasteUtils.paste(resetFile, minPoint.add(side.pasteOffsetX, 0, side.pasteOffsetZ), side.rotate); } @@ -162,11 +165,13 @@ public class PathArea implements Region.Area { for (Corner corner : Corner.values()) { Pair pair = SELECTOR_CORNER.Select(tile, corner); VariantSelector selector = pair.getKey(); - if (selector == null) continue; RotationCorrection rotationCorrection = pair.getValue(); - - resetFile = selector.select(regionIdentifier, corner.side1.ordinal() * corner.side2.ordinal() + corner.side1.rotate * corner.side2.rotate).orElse(null); - if (resetFile == null) continue; + if (selector != null) resetFile = selector.select(regionIdentifier, corner.side1.ordinal() * corner.side2.ordinal() + corner.side1.rotate * corner.side2.rotate).orElse(null); + if (selector == null || resetFile == null) { + if (!BauSystem.DEV_SERVER) continue; + resetFile = FALLBACK_SCHEM; + rotationCorrection = RotationCorrection.Unchanged; + } int rotate = corner.rotate; switch (rotationCorrection) { diff --git a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/special/wet/WetRegion.java b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/special/wet/WetRegion.java index 93709831..b21049bb 100644 --- a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/special/wet/WetRegion.java +++ b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/special/wet/WetRegion.java @@ -25,7 +25,6 @@ import de.steamwar.bausystem.region.RegionHistory; import de.steamwar.bausystem.region.RegionType; import de.steamwar.bausystem.region.dynamic.*; import de.steamwar.bausystem.region.dynamic.special.SpecialArea; -import de.steamwar.bausystem.region.dynamic.special.SpecialRegionData; import de.steamwar.sql.GameModeConfig; import lombok.NonNull; import org.bukkit.Material; @@ -53,7 +52,7 @@ public class WetRegion extends DynamicRegion { @Override public void init() { area = new SpecialArea(Tile.fromXZ(minX, minZ).orElseThrow(), this, WET); - regionData = new SpecialRegionData(this); + regionData = new WetRegionData(this); } @Override diff --git a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/special/wet/WetRegionData.java b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/special/wet/WetRegionData.java new file mode 100644 index 00000000..d69c922e --- /dev/null +++ b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/special/wet/WetRegionData.java @@ -0,0 +1,45 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2026 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.dynamic.special.wet; + +import de.steamwar.bausystem.region.RegionFlagPolicy; +import de.steamwar.bausystem.region.dynamic.DynamicRegion; +import de.steamwar.bausystem.region.dynamic.special.SpecialRegionData; +import de.steamwar.bausystem.region.flags.Flag; +import de.steamwar.bausystem.region.flags.ProtectMode; +import lombok.NonNull; + +public class WetRegionData extends SpecialRegionData { + + public WetRegionData(DynamicRegion region) { + super(region); + } + + @Override + protected void initialize() { + flagMap.put(Flag.PROTECT, ProtectMode.INACTIVE); + } + + @Override + public @NonNull & Flag.Value> RegionFlagPolicy has(@NonNull Flag flag) { + if (flag.oneOf(Flag.PROTECT)) return RegionFlagPolicy.NOT_APPLICABLE; + return super.has(flag); + } +}