diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PasteBuilder.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PasteBuilder.java index f6b05414..9323ceab 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PasteBuilder.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PasteBuilder.java @@ -57,6 +57,19 @@ public class PasteBuilder { this.clipboardProvider = clipboardProvider; } + public PasteBuilder with(ClipboardProvider clipboardProvider) { + return new PasteBuilder(clipboardProvider) + .pastePoint(pastPoint) + .rotate(rotate) + .ignoreAir(ignoreAir) + .reset(reset) + .minPoint(minPoint) + .maxPoint(maxPoint) + .waterLevel(waterLevel) + .predicates(predicates) + .mappers(mappers); + } + public PasteBuilder pastePoint(Point point) { this.pastPoint = point; return this; @@ -92,6 +105,16 @@ public class PasteBuilder { return this; } + private PasteBuilder predicates(List> predicates) { + this.predicates = predicates; + return this; + } + + public PasteBuilder mappers(List> mappers) { + this.mappers = mappers; + return this; + } + public PasteBuilder only(BiPredicate predicate) { predicates.add(predicate); return this; 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 f26f1ffb..92d039a1 100644 --- a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/DynamicRegionSystem.java +++ b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/DynamicRegionSystem.java @@ -20,30 +20,48 @@ package de.steamwar.bausystem.region; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.region.dynamic.DynamicRegion; import de.steamwar.bausystem.region.dynamic.MovementListener; -import de.steamwar.bausystem.region.dynamic.Tile; +import de.steamwar.bausystem.region.dynamic.RegionDataRepository; import de.steamwar.bausystem.region.dynamic.global.GlobalRegion; +import de.steamwar.bausystem.region.dynamic.spawn.SpawnPathRegion; +import de.steamwar.bausystem.region.dynamic.spawn.SpawnRegion; import lombok.NonNull; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.World; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; +import java.util.*; import java.util.stream.Stream; public class DynamicRegionSystem implements RegionSystem { public static DynamicRegionSystem INSTANCE; + private static final World WORLD = Bukkit.getWorlds().get(0); - private static Map tileMap = new HashMap<>(); private static Map regionMap = new HashMap<>(); @Override public void load() { INSTANCE = this; + RegionDataRepository.loadRegions(); Bukkit.getPluginManager().registerEvents(new MovementListener(), BauSystem.getInstance()); + + if (regionMap.isEmpty()) { + new SpawnRegion(-9, -9); + new SpawnPathRegion(-9, -27); + new SpawnPathRegion(-9, 10); + new SpawnPathRegion(-27, -9); + new SpawnPathRegion(10, -9); + } + } + + public void add(DynamicRegion region) { + regionMap.put(region.getID(), region); + } + + public void delete(DynamicRegion region) { + regionMap.remove(region.getID()); } @Override @@ -62,11 +80,10 @@ public class DynamicRegionSystem implements RegionSystem { @Override public @NonNull Region get(@NonNull Location location) { - Optional tile = Tile.fromLocation(location); - if (tile.isEmpty()) return GlobalRegion.INSTANCE; - UUID uuid = tileMap.get(tile.get()); - if (uuid == null) return GlobalRegion.INSTANCE; - return regionMap.getOrDefault(uuid, GlobalRegion.INSTANCE); + return regionMap.values().stream() + .filter(region -> region.getArea().inRegion(location, false)) + .findFirst() + .orElse(GlobalRegion.INSTANCE); } @Override @@ -79,6 +96,26 @@ public class DynamicRegionSystem implements RegionSystem { return regionMap.values().stream(); } + public Stream getNeighbours(Region region) { + Point minPoint = region.getArea().getMinPoint(false).subtract(19, 0, 19); + Point maxPoint = region.getArea().getMaxPoint(false).add(19, 0, 19); + Set neighbours = new HashSet<>(); + for (int x = minPoint.getX(); x <= maxPoint.getX(); x += 19) { + int minZ = minPoint.getZ(); + int maxZ = maxPoint.getZ(); + neighbours.add(get(new Location(WORLD, x, 0, minZ))); + neighbours.add(get(new Location(WORLD, x, 0, maxZ))); + } + for (int z = minPoint.getZ() + 19; z <= maxPoint.getZ() - 19; z += 19) { + int minX = minPoint.getX(); + int maxX = maxPoint.getX(); + neighbours.add(get(new Location(WORLD, minX, 0, z))); + neighbours.add(get(new Location(WORLD, maxX, 0, z))); + } + neighbours.remove(GlobalRegion.INSTANCE); + return neighbours.stream(); + } + @Override public boolean isModular() { return true; 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 8fe3b713..1d545d58 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 @@ -19,14 +19,67 @@ package de.steamwar.bausystem.region.dynamic; -import de.steamwar.bausystem.region.FlagStorage; -import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.*; +import lombok.NonNull; -public interface DynamicRegion extends Region { +import java.util.UUID; - default void update(Tile updateFrom) { - System.out.println("Updating from " + updateFrom); +public abstract class DynamicRegion implements Region { + + protected final UUID id; + protected final int minX; + protected final int minZ; + + protected final RegionHistory history = new RegionHistory.Impl(20); + protected final RegionBackups backups; + + protected DynamicRegion(int minX, int minZ) { + this.id = UUID.randomUUID(); + this.minX = minX; + this.minZ = minZ; + backups = RegionDataRepository.getBackups(this); + RegionDataRepository.saveRegion(this); + DynamicRegionSystem.INSTANCE.add(this); } - void setFlags(FlagStorage flags); + protected DynamicRegion(RegionConstructorData regionConstructorData) { + this.id = regionConstructorData.uuid; + this.minX = regionConstructorData.minX; + this.minZ = regionConstructorData.minZ; + backups = RegionDataRepository.getBackups(this); + DynamicRegionSystem.INSTANCE.add(this); + } + + public RegionConstructorData getRegionConstructorData() { + return new RegionConstructorData.RegionConstructorDataBuilder() + .regionClass(this.getClass().getSimpleName()) + .uuid(id) + .minX(minX) + .minZ(minZ) + .build(); + } + + @Override + public @NonNull UUID getID() { + return id; + } + + public abstract void update(DynamicRegion updateFrom); + + public abstract void setFlags(FlagStorage flags); + + public void delete() { + DynamicRegionSystem.INSTANCE.delete(this); + RegionDataRepository.deleteRegion(this); + } + + @Override + public @NonNull RegionHistory getHistory() { + return history; + } + + @Override + public @NonNull RegionBackups getBackups() { + return backups; + } } diff --git a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/MovementListener.java b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/MovementListener.java index 0f337190..33a1197e 100644 --- a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/MovementListener.java +++ b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/MovementListener.java @@ -20,8 +20,10 @@ package de.steamwar.bausystem.region.dynamic; import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.shared.Pair; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.Location; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerMoveEvent; @@ -30,14 +32,28 @@ import java.util.Optional; public class MovementListener implements Listener { + private static final int tileSize = 19; + private static final int minTile = -1023; + private static final int maxTile = 1023; + + public static Pair fromLocation(Location location) { + int x = (location.getBlockX() + 9) / tileSize; + int z = (location.getBlockZ() + 9) / tileSize; + if (location.getX() < -9) x--; + if (location.getZ() < -9) z--; + if (x < minTile || z < minTile) return null; + if (x > maxTile || z > maxTile) return null; + return new Pair<>(x, z); + } + @EventHandler public void onPlayerMove(PlayerMoveEvent event) { - Optional tile = Tile.fromLocation(event.getTo()); + Pair tile = fromLocation(event.getTo()); Region region = Region.getRegion(event.getTo()); - if (tile.isPresent()) { - event.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(region.getType() + " " + tile.get() + " " + region.getType())); + if (tile != null) { + event.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(tile.getKey() + " : " + tile.getValue() + " " + region.getType())); } else { - event.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(region.getType() + " NONE " + region.getType())); + event.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("NONE " + region.getType())); } } } diff --git a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/global/GlobalFlagStorage.java b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/NonNormalFlagStorage.java similarity index 90% rename from BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/global/GlobalFlagStorage.java rename to BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/NonNormalFlagStorage.java index a55b3d74..b96ecd5c 100644 --- a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/global/GlobalFlagStorage.java +++ b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/NonNormalFlagStorage.java @@ -17,11 +17,10 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.region.dynamic.global; +package de.steamwar.bausystem.region.dynamic; import de.steamwar.bausystem.region.FlagOptional; import de.steamwar.bausystem.region.RegionFlagPolicy; -import de.steamwar.bausystem.region.dynamic.DefaultFlagStorage; import de.steamwar.bausystem.region.flags.ColorMode; import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.ProtectMode; @@ -31,9 +30,9 @@ import lombok.NonNull; import lombok.ToString; @ToString -public class GlobalFlagStorage extends DefaultFlagStorage { +public class NonNormalFlagStorage extends DefaultFlagStorage { - public GlobalFlagStorage() { + public NonNormalFlagStorage() { flagMap.put(Flag.TNT, TNTMode.DENY); } diff --git a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/RegionConstructorData.java b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/RegionConstructorData.java new file mode 100644 index 00000000..fb18dc7e --- /dev/null +++ b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/RegionConstructorData.java @@ -0,0 +1,61 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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; + +import com.google.gson.JsonObject; +import com.google.gson.stream.JsonWriter; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Cleanup; +import lombok.SneakyThrows; + +import java.io.File; +import java.io.FileWriter; +import java.util.UUID; + +@Builder +@AllArgsConstructor +public class RegionConstructorData { + + public final String regionClass; + public final UUID uuid; + public final int minX; + public final int minZ; + + public RegionConstructorData(JsonObject jsonObject) { + regionClass = jsonObject.get("regionClass").getAsString(); + uuid = UUID.fromString(jsonObject.get("uuid").getAsString()); + minX = jsonObject.get("minX").getAsInt(); + minZ = jsonObject.get("minZ").getAsInt(); + } + + @SneakyThrows + public void write(File file) { + @Cleanup + JsonWriter writer = new JsonWriter(new FileWriter(file)); + writer.setIndent(" "); + writer.beginObject(); + writer.name("regionClass").value(regionClass); + writer.name("uuid").value(uuid.toString()); + writer.name("minX").value(minX); + writer.name("minZ").value(minZ); + writer.endObject(); + } +} diff --git a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/RegionDataRepository.java b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/RegionDataRepository.java index a369ea17..e7dbeb27 100644 --- a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/RegionDataRepository.java +++ b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/RegionDataRepository.java @@ -25,8 +25,11 @@ import com.google.gson.stream.JsonWriter; import com.sk89q.worldedit.EditSession; import de.steamwar.bausystem.region.FlagStorage; import de.steamwar.bausystem.region.Point; +import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.RegionBackups; import de.steamwar.bausystem.region.dynamic.normal.NormalFlagStorage; +import de.steamwar.bausystem.region.dynamic.spawn.SpawnPathRegion; +import de.steamwar.bausystem.region.dynamic.spawn.SpawnRegion; import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.utils.FlatteningWrapper; import de.steamwar.bausystem.utils.PasteBuilder; @@ -48,29 +51,61 @@ import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; +import java.util.function.Function; @UtilityClass public class RegionDataRepository { + public static final String META_FILE_NAME = "meta.json"; public static final String FLAGS_FILE_NAME = "flags.json"; public static final String REGION_SCHEM_FILE_NAME = "region.schem"; + public static final String BACKUP_DIRECTORY = "backup"; private static File regionDataFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "regions"); + private static Map> regionCreators = new HashMap<>(); + static { + regionCreators.put(SpawnRegion.class.getSimpleName(), SpawnRegion::new); + regionCreators.put(SpawnPathRegion.class.getSimpleName(), SpawnPathRegion::new); + } static { regionDataFolder.mkdirs(); } - private File getRegionDirectory(DynamicRegion region) { + private File getRegionDirectory(Region region) { File file = new File(regionDataFolder, region.getID().toString()); file.mkdirs(); return file; } - public void loadFlagStorage(DynamicRegion region, FlagStorage storage) { + @SneakyThrows + public List loadRegions() { + File[] files = regionDataFolder.listFiles(); + List regions = new ArrayList<>(); + for (File file : files) { + File metaFile = new File(file, META_FILE_NAME); + if (!metaFile.exists()) continue; + JsonObject jsonObject = JsonParser.parseReader(new FileReader(metaFile)).getAsJsonObject(); + RegionConstructorData regionConstructorData = new RegionConstructorData(jsonObject); + Function constructor = regionCreators.get(regionConstructorData.regionClass); + if (constructor == null) continue; + regions.add(constructor.apply(regionConstructorData)); + } + return regions; + } + + public void saveRegion(DynamicRegion region) { + File file = getRegionDirectory(region); + file = new File(file, META_FILE_NAME); + region.getRegionConstructorData() + .write(file); + } + + public void deleteRegion(DynamicRegion region) { + deleteDir(getRegionDirectory(region)); + } + + public void loadFlagStorage(Region region, FlagStorage storage) { File file = getRegionDirectory(region); file = new File(file, FLAGS_FILE_NAME); loadFlagStorage(file, storage); @@ -84,6 +119,7 @@ public class RegionDataRepository { if (file == null || !file.exists()) return; JsonObject jsonObject = JsonParser.parseReader(new FileReader(file)).getAsJsonObject(); for (Flag flag : Flag.getFlags()) { + if (!jsonObject.has(flag.name())) continue; Flag.Value value; try { value = flag.valueOfValue(jsonObject.get(flag.name()).getAsString()); @@ -94,7 +130,7 @@ public class RegionDataRepository { } } - private void saveFlagStorage(DynamicRegion region, FlagStorage storage) { + private void saveFlagStorage(Region region, FlagStorage storage) { File file = getRegionDirectory(region); file = new File(file, FLAGS_FILE_NAME); saveFlagStorage(file, storage); @@ -121,7 +157,7 @@ public class RegionDataRepository { return RegionBackups.EMPTY; } - File directory = new File(getRegionDirectory(region), "backup"); + File directory = new File(getRegionDirectory(region), BACKUP_DIRECTORY); directory.mkdirs(); return new RegionBackups() { private List backups = new ArrayList<>(); diff --git a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/Tile.java b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/Tile.java deleted file mode 100644 index f29b5405..00000000 --- a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/Tile.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2020 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; - -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import org.bukkit.Location; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -@AllArgsConstructor(access = AccessLevel.PRIVATE) -public class Tile { - - private static final int tileSize = 19; - private static final int minTile = -1023; - private static final int maxTile = 1023; - - public static Optional fromLocation(Location location) { - int x = (location.getBlockX() + 9) / tileSize; - int z = (location.getBlockZ() + 9) / tileSize; - if (location.getX() < -9) x--; - if (location.getZ() < -9) z--; - if (x < minTile || z < minTile) return Optional.empty(); - if (x > maxTile || z > maxTile) return Optional.empty(); - return Optional.of(new Tile(x, z)); - } - - private int x; - private int z; - - public String toString() { - return x + " : " + z; - } - - public List getNeighbors() { - List neighbors = new ArrayList<>(); - for (int x = -1; x <= 1; x++) { - for (int z = -1; z <= 1; z++) { - if (x == 0 && z == 0) continue; - if (this.x + x < minTile || this.z + z < minTile) continue; - if (this.x + x > maxTile || this.z + z > maxTile) continue; - neighbors.add(new Tile(this.x + x, this.z + z)); - } - } - return neighbors; - } -} diff --git a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/TileArea.java b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/TileArea.java new file mode 100644 index 00000000..71a11093 --- /dev/null +++ b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/TileArea.java @@ -0,0 +1,84 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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; + +import com.sk89q.worldedit.EditSession; +import de.steamwar.bausystem.region.Point; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.RegionHistory; +import de.steamwar.bausystem.utils.PasteBuilder; +import lombok.NonNull; + +import javax.annotation.Nullable; +import java.io.File; + +public class TileArea implements Region.Area { + + private final int minX; + private final int minZ; + private final File resetFile; + private final Point minPoint; + private final Point maxPoint; + private final Point copyPoint; + private final RegionHistory regionHistory; + + public TileArea(int minX, int minZ, File resetFile, RegionHistory regionHistory) { + this.minX = minX; + this.minZ = minZ; + this.resetFile = resetFile; + + minPoint = new Point(minX, 0, minZ); + maxPoint = new Point(minX + 18, 255, minZ + 18); + copyPoint = new Point(minX + 9, 0, minZ + 9); + + this.regionHistory = regionHistory; + } + + @Override + public @NonNull Point getMinPoint(boolean extension) { + return minPoint; + } + + @Override + public @NonNull Point getMaxPoint(boolean extension) { + return maxPoint; + } + + @Override + public @NonNull Point getCopyPoint() { + return copyPoint; + } + + @Nullable + @Override + public File getResetFile() { + return resetFile; + } + + @Override + public void reset(PasteBuilder pasteBuilder, boolean extension) { + EditSession editSession = pasteBuilder.with(new PasteBuilder.FileProvider(resetFile)) + .minPoint(minPoint) + .maxPoint(maxPoint) + .pastePoint(minPoint) + .run(); + regionHistory.remember(editSession); + } +} diff --git a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/global/GlobalRegion.java b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/global/GlobalRegion.java index 5a7da285..abacec3a 100644 --- a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/global/GlobalRegion.java +++ b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/global/GlobalRegion.java @@ -22,6 +22,7 @@ package de.steamwar.bausystem.region.dynamic.global; import com.sk89q.worldedit.extent.clipboard.Clipboard; import de.steamwar.bausystem.region.*; import de.steamwar.bausystem.region.dynamic.DynamicRegion; +import de.steamwar.bausystem.region.dynamic.NonNormalFlagStorage; import de.steamwar.bausystem.region.dynamic.RegionDataRepository; import de.steamwar.bausystem.utils.PasteBuilder; import lombok.NonNull; @@ -32,7 +33,7 @@ import java.io.File; import java.util.UUID; import java.util.function.BiConsumer; -public class GlobalRegion implements DynamicRegion { +public class GlobalRegion implements Region { public static final GlobalRegion INSTANCE = new GlobalRegion(); @@ -90,7 +91,7 @@ public class GlobalRegion implements DynamicRegion { private static final RegionConfig GLOBAL_CONFIG = new RegionConfig(null); - private static FlagStorage FLAG_STORAGE = new GlobalFlagStorage(); + private static FlagStorage FLAG_STORAGE = new NonNormalFlagStorage(); static { RegionDataRepository.loadFlagStorage(INSTANCE, FLAG_STORAGE); } @@ -113,11 +114,6 @@ public class GlobalRegion implements DynamicRegion { return FLAG_STORAGE; } - @Override - public void setFlags(FlagStorage flags) { - throw new UnsupportedOperationException(); - } - @Override public @NonNull Region.Area getArea() { return GLOBAL_AREA; diff --git a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/spawn/SpawnPathRegion.java b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/spawn/SpawnPathRegion.java new file mode 100644 index 00000000..ab1a537e --- /dev/null +++ b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/spawn/SpawnPathRegion.java @@ -0,0 +1,84 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.FlagStorage; +import de.steamwar.bausystem.region.RegionConfig; +import de.steamwar.bausystem.region.RegionType; +import de.steamwar.bausystem.region.dynamic.*; +import lombok.NonNull; + +public class SpawnPathRegion extends DynamicRegion { + + private FlagStorage flagStorage = new NonNormalFlagStorage(); + private final Area area; + private final RegionConfig config = new RegionConfig(null); + + public SpawnPathRegion(int minX, int minZ) { + super(minX, minZ); + RegionDataRepository.loadFlagStorage(this, flagStorage); + area = new TileArea(minX, minZ, null, history); + } + + public SpawnPathRegion(RegionConstructorData regionConstructorData) { + super(regionConstructorData); + RegionDataRepository.loadFlagStorage(this, flagStorage); + area = new TileArea(minX, minZ, null, history); + } + + @Override + public void update(DynamicRegion updateFrom) { + // TODO: Implement + } + + @Override + public void setFlags(FlagStorage flags) { + } + + @Override + public @NonNull RegionType getType() { + return RegionType.SPAWN_PATH; + } + + @Override + public @NonNull FlagStorage getFlags() { + return flagStorage; + } + + @Override + public @NonNull Area getArea() { + return area; + } + + @Override + public @NonNull Area getBuildArea() { + return Area.EMPTY; + } + + @Override + public @NonNull Area getTestblockArea() { + return Area.EMPTY; + } + + @Override + public @NonNull RegionConfig getGameModeConfig() { + return config; + } +} 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..d11f602f --- /dev/null +++ b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/spawn/SpawnRegion.java @@ -0,0 +1,84 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.FlagStorage; +import de.steamwar.bausystem.region.RegionConfig; +import de.steamwar.bausystem.region.RegionType; +import de.steamwar.bausystem.region.dynamic.*; +import lombok.NonNull; + +public class SpawnRegion extends DynamicRegion { + + private FlagStorage flagStorage = new NonNormalFlagStorage(); + private final Area area; + private final RegionConfig config = new RegionConfig(null); + + public SpawnRegion(int minX, int minZ) { + super(minX, minZ); + RegionDataRepository.loadFlagStorage(this, flagStorage); + area = new TileArea(minX, minZ, null, history); + } + + public SpawnRegion(RegionConstructorData regionConstructorData) { + super(regionConstructorData); + RegionDataRepository.loadFlagStorage(this, flagStorage); + area = new TileArea(minX, minZ, null, history); + } + + @Override + public void update(DynamicRegion updateFrom) { + // TODO: Implement + } + + @Override + public void setFlags(FlagStorage flags) { + } + + @Override + public @NonNull RegionType getType() { + return RegionType.SPAWN; + } + + @Override + public @NonNull FlagStorage getFlags() { + return flagStorage; + } + + @Override + public @NonNull Area getArea() { + return area; + } + + @Override + public @NonNull Area getBuildArea() { + return Area.EMPTY; + } + + @Override + public @NonNull Area getTestblockArea() { + return Area.EMPTY; + } + + @Override + public @NonNull RegionConfig getGameModeConfig() { + return config; + } +}