Files
SteamWar/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java
T

129 lines
3.4 KiB
Java

/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 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;
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;
public interface Region {
static Region getRegion(Location location) {
return RegionSystem.INSTANCE.get(location);
}
RegionType getType();
<T extends Enum<T> & Flag.Value<T>> RegionFlagPolicy hasFlag(@NonNull Flag<T> flag);
<T extends Enum<T> & Flag.Value<T>> boolean setFlag(@NonNull Flag<T> flag, T value);
<T extends Enum<T> & Flag.Value<T>> Optional<T> getFlag(@NonNull Flag<T> flag);
default <T extends Enum<T> & Flag.Value<T>> boolean isFlag(@NonNull Flag<T> flag, T value) {
if (hasFlag(flag).isReadable()) {
Optional<T> optional = getFlag(flag);
return optional.isPresent() && optional.get() == value;
}
return false;
}
Point getMinPoint();
Point getMaxPoint();
boolean inRegion(Location location);
Inner getBuildArea();
Inner getTestblockArea();
// TODO: Add forEachChunk and getChunkOutsidePredicate
Optional<File> getGameModeConfig();
boolean backup(boolean automatic);
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 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;
}
Point getMinPoint(boolean extension);
Point getMaxPoint(boolean extension);
boolean inRegion(Location location, boolean extension);
Optional<EditSession> copy(boolean extension);
void reset(@Nullable SchematicNode schematicNode, boolean extension);
}
}