diff --git a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/DynamicRegionEditor.java b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/DynamicRegionEditor.java index 02a78e7c..cc64cd5c 100644 --- a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/DynamicRegionEditor.java +++ b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/DynamicRegionEditor.java @@ -122,6 +122,8 @@ public class DynamicRegionEditor implements SWPlayer.Component, Listener { entityServer.close(); task.cancel(); PlayerMoveEvent.getHandlerList().unregister(this); + PlayerSwapHandItemsEvent.getHandlerList().unregister(this); + PlayerInteractEvent.getHandlerList().unregister(this); } @EventHandler 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 a17af251..70ced2b4 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 @@ -23,6 +23,7 @@ import com.google.gson.*; import com.google.gson.stream.JsonWriter; import de.steamwar.bausystem.region.*; import de.steamwar.bausystem.region.dynamic.path.PathRegion; +import de.steamwar.bausystem.region.dynamic.path.PathRegionData; import de.steamwar.bausystem.region.flags.Flag; import lombok.Cleanup; import lombok.SneakyThrows; @@ -94,7 +95,7 @@ public class DynamicRegionRepository { RegionSystem.LOGGER.log(Level.WARNING, "Failed to resolve region id: " + region.getName()); continue; } - if (regionUUID.equals(RegionSystem.GLOBAL_REGION_ID)) { + if (regionUUID.equals(RegionSystem.GLOBAL_REGION_ID) || regionUUID.equals(PathRegionData.PATH_REGION_ID)) { continue; } @@ -179,13 +180,18 @@ public class DynamicRegionRepository { return regionConstructor.newInstance(uuid, tileData); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + e.printStackTrace(); RegionSystem.LOGGER.log(Level.SEVERE, "Failed to read region metadata file (invalid data)"); return null; } } + private static File getRegionDirectory(UUID uuid) { + return new File(REGION_DATA_FOLDER, uuid.toString()); + } + public static File getRegionDirectory(Region region) { - return new File(REGION_DATA_FOLDER, region.getID().toString()); + return getRegionDirectory(region.getID()); } public static File getBackupsTypeDirectory(Region region, RegionBackups.BackupType backupType) { @@ -198,7 +204,17 @@ public class DynamicRegionRepository { return new File(getBackupsTypeDirectory(region, backup.getType()), backup.getName()); } + public static void loadRegionData(UUID uuid, RegionData regionData) { + File regionDirectory = getRegionDirectory(uuid); + if (!regionDirectory.exists()) return; + loadRegionData(regionDirectory, regionData); + } + public static void loadRegionData(Region region, RegionData regionData) { + if (region.getRegionData() instanceof PathRegionData) { + return; + } + File regionDirectory = getRegionDirectory(region); if (!regionDirectory.exists()) return; loadRegionData(regionDirectory, regionData); @@ -252,16 +268,17 @@ public class DynamicRegionRepository { throw new IllegalArgumentException(); } - File regionDirectory = new File(REGION_DATA_FOLDER, region.getID().toString()); - if (!regionDirectory.exists()) { - regionDirectory.mkdir(); - } + File regionDirectory = getRegionDirectory(region); + if (!regionDirectory.exists()) regionDirectory.mkdir(); if (region instanceof DynamicRegion dynamicRegion) { RegionConstructorData constructorData = DynamicRegionSystem.constructorDataMap.get(region.getClass()); writeMetaFile(regionDirectory, constructorData, dynamicRegion); } + if (region.getRegionData() instanceof PathRegionData) { + return; + } writeFlagsFile(regionDirectory, region.getRegionData()); } @@ -273,6 +290,11 @@ public class DynamicRegionRepository { writeFlagsFile(backupDirectory, backup.getRegionData()); } + public static void saveData(UUID uuid, RegionData regionData) { + File regionDirectory = getRegionDirectory(uuid); + writeFlagsFile(regionDirectory, regionData); + } + @SneakyThrows private static void writeMetaFile(File regionDirectory, RegionConstructorData constructorData, DynamicRegion dynamicRegion) { @Cleanup 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 b2e46ae4..741f7706 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 @@ -63,7 +63,7 @@ public class PathRegion extends DynamicRegion { super(id, null); this.tile = tile; area = new PathArea(tile, this); - regionData = new PathRegionData(this); + regionData = PathRegionData.INSTANCE; calculateGardenState(); } diff --git a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/path/PathRegionData.java b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/path/PathRegionData.java index 1f04d83c..c6d2ec20 100644 --- a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/path/PathRegionData.java +++ b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/path/PathRegionData.java @@ -20,7 +20,9 @@ package de.steamwar.bausystem.region.dynamic.path; import de.steamwar.bausystem.region.RegionData; +import de.steamwar.bausystem.region.RegionDataStore; import de.steamwar.bausystem.region.RegionFlagPolicy; +import de.steamwar.bausystem.region.dynamic.DynamicRegionRepository; import de.steamwar.bausystem.region.flags.FireMode; import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.ProtectMode; @@ -28,10 +30,26 @@ import de.steamwar.bausystem.region.flags.TNTMode; import de.steamwar.core.Core; import lombok.NonNull; +import java.util.UUID; + public class PathRegionData extends RegionData { - public PathRegionData(PathRegion pathRegion) { - super(pathRegion); + public static final UUID PATH_REGION_ID = new UUID(Long.MAX_VALUE, Long.MAX_VALUE); + + public static final PathRegionData INSTANCE = new PathRegionData(); + + private PathRegionData() { + super(new RegionDataStore() { + @Override + public void save() { + DynamicRegionRepository.saveData(PATH_REGION_ID, INSTANCE); + } + + @Override + public void load(RegionData regionData) { + DynamicRegionRepository.loadRegionData(PATH_REGION_ID, regionData); + } + }); } @Override diff --git a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/spawn/SpawnArea.java b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/spawn/SpawnArea.java new file mode 100644 index 00000000..c571667d --- /dev/null +++ b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/spawn/SpawnArea.java @@ -0,0 +1,54 @@ +/* + * 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.spawn; + +import de.steamwar.bausystem.region.Point; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.utils.PasteBuilder; +import lombok.NonNull; + +public class SpawnArea implements Region.Area { + + @Override + public @NonNull Point getMinPoint(boolean extension) { + return null; + } + + @Override + public @NonNull Point getMaxPoint(boolean extension) { + return null; + } + + @Override + public @NonNull Point getCopyPoint() { + return null; + } + + @Override + public void reset(PasteBuilder pasteBuilder, boolean extension) { + // TODO: Implement! + Region.Area.super.reset(pasteBuilder, extension); + } + + @Override + public void place(PasteBuilder pasteBuilder, boolean extension) { + + } +} diff --git a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/spawn/SpawnRegion.java b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/spawn/SpawnRegion.java new file mode 100644 index 00000000..226e28d0 --- /dev/null +++ b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/spawn/SpawnRegion.java @@ -0,0 +1,96 @@ +/* + * 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.spawn; + +import com.google.gson.JsonArray; +import com.google.gson.stream.JsonWriter; +import de.steamwar.bausystem.region.RegionBackups; +import de.steamwar.bausystem.region.RegionHistory; +import de.steamwar.bausystem.region.RegionType; +import de.steamwar.bausystem.region.dynamic.DynamicRegion; +import de.steamwar.bausystem.region.dynamic.Tile; +import de.steamwar.bausystem.region.dynamic.TileUtils; +import de.steamwar.sql.GameModeConfig; +import lombok.NonNull; +import org.bukkit.Material; + +import java.io.IOException; +import java.util.UUID; + +public class SpawnRegion extends DynamicRegion { + + private final Tile tile; + + public SpawnRegion(Tile tile) { + this(UUID.randomUUID(), tile); + finishCreate(); + } + + public SpawnRegion(UUID id, JsonArray tileData) { + this(id, TileUtils.readTile(tileData)); + finishLoad(); + } + + private SpawnRegion(UUID id, Tile tile) { + super(id, null); + this.tile = tile; + // TODO: Initialize + } + + @Override + public void writeTileData(JsonWriter writer) throws IOException { + TileUtils.writeTile(writer, tile); + } + + @Override + public @NonNull RegionType getType() { + return RegionType.SPAWN; + } + + @Override + public @NonNull Area getArea() { + return null; + } + + @Override + public @NonNull Area getBuildArea() { + return Area.EMPTY; + } + + @Override + public @NonNull Area getTestblockArea() { + return Area.EMPTY; + } + + @Override + public @NonNull GameModeConfig getGameModeConfig() { + return GameModeConfig.getDefaults(); + } + + @Override + public @NonNull RegionHistory getHistory() { + return RegionHistory.EMPTY; + } + + @Override + public @NonNull RegionBackups getBackups() { + return RegionBackups.EMPTY; + } +}