Update PathRegion

This commit is contained in:
2026-03-23 15:40:26 +01:00
parent 9c47942237
commit f8dd7f0321
8 changed files with 84 additions and 522 deletions
@@ -91,25 +91,6 @@ public class DynamicRegionSystem implements RegionSystem {
.collect(Collectors.toUnmodifiableMap(entry -> entry.getValue().identifier(), Map.Entry::getKey));
DynamicRegionRepository.loadRegions();
// [STDOUT] PATH 239
// [STDOUT] DRY 4
// [STDOUT] DRY_SPECIAL 18
// [STDOUT] WET 2
// [STDOUT] WET_SPECIAL 9
regionTypeMap.forEach((type, regions) -> {
if (type != RegionType.PATH) return;
MultiTileArea multiTileArea = new MultiTileArea() {
@Override
public void place(Location location, PasteBuilder pasteBuilder, boolean extension) {
}
};
for (Region region : regions) {
PathRegion pathRegion = (PathRegion) region;
multiTileArea.addTile(pathRegion.getTile());
}
multiTileArea.quantize();
});
new DynamicRegionCommand();
new WireframeCommand();
}
@@ -27,6 +27,7 @@ import de.steamwar.bausystem.region.DynamicRegionSystem;
import de.steamwar.bausystem.region.Point;
import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.region.RegionData;
import de.steamwar.bausystem.region.dynamic.path.PathArea;
import de.steamwar.bausystem.region.dynamic.path.PathRegion;
import de.steamwar.bausystem.shared.Pair;
import lombok.Getter;
@@ -136,12 +136,6 @@ public class DynamicRegionRepository {
}
constructRegion(regionClass, regionUUID, tileData);
}
// Calculate Garden State for all PathRegions
DynamicRegionSystem.INSTANCE.getRegionsByType(RegionType.PATH)
.forEach(region -> {
((PathRegion) region).calculateGardenState();
});
}
public static DynamicRegion constructRegion(Class<? extends DynamicRegion> clazz, Tile tile) {
@@ -19,12 +19,12 @@
package de.steamwar.bausystem.region.dynamic.path;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.region.DynamicRegionSystem;
import de.steamwar.bausystem.region.Point;
import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.region.RegionType;
import de.steamwar.bausystem.region.dynamic.MultiTileArea;
import de.steamwar.bausystem.region.dynamic.PasteUtils;
import de.steamwar.bausystem.region.dynamic.Tile;
import de.steamwar.bausystem.region.dynamic.VariantSelector;
@@ -33,16 +33,14 @@ import de.steamwar.bausystem.utils.PasteBuilder;
import lombok.NonNull;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.function.BiConsumer;
import static de.steamwar.bausystem.region.RegionType.ConnectionType.*;
public class PathArea implements Region.Area {
public class PathArea extends MultiTileArea {
private static final File PATH_DIR = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "sections/path");
private static final File FALLBACK_SCHEM = new File(PATH_DIR, "Fallback.schem");
@@ -111,64 +109,15 @@ public class PathArea implements Region.Area {
.Case(Path, Path, Garden, CORNER_INNER_GARDEN, RotationCorrection.UsingOrdinal)
;
private final PathRegion region;
private final UUID regionIdentifier;
private final Tile tile;
private final Point minPoint;
private final Point maxPoint;
private final Point copyPoint;
public PathArea(Tile tile, PathRegion region) {
this.region = region;
this.regionIdentifier = region.getID();
this.tile = tile;
minPoint = Point.fromLocation(tile.getMinLocation()).setY(WORLD_MIN_Y);
maxPoint = Point.fromLocation(tile.getMaxLocation()).setY(WORLD_MAX_Y);
copyPoint = Point.fromLocation(tile.getCenterLocation());
public PathArea() {
}
@Override
public @NonNull Point getMinPoint(boolean extension) {
return minPoint;
public PathArea(List<Pair<Tile, Tile>> list) {
super(list);
}
@Override
public @NonNull Point getMaxPoint(boolean extension) {
return maxPoint;
}
@Override
public @NonNull Point getCopyPoint() {
return Point.ZERO;
}
@Override
public boolean inRegion(Location location, boolean extension) {
return inRegion(location.getBlockX(), location.getBlockZ(), extension);
}
@Override
public boolean inRegion(int x, int z, boolean extension) {
// TODO: Implement further!
return Region.Area.super.inRegion(x, z, extension);
}
@Override
public @Nullable Clipboard copy(boolean extension) {
return null;
}
@Override
public void forEachChunk(BiConsumer<Integer, Integer> executor) {
}
@Override
public boolean isChunkOutside(int chunkX, int chunkZ) {
return true;
}
public void reset(PathSide side) {
public void reset(@NonNull Tile tile, PathSide side) {
if (!tiles.contains(tile)) return;
File resetFile = null;
VariantSelector selector = SELECTOR_SIDE.Select(tile, side);
if (selector != null) resetFile = selector.select().orElse(null);
@@ -177,10 +126,12 @@ public class PathArea implements Region.Area {
resetFile = FALLBACK_SCHEM;
}
Point minPoint = Point.fromLocation(tile.getMinLocation());
PasteUtils.paste(resetFile, minPoint.add(side.pasteOffsetX, 0, side.pasteOffsetZ), side.rotate);
}
public void reset(PathCorner corner) {
public void reset(@NonNull Tile tile, PathCorner corner) {
if (!tiles.contains(tile)) return;
File resetFile = null;
Pair<VariantSelector, RotationCorrection> pair = SELECTOR_CORNER.Select(tile, corner);
VariantSelector selector = pair.getKey();
@@ -204,12 +155,17 @@ public class PathArea implements Region.Area {
break;
}
Point minPoint = Point.fromLocation(tile.getMinLocation());
PasteUtils.paste(resetFile, minPoint.add(corner.pasteOffsetX, 0, corner.pasteOffsetZ), rotate);
}
@Override
public void place(Location location, PasteBuilder pasteBuilder, boolean extension) {
if (region.isGarden()) {
Tile tile = Tile.fromLocation(location).orElse(null);
if (tile == null || !tiles.contains(tile)) return;
Point minPoint = Point.fromLocation(tile.getMinLocation());
if (isGarden(tile)) {
File resetFile = GARDEN.select().orElse(null);
if (resetFile != null) {
PasteUtils.paste(resetFile, minPoint, 0);
@@ -223,14 +179,30 @@ public class PathArea implements Region.Area {
}
for (PathSide side : PathSide.values()) {
reset(side);
reset(tile, side);
}
for (PathCorner corner : PathCorner.values()) {
reset(corner);
reset(tile, corner);
}
}
public static boolean isGarden(Tile tile) {
for (int x = -1; x <= 1; x++) {
for (int z = -1; z <= 1; z++) {
if (x == 0 && z == 0) continue;
Tile t = tile.add(x, z).orElse(null);
if (t == null) {
return false;
}
if (!DynamicRegionSystem.INSTANCE.get(t).getType().isPath()) {
return false;
}
}
}
return true;
}
protected static RegionType.ConnectionType getConnectionType(Tile tile, PathSide side, PathSide optionalSide) {
Optional<Tile> optionalTile = tile.add(side.tileOffsetX, side.tileOffsetZ);
if (optionalSide != null) {
@@ -241,8 +213,8 @@ public class PathArea implements Region.Area {
}
tile = optionalTile.get();
Region region = DynamicRegionSystem.INSTANCE.get(tile.getCenterLocation());
if (region instanceof PathRegion pathRegion) {
return pathRegion.isGarden() ? Garden : Path;
if (region instanceof PathRegion) {
return isGarden(tile) ? Garden : Path;
}
return region.getType().getConnectionType();
}
@@ -19,13 +19,16 @@
package de.steamwar.bausystem.region.dynamic.path;
import com.google.gson.JsonArray;
import com.google.gson.stream.JsonWriter;
import de.steamwar.bausystem.region.*;
import de.steamwar.bausystem.region.dynamic.*;
import de.steamwar.sql.GameModeConfig;
import lombok.Getter;
import lombok.NonNull;
import org.bukkit.Location;
import org.bukkit.Material;
import java.io.IOException;
import java.util.UUID;
@RegionConstructorData(
@@ -38,45 +41,39 @@ import java.util.UUID;
public class PathRegion extends DynamicRegion {
private final PathArea area;
@Getter
private final Tile tile;
public PathRegion(UUID id, int minX, int minZ) {
super(id, minX, minZ);
tile = Tile.fromXZ(minX, minZ).orElseThrow();
area = new PathArea(tile, this);
public PathRegion(Tile minTile, PathArea area) {
super(minTile);
this.area = new PathArea();
regionData = new PathRegionData(this);
finishInit();
calculateGardenState();
finishCreate();
}
public void update(DynamicRegion updateFrom, NeighbourDirection direction) {
for (PathSide side : direction.getSideUpdates()) {
area.reset(side);
}
for (PathCorner corner : direction.getCornerUpdates()) {
area.reset(corner);
public PathRegion(UUID id, JsonArray tileData) {
super(id, tileData);
area = new PathArea(readQuantizedTiles(tileData));
regionData = new PathRegionData(this);
finishLoad();
}
@Override
public void writeData(JsonWriter writer) throws IOException {
writeQuantizedTiles(writer, area.quantize());
}
public void add(Tile tile) {
if (area.addTile(tile)) {
save();
}
}
@Getter
private boolean garden = false;
public void calculateGardenState() {
garden = false;
for (int x = -1; x <= 1; x++) {
for (int z = -1; z <= 1; z++) {
if (x == 0 && z == 0) continue;
Tile t = tile.add(x, z).orElse(null);
if (t == null) {
return;
}
if (!DynamicRegionSystem.INSTANCE.get(t).getType().isPath()) {
return;
}
}
public void update(Tile toUpdate, NeighbourDirection toDirection) {
for (PathSide side : toDirection.getSideUpdates()) {
area.reset(toUpdate, side);
}
for (PathCorner corner : toDirection.getCornerUpdates()) {
area.reset(toUpdate, corner);
}
garden = true;
}
@Override
@@ -125,7 +122,22 @@ public class PathRegion extends DynamicRegion {
}
@Override
public String toString() {
return tile + "=" + getID();
public void delete(Location location) {
Tile tile = Tile.fromLocation(location).orElse(null);
if (tile == null) return;
boolean delete = area.removeTile(tile);
if (delete) {
DynamicRegionSystem.INSTANCE.remove(this);
DynamicRegionRepository.deleteRegion(this);
}
Point minPoint = Point.fromLocation(tile.getMinLocation());
Point maxPoint = Point.fromLocation(tile.getMaxLocation());
PasteUtils.reset(minPoint, maxPoint);
this.updateNeighbours();
if (!delete) {
save();
}
}
}
@@ -1,203 +0,0 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.region.dynamic.path_special;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.region.DynamicRegionSystem;
import de.steamwar.bausystem.region.Point;
import de.steamwar.bausystem.region.dynamic.MultiTileArea;
import de.steamwar.bausystem.region.dynamic.PasteUtils;
import de.steamwar.bausystem.region.dynamic.Tile;
import de.steamwar.bausystem.region.dynamic.VariantSelector;
import de.steamwar.bausystem.region.dynamic.path.*;
import de.steamwar.bausystem.shared.Pair;
import de.steamwar.bausystem.utils.PasteBuilder;
import lombok.NonNull;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import java.io.File;
import java.util.List;
import static de.steamwar.bausystem.region.RegionType.ConnectionType.*;
public class PathArea extends MultiTileArea {
private static final File PATH_DIR = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "sections/path");
private static final File FALLBACK_SCHEM = new File(PATH_DIR, "Fallback.schem");
private static final VariantSelector CENTER_NORMAL = VariantSelector.Get(new File(PATH_DIR, "center/normal"));
private static final VariantSelector SIDE_GLOBAL = VariantSelector.Get(new File(PATH_DIR, "side/global"));
private static final VariantSelector CORNER_INNER_GLOBAL = VariantSelector.Get(new File(PATH_DIR, "cinner/global"));
private static final VariantSelector CORNER_OUTER_GLOBAL = VariantSelector.Get(new File(PATH_DIR, "couter/global"));
private static final VariantSelector SIDE_WATER = VariantSelector.Get(new File(PATH_DIR, "side/water"));
private static final VariantSelector CORNER_INNER_WATER = VariantSelector.Get(new File(PATH_DIR, "cinner/water"));
private static final VariantSelector CORNER_OUTER_WATER = VariantSelector.Get(new File(PATH_DIR, "couter/water"));
private static final VariantSelector SIDE_CLOSED = VariantSelector.Get(new File(PATH_DIR, "side/closed"));
private static final VariantSelector CORNER_INNER_CLOSED = VariantSelector.Get(new File(PATH_DIR, "cinner/closed"));
private static final VariantSelector CORNER_OUTER_CLOSED = VariantSelector.Get(new File(PATH_DIR, "couter/closed"));
private static final VariantSelector GARDEN = VariantSelector.Get(new File(PATH_DIR, "garden"));
private static final VariantSelector SIDE_GARDEN = VariantSelector.Get(new File(PATH_DIR, "side/garden"));
private static final VariantSelector SIDE_GARDEN_CONNECTED = VariantSelector.Get(new File(PATH_DIR, "side/garden_connected"));
private static final VariantSelector CORNER_INNER_GARDEN = VariantSelector.Get(new File(PATH_DIR, "cinner/garden"));
private static final VariantSelector CORNER_OUTER_GARDEN = VariantSelector.Get(new File(PATH_DIR, "couter/garden"));
private static final SelectorSide SELECTOR_SIDE = new SelectorSide()
.Case(Path, CENTER_NORMAL)
.Case(Global, SIDE_GLOBAL)
.Case(Water, SIDE_WATER)
.Case(Closed, SIDE_CLOSED)
.Case(Garden, SIDE_GARDEN_CONNECTED);
private static final SelectorCorner SELECTOR_CORNER = new SelectorCorner()
// Path to Path
.Case(Path, Path, Path, CENTER_NORMAL, RotationCorrection.UsingOrdinal)
// Path to Global
.Case(Path, Global, Global, SIDE_GLOBAL, RotationCorrection.WithCorrection)
.Case(Global, Path, Path, SIDE_GLOBAL)
.Case(Global, Path, Global, SIDE_GLOBAL)
.Case(Path, Global, Path, SIDE_GLOBAL, RotationCorrection.WithCorrection)
.Case(Global, Global, Global, CORNER_OUTER_GLOBAL, RotationCorrection.UsingOrdinal)
.Case(Global, Global, Path, CORNER_OUTER_GLOBAL, RotationCorrection.UsingOrdinal)
.Case(Path, Path, Global, CORNER_INNER_GLOBAL, RotationCorrection.UsingOrdinal)
// Path to Water
.Case(Path, Water, Water, SIDE_WATER, RotationCorrection.WithCorrection)
.Case(Water, Path, Path, SIDE_WATER)
.Case(Water, Path, Water, SIDE_WATER)
.Case(Path, Water, Path, SIDE_WATER, RotationCorrection.WithCorrection)
.Case(Water, Water, Water, CORNER_OUTER_WATER, RotationCorrection.UsingOrdinal)
.Case(Water, Water, Path, CORNER_OUTER_WATER, RotationCorrection.UsingOrdinal)
.Case(Path, Path, Water, CORNER_INNER_WATER, RotationCorrection.UsingOrdinal)
// Path to Closed
.Case(Path, Closed, Closed, SIDE_CLOSED, RotationCorrection.WithCorrection)
.Case(Closed, Path, Path, SIDE_CLOSED)
.Case(Closed, Path, Closed, SIDE_CLOSED)
.Case(Path, Closed, Path, SIDE_CLOSED, RotationCorrection.WithCorrection)
.Case(Closed, Closed, Closed, CORNER_OUTER_CLOSED, RotationCorrection.UsingOrdinal)
.Case(Closed, Closed, Path, CORNER_OUTER_CLOSED, RotationCorrection.UsingOrdinal)
.Case(Path, Path, Closed, CORNER_INNER_CLOSED, RotationCorrection.UsingOrdinal)
// Path to Garden
.Case(Path, Garden, Garden, SIDE_GARDEN, RotationCorrection.WithCorrection)
.Case(Garden, Path, Path, SIDE_GARDEN)
.Case(Garden, Path, Garden, SIDE_GARDEN)
.Case(Path, Garden, Path, SIDE_GARDEN, RotationCorrection.WithCorrection)
.Case(Garden, Garden, Garden, CORNER_OUTER_GARDEN, RotationCorrection.UsingOrdinal)
.Case(Garden, Garden, Path, CORNER_OUTER_GARDEN, RotationCorrection.UsingOrdinal)
.Case(Path, Path, Garden, CORNER_INNER_GARDEN, RotationCorrection.UsingOrdinal)
;
public PathArea() {
}
public PathArea(List<Pair<Tile, Tile>> list) {
super(list);
}
public void reset(@NonNull Tile tile, PathSide side) {
if (!tiles.contains(tile)) return;
File resetFile = null;
VariantSelector selector = SELECTOR_SIDE.Select(tile, side);
if (selector != null) resetFile = selector.select().orElse(null);
if (selector == null || resetFile == null) {
if (!BauSystem.DEV_SERVER) return;
resetFile = FALLBACK_SCHEM;
}
Point minPoint = Point.fromLocation(tile.getMinLocation());
PasteUtils.paste(resetFile, minPoint.add(side.pasteOffsetX, 0, side.pasteOffsetZ), side.rotate);
}
public void reset(@NonNull Tile tile, PathCorner corner) {
if (!tiles.contains(tile)) return;
File resetFile = null;
Pair<VariantSelector, RotationCorrection> pair = SELECTOR_CORNER.Select(tile, corner);
VariantSelector selector = pair.getKey();
RotationCorrection rotationCorrection = pair.getValue();
if (selector != null) resetFile = selector.select().orElse(null);
if (selector == null || resetFile == null) {
if (!BauSystem.DEV_SERVER) return;
resetFile = FALLBACK_SCHEM;
rotationCorrection = RotationCorrection.Unchanged;
}
int rotate = corner.rotate;
switch (rotationCorrection) {
case Unchanged:
break;
case UsingOrdinal:
rotate = corner.ordinal() * 90;
break;
case WithCorrection:
rotate += corner.rotateCorrection;
break;
}
Point minPoint = Point.fromLocation(tile.getMinLocation());
PasteUtils.paste(resetFile, minPoint.add(corner.pasteOffsetX, 0, corner.pasteOffsetZ), rotate);
}
@Override
public void place(Location location, PasteBuilder pasteBuilder, boolean extension) {
Tile tile = Tile.fromLocation(location).orElse(null);
if (tile == null || !tiles.contains(tile)) return;
Point minPoint = Point.fromLocation(tile.getMinLocation());
if (isGarden(tile)) {
File resetFile = GARDEN.select().orElse(null);
if (resetFile != null) {
PasteUtils.paste(resetFile, minPoint, 0);
}
return;
}
File resetFile = CENTER_NORMAL.select().orElse(null);
if (resetFile != null) {
PasteUtils.paste(resetFile, minPoint.add(7, 0, 7), 0);
}
for (PathSide side : PathSide.values()) {
reset(tile, side);
}
for (PathCorner corner : PathCorner.values()) {
reset(tile, corner);
}
}
private boolean isGarden(Tile tile) {
for (int x = -1; x <= 1; x++) {
for (int z = -1; z <= 1; z++) {
if (x == 0 && z == 0) continue;
Tile t = tile.add(x, z).orElse(null);
if (t == null) {
return false;
}
if (!DynamicRegionSystem.INSTANCE.get(t).getType().isPath()) {
return false;
}
}
}
return true;
}
}
@@ -1,138 +0,0 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.region.dynamic.path_special;
import com.google.gson.JsonArray;
import com.google.gson.stream.JsonWriter;
import de.steamwar.bausystem.region.*;
import de.steamwar.bausystem.region.dynamic.*;
import de.steamwar.bausystem.region.dynamic.path.PathCorner;
import de.steamwar.bausystem.region.dynamic.path.PathSide;
import de.steamwar.sql.GameModeConfig;
import lombok.NonNull;
import org.bukkit.Location;
import org.bukkit.Material;
import java.io.IOException;
import java.util.UUID;
public class PathRegion extends DynamicRegion {
private final PathArea area;
public PathRegion(Tile minTile, PathArea area) {
super(minTile);
this.area = new PathArea();
regionData = new PathRegionData(this);
finishCreate();
}
public PathRegion(UUID id, JsonArray tileData) {
super(id, tileData);
area = new PathArea(readQuantizedTiles(tileData));
regionData = new PathRegionData(this);
finishLoad();
}
@Override
public void writeData(JsonWriter writer) throws IOException {
writeQuantizedTiles(writer, area.quantize());
}
public void add(Tile tile) {
if (area.addTile(tile)) {
save();
}
}
public void update(Tile toUpdate, NeighbourDirection toDirection) {
for (PathSide side : toDirection.getSideUpdates()) {
area.reset(toUpdate, side);
}
for (PathCorner corner : toDirection.getCornerUpdates()) {
area.reset(toUpdate, corner);
}
}
@Override
public @NonNull RegionType getType() {
return RegionType.PATH;
}
@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 GameModeConfig<Material, String> getGameModeConfig() {
return GameModeConfig.getDefaults();
}
@Override
public @NonNull RegionHistory getHistory() {
return RegionHistory.EMPTY;
}
@Override
public @NonNull RegionBackups getBackups() {
return RegionBackups.EMPTY;
}
@Override
public void save() {
DynamicRegionRepository.saveRegion(this);
}
@Override
public void load(RegionData regionData) {
DynamicRegionRepository.loadRegionData(this, regionData);
}
@Override
public void delete(Location location) {
Tile tile = Tile.fromLocation(location).orElse(null);
if (tile == null) return;
boolean delete = area.removeTile(tile);
if (delete) {
DynamicRegionSystem.INSTANCE.remove(this);
DynamicRegionRepository.deleteRegion(this);
}
Point minPoint = Point.fromLocation(tile.getMinLocation());
Point maxPoint = Point.fromLocation(tile.getMaxLocation());
PasteUtils.reset(minPoint, maxPoint);
this.updateNeighbours();
if (!delete) {
save();
}
}
}
@@ -1,57 +0,0 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.region.dynamic.path_special;
import de.steamwar.bausystem.region.RegionData;
import de.steamwar.bausystem.region.RegionFlagPolicy;
import de.steamwar.bausystem.region.flags.FireMode;
import de.steamwar.bausystem.region.flags.Flag;
import de.steamwar.bausystem.region.flags.ProtectMode;
import de.steamwar.bausystem.region.flags.TNTMode;
import de.steamwar.core.Core;
import lombok.NonNull;
public class PathRegionData extends RegionData {
public PathRegionData(PathRegion pathRegion) {
super(pathRegion);
}
@Override
protected void initialize() {
flagMap.put(Flag.TNT, TNTMode.DENY);
flagMap.put(Flag.FIRE, FireMode.DENY);
flagMap.put(Flag.PROTECT, ProtectMode.INACTIVE);
}
@Override
public @NonNull <T extends Enum<T> & Flag.Value<T>> RegionFlagPolicy has(@NonNull Flag<T> flag) {
if (flag.oneOf(Flag.TNT, Flag.FIRE, Flag.PROTECT)) {
return RegionFlagPolicy.READ_ONLY;
}
if (flag.oneOf(Flag.ITEMS) && Core.getVersion() >= 20) {
return RegionFlagPolicy.WRITABLE;
}
if (flag.oneOf(Flag.FREEZE)) {
return RegionFlagPolicy.WRITABLE;
}
return RegionFlagPolicy.NOT_APPLICABLE;
}
}