Update Region

This commit is contained in:
2025-07-03 10:22:56 +02:00
parent 7dc9da549c
commit e98f53bbab
3 changed files with 47 additions and 80 deletions
@@ -21,9 +21,13 @@ package de.steamwar.bausystem.region;
import de.steamwar.bausystem.region.flags.Flag;
import java.util.Optional;
public interface FlagStorage {
<T extends Enum<T> & Flag.Value<T>> RegionFlagPolicy has(Flag<T> flag);
<T extends Enum<T> & Flag.Value<T>> boolean set(Flag<T> flag, T value);
<T extends Enum<T> & Flag.Value<T>> T get(Flag<T> flag);
<T extends Enum<T> & Flag.Value<T>> Optional<T> get(Flag<T> flag);
}
@@ -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();
<T extends Enum<T> & Flag.Value<T>> RegionFlagPolicy hasFlag(@NonNull Flag<T> flag);
FlagStorage getFlags();
<T extends Enum<T> & Flag.Value<T>> boolean setFlag(@NonNull Flag<T> flag, T value);
Area getArea();
<T extends Enum<T> & Flag.Value<T>> Optional<T> getFlag(@NonNull Flag<T> flag);
Optional<Area> getBuildArea();
default <T extends Enum<T> & Flag.Value<T>> boolean isFlag(@NonNull Flag<T> flag, T value) {
return isFlag(flag, value, false);
}
default <T extends Enum<T> & Flag.Value<T>> boolean isFlag(@NonNull Flag<T> flag, T value, boolean defaultValue) {
if (hasFlag(flag).isReadable()) {
Optional<T> optional = getFlag(flag);
return optional.isPresent() && optional.get() == value;
}
return defaultValue;
}
Point getMinPoint();
Point getMaxPoint();
boolean inRegion(Location location);
Inner getBuildArea();
Inner getTestblockArea();
Optional<Area> getTestblockArea();
// TODO: Add forEachChunk and getChunkOutsidePredicate
Optional<File> getGameModeConfig();
boolean backup(boolean automatic);
RegionHistory getHistory();
Optional<EditSession> 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<EditSession> 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<EditSession> copy(boolean extension);
void reset(@Nullable SchematicNode schematicNode, boolean extension);
void forEachChunk(BiConsumer<Integer, Integer> executor);
boolean isChunkOutside(int chunkX, int chunkZ);
}
}
@@ -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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.region;
import com.sk89q.worldedit.EditSession;
public interface RegionHistory {
void remember(EditSession editSession);
boolean undo();
boolean redo();
}