From 27deebd5703c8c22806099133d16a4be8cac720c Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Fri, 6 Mar 2026 21:09:09 +0100 Subject: [PATCH] Cleanup and add comments --- .../bausystem/region/DynamicRegionSystem.java | 6 ++++++ .../bausystem/region/dynamic/DynamicRegion.java | 14 +++++++------- .../region/dynamic/DynamicRegionRepository.java | 8 +++++++- .../bausystem/region/dynamic/path/PathRegion.java | 1 - 4 files changed, 20 insertions(+), 9 deletions(-) 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 3fb684d6..68d1ec6f 100644 --- a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/DynamicRegionSystem.java +++ b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/DynamicRegionSystem.java @@ -26,6 +26,7 @@ import de.steamwar.bausystem.shared.Pair; import lombok.NonNull; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.jetbrains.annotations.NotNull; import javax.annotation.Nullable; import java.io.BufferedReader; @@ -138,6 +139,10 @@ public class DynamicRegionSystem implements RegionSystem { return regionMap.values().stream(); } + public @NonNull Stream getRegionsByType(RegionType type) { + return regionTypeMap.get(type).stream(); + } + private Stream> getNeighbours(Region region, boolean noCorners, boolean fastCache, Collection regions) { Point minPoint = region.getArea().getMinPoint(false).subtract(TILE_SIZE_ADJUSTED, 0, TILE_SIZE_ADJUSTED); Point maxPoint = region.getArea().getMaxPoint(false).add(Tile.tileSize, 0, Tile.tileSize); @@ -175,6 +180,7 @@ public class DynamicRegionSystem implements RegionSystem { } @Override + @NotNull public Stream getConnectedRegions(Region region) { Set regions = regionTypeMap.get(region.getType()); diff --git a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/DynamicRegion.java b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/DynamicRegion.java index 6c367825..a9fdc8f7 100644 --- a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/DynamicRegion.java +++ b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/DynamicRegion.java @@ -52,20 +52,20 @@ public abstract class DynamicRegion implements Region { public abstract void init(); public final void updateNeighbours() { - List> list = DynamicRegionSystem.INSTANCE.getNeighbours(this).toList(); + List> list = DynamicRegionSystem.INSTANCE.getNeighbours(this) + .filter(data -> data.getKey() instanceof PathRegion) + .map(data -> new Pair<>((PathRegion) data.getKey(), data.getValue())) + .toList(); + // Calculate Garden State for all neighbouring PathRegions list.forEach(data -> { - if (data.getKey() instanceof PathRegion pathRegion) { - pathRegion.calculateGardenState(); - } + data.getKey().calculateGardenState(); }); + // Updating world state for all neighbouring PathRegions list.forEach(data -> { data.getKey().update(this, data.getValue().opposite()); }); } - public void update(DynamicRegion updateFrom, NeighbourDirection direction) { - } - public void setRegionData(@NonNull RegionData regionData) { this.regionData = regionData; regionData.setStore(this); 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 5f52a37b..b92584ed 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 @@ -25,6 +25,7 @@ import com.google.gson.JsonParser; import com.google.gson.JsonSyntaxException; import com.google.gson.stream.JsonWriter; import de.steamwar.bausystem.region.*; +import de.steamwar.bausystem.region.dynamic.path.PathRegion; import de.steamwar.bausystem.region.flags.Flag; import lombok.Cleanup; import lombok.SneakyThrows; @@ -136,7 +137,6 @@ public class DynamicRegionRepository { RegionSystem.LOGGER.log(Level.SEVERE, "Failed to read region metadata file (region no longer exists)"); continue; } - RegionConstructorData constructorData = DynamicRegionSystem.constructorDataMap.get(regionClass); Tile tile = Tile.fromTile(tileX, tileZ).orElse(null); if (tile == null) { @@ -146,6 +146,12 @@ public class DynamicRegionRepository { Location minTileLocation = tile.getMinLocation(); constructRegion(regionClass, regionUUID, minTileLocation.getBlockX(), minTileLocation.getBlockZ()); } + + // Calculate Garden State for all PathRegions + DynamicRegionSystem.INSTANCE.getRegionsByType(RegionType.PATH) + .forEach(region -> { + ((PathRegion) region).calculateGardenState(); + }); } public static DynamicRegion constructRegion(Class clazz, UUID uuid, int minX, int minZ) { diff --git a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/path/PathRegion.java b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/path/PathRegion.java index fbe78c7e..0f2096b7 100644 --- a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/path/PathRegion.java +++ b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/path/PathRegion.java @@ -49,7 +49,6 @@ public class PathRegion extends DynamicRegion { regionData = new PathRegionData(this); } - @Override public void update(DynamicRegion updateFrom, NeighbourDirection direction) { for (PathSide side : direction.getSideUpdates()) { area.reset(side);