diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/FlagStorage.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/FlagStorage.java index 3ca76ace..1c8048b6 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/FlagStorage.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/FlagStorage.java @@ -21,9 +21,13 @@ package de.steamwar.bausystem.region; import de.steamwar.bausystem.region.flags.Flag; +import java.util.Optional; + public interface FlagStorage { + & Flag.Value> RegionFlagPolicy has(Flag flag); + & Flag.Value> boolean set(Flag flag, T value); - & Flag.Value> T get(Flag flag); + & Flag.Value> Optional get(Flag flag); } 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 74a4fcec..34d69f45 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java @@ -20,15 +20,14 @@ package de.steamwar.bausystem.region; import com.sk89q.worldedit.EditSession; -import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.sql.SchematicNode; -import lombok.NonNull; import org.bukkit.Location; import javax.annotation.Nullable; import java.io.File; import java.util.Optional; import java.util.UUID; +import java.util.function.BiConsumer; public interface Region { @@ -40,92 +39,21 @@ public interface Region { RegionType getType(); - & Flag.Value> RegionFlagPolicy hasFlag(@NonNull Flag flag); + FlagStorage getFlags(); - & Flag.Value> boolean setFlag(@NonNull Flag flag, T value); + Area getArea(); - & Flag.Value> Optional getFlag(@NonNull Flag flag); + Optional getBuildArea(); - default & Flag.Value> boolean isFlag(@NonNull Flag flag, T value) { - return isFlag(flag, value, false); - } - - default & Flag.Value> boolean isFlag(@NonNull Flag flag, T value, boolean defaultValue) { - if (hasFlag(flag).isReadable()) { - Optional optional = getFlag(flag); - return optional.isPresent() && optional.get() == value; - } - return defaultValue; - } - - Point getMinPoint(); - - Point getMaxPoint(); - - boolean inRegion(Location location); - - Inner getBuildArea(); - - Inner getTestblockArea(); + Optional getTestblockArea(); // TODO: Add forEachChunk and getChunkOutsidePredicate Optional getGameModeConfig(); - boolean backup(boolean automatic); + RegionHistory getHistory(); - Optional copy(); - - void reset(); - - void remember(EditSession editSession); - - boolean undo(); - - boolean redo(); - - interface Inner { - - Inner EMPTY = new Inner() { - private static final Point ZERO = new Point(0, 0, 0); - - @Override - public Point getMinPoint(boolean extension) { - return ZERO; - } - - @Override - public Point getMaxPoint(boolean extension) { - return ZERO; - } - - @Override - public Point getCopyPoint() { - return ZERO; - } - - @Override - public boolean inRegion(Location location, boolean extension) { - return false; - } - - @Override - public Optional copy(boolean extension) { - return Optional.empty(); - } - - @Override - public void reset(@Nullable SchematicNode schematicNode, boolean extension) { - } - }; - - default boolean isEmpty() { - return this == EMPTY; - } - - default boolean isPresent() { - return this != EMPTY; - } + interface Area { Point getMinPoint(boolean extension); @@ -138,5 +66,9 @@ public interface Region { Optional copy(boolean extension); void reset(@Nullable SchematicNode schematicNode, boolean extension); + + void forEachChunk(BiConsumer executor); + + boolean isChunkOutside(int chunkX, int chunkZ); } } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionHistory.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionHistory.java new file mode 100644 index 00000000..17ff9c19 --- /dev/null +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionHistory.java @@ -0,0 +1,31 @@ +/* + * 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; + +import com.sk89q.worldedit.EditSession; + +public interface RegionHistory { + + void remember(EditSession editSession); + + boolean undo(); + + boolean redo(); +}