2021-04-18 09:10:30 +02:00
|
|
|
/*
|
|
|
|
* This file is a part of the SteamWar software.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2021 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;
|
|
|
|
|
2021-04-18 18:53:58 +02:00
|
|
|
import com.sk89q.worldedit.EditSession;
|
2022-08-05 12:22:11 +02:00
|
|
|
import com.sk89q.worldedit.WorldEdit;
|
|
|
|
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
2021-09-18 14:23:52 +02:00
|
|
|
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
2022-07-29 22:36:41 +02:00
|
|
|
import de.steamwar.bausystem.BauSystem;
|
2021-04-18 18:37:32 +02:00
|
|
|
import de.steamwar.bausystem.region.flags.Flag;
|
2021-04-20 12:24:28 +02:00
|
|
|
import de.steamwar.bausystem.region.flags.flagvalues.ColorMode;
|
2021-04-19 19:54:38 +02:00
|
|
|
import de.steamwar.bausystem.region.flags.flagvalues.TNTMode;
|
2021-06-28 17:46:13 +02:00
|
|
|
import de.steamwar.bausystem.region.tags.Tag;
|
2021-04-18 17:34:02 +02:00
|
|
|
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
|
|
|
import de.steamwar.bausystem.region.utils.RegionType;
|
2021-04-18 18:53:58 +02:00
|
|
|
import de.steamwar.bausystem.shared.SizedStack;
|
2022-01-29 15:28:28 +01:00
|
|
|
import de.steamwar.bausystem.utils.FlatteningWrapper;
|
2022-07-29 22:36:41 +02:00
|
|
|
import de.steamwar.core.Core;
|
2022-09-24 20:39:09 +02:00
|
|
|
import de.steamwar.sql.SchematicData;
|
2021-11-30 19:07:12 +01:00
|
|
|
import de.steamwar.sql.SchematicNode;
|
2021-04-20 11:03:46 +02:00
|
|
|
import lombok.AccessLevel;
|
2021-04-18 15:48:15 +02:00
|
|
|
import lombok.Getter;
|
2021-04-18 18:37:32 +02:00
|
|
|
import lombok.NonNull;
|
2021-07-05 19:32:10 +02:00
|
|
|
import org.bukkit.Bukkit;
|
2021-04-18 17:34:02 +02:00
|
|
|
import org.bukkit.Location;
|
|
|
|
import yapion.hierarchy.types.YAPIONObject;
|
|
|
|
import yapion.hierarchy.types.YAPIONType;
|
|
|
|
import yapion.hierarchy.types.YAPIONValue;
|
2021-04-18 15:48:15 +02:00
|
|
|
|
2021-04-20 12:24:28 +02:00
|
|
|
import java.io.File;
|
2021-04-20 09:24:15 +02:00
|
|
|
import java.io.IOException;
|
2021-07-06 11:34:02 +02:00
|
|
|
import java.time.LocalDateTime;
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
import java.util.*;
|
2022-07-29 22:36:41 +02:00
|
|
|
import java.util.function.ObjIntConsumer;
|
2021-04-19 20:33:15 +02:00
|
|
|
import java.util.function.Predicate;
|
2021-05-03 16:58:01 +02:00
|
|
|
import java.util.stream.Collectors;
|
2021-04-18 15:34:31 +02:00
|
|
|
|
2021-04-20 13:46:51 +02:00
|
|
|
import static de.steamwar.bausystem.region.RegionUtils.paste;
|
|
|
|
|
2021-04-18 15:48:15 +02:00
|
|
|
@Getter
|
2021-04-18 09:10:30 +02:00
|
|
|
public class Region {
|
2021-04-18 15:34:31 +02:00
|
|
|
|
2021-07-05 19:32:10 +02:00
|
|
|
@Getter
|
2021-05-03 16:58:01 +02:00
|
|
|
private static final Map<String, Region> REGION_MAP = new HashMap<>();
|
2021-07-05 19:32:10 +02:00
|
|
|
private static final File backupFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "backup");
|
2021-07-31 11:46:45 +02:00
|
|
|
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy.MM.dd' 'HH:mm:ss");
|
2021-04-18 17:34:02 +02:00
|
|
|
|
|
|
|
public static Region getRegion(Location location) {
|
2021-05-03 16:58:01 +02:00
|
|
|
return REGION_MAP.values().stream()
|
2021-05-01 18:18:49 +02:00
|
|
|
.filter(r -> r.inRegion(location, r.minPoint, r.maxPoint))
|
|
|
|
.findFirst()
|
|
|
|
.orElse(GlobalRegion.instance);
|
2021-04-18 17:34:02 +02:00
|
|
|
}
|
|
|
|
|
2021-05-03 16:58:01 +02:00
|
|
|
public static Set<Region> getRegion(Prototype prototype) {
|
|
|
|
return REGION_MAP.values().stream()
|
|
|
|
.filter(r -> r.getPrototype() == prototype)
|
|
|
|
.collect(Collectors.toSet());
|
|
|
|
}
|
|
|
|
|
2021-04-20 08:39:35 +02:00
|
|
|
public static void setGlobal(Flag flagType, Flag.Value<?> value) {
|
2021-05-03 16:58:01 +02:00
|
|
|
REGION_MAP.values().forEach(region -> region.set(flagType, value));
|
2021-04-20 08:39:35 +02:00
|
|
|
}
|
|
|
|
|
2021-04-20 13:46:51 +02:00
|
|
|
YAPIONObject regionData;
|
2021-04-18 18:37:32 +02:00
|
|
|
|
2021-04-18 19:00:19 +02:00
|
|
|
private String name;
|
2021-04-18 15:34:31 +02:00
|
|
|
private Prototype prototype;
|
2021-05-03 17:26:58 +02:00
|
|
|
private Set<String> prototypes;
|
2021-12-22 14:05:44 +01:00
|
|
|
private String skin;
|
2021-04-18 15:34:31 +02:00
|
|
|
|
|
|
|
private Point minPoint;
|
|
|
|
private Point maxPoint;
|
|
|
|
|
|
|
|
private Point minPointTestblock;
|
|
|
|
private Point maxPointTestblock;
|
|
|
|
|
|
|
|
private Point minPointTestblockExtension;
|
|
|
|
private Point maxPointTestblockExtension;
|
|
|
|
|
|
|
|
private Point minPointBuild;
|
|
|
|
private Point maxPointBuild;
|
|
|
|
|
|
|
|
private Point minPointBuildExtension;
|
|
|
|
private Point maxPointBuildExtension;
|
|
|
|
|
2021-04-19 17:32:16 +02:00
|
|
|
private int floorLevel;
|
|
|
|
private int waterLevel;
|
|
|
|
|
2021-05-03 16:32:44 +02:00
|
|
|
private Point copyPoint; // Nullable
|
2021-11-09 20:18:09 +01:00
|
|
|
private Point testBlockPoint; // Nullable
|
2021-05-03 16:32:44 +02:00
|
|
|
|
2021-04-18 19:00:19 +02:00
|
|
|
private String linkedRegionName = null; // Nullable
|
2021-04-18 15:34:31 +02:00
|
|
|
private Region linkedRegion = null; // Nullable
|
|
|
|
|
|
|
|
private FlagStorage flagStorage;
|
|
|
|
|
2021-04-20 11:03:46 +02:00
|
|
|
@Getter(AccessLevel.PRIVATE)
|
2021-04-18 18:53:58 +02:00
|
|
|
private SizedStack<EditSession> undoSessions;
|
2021-04-20 11:03:46 +02:00
|
|
|
|
|
|
|
@Getter(AccessLevel.PRIVATE)
|
2021-04-18 18:53:58 +02:00
|
|
|
private SizedStack<EditSession> redoSessions;
|
|
|
|
|
2021-04-18 19:00:19 +02:00
|
|
|
public Region(String name, Prototype prototype, YAPIONObject regionConfig, FlagStorage flagStorage, YAPIONObject regionData) {
|
|
|
|
this.name = name;
|
2021-04-18 18:37:32 +02:00
|
|
|
this.regionData = regionData;
|
2021-04-18 17:34:02 +02:00
|
|
|
if (prototype != null) {
|
2021-05-03 16:58:01 +02:00
|
|
|
REGION_MAP.put(name, this);
|
2021-04-18 17:34:02 +02:00
|
|
|
}
|
|
|
|
|
2021-04-19 20:33:15 +02:00
|
|
|
linkedRegionName = regionConfig.getPlainValueOrDefault("optionsLinkedWith", null);
|
2021-04-18 19:00:19 +02:00
|
|
|
|
2021-04-18 17:34:02 +02:00
|
|
|
prototypes = new HashSet<>();
|
|
|
|
if (regionConfig.containsKey("prototypes", YAPIONType.ARRAY)) {
|
|
|
|
regionConfig.getArray("prototypes").forEach(yapionAnyType -> {
|
|
|
|
if (yapionAnyType instanceof YAPIONValue) {
|
2021-05-03 17:26:58 +02:00
|
|
|
prototypes.add(((YAPIONValue<String>) yapionAnyType).get());
|
2021-04-18 17:34:02 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-12-01 20:18:18 +01:00
|
|
|
if (regionConfig.containsKey("prototype")) {
|
|
|
|
prototypes.add(regionConfig.getPlainValue("prototype"));
|
|
|
|
}
|
|
|
|
|
2021-04-18 17:34:02 +02:00
|
|
|
this.flagStorage = flagStorage;
|
2021-04-18 18:27:54 +02:00
|
|
|
Point point = null;
|
|
|
|
if (regionConfig.containsKey("minX", Integer.class) && regionConfig.containsKey("minY", Integer.class) && regionConfig.containsKey("minZ", Integer.class)) {
|
|
|
|
point = new Point(regionConfig.getPlainValue("minX"), regionConfig.getPlainValue("minY"), regionConfig.getPlainValue("minZ"));
|
|
|
|
}
|
2021-12-01 20:18:18 +01:00
|
|
|
if (prototype != null && prototypes.contains(prototype.getName())) {
|
|
|
|
generatePrototypeData(prototype, point);
|
|
|
|
} else if (regionConfig.containsKey("prototype")) {
|
|
|
|
generatePrototypeData(Prototype.getByName(regionConfig.getPlainValue("prototype")), point);
|
|
|
|
}
|
2021-12-22 14:05:44 +01:00
|
|
|
if (prototype != null) {
|
2021-12-22 14:26:26 +01:00
|
|
|
skin = regionData.getPlainValueOrDefault("skin", prototype.getDefaultSkin());
|
2021-12-23 17:41:21 +01:00
|
|
|
if (!prototype.getSkinMap().containsKey(skin)) {
|
|
|
|
skin = prototype.getDefaultSkin();
|
|
|
|
}
|
2021-12-22 14:05:44 +01:00
|
|
|
}
|
2021-12-22 14:26:26 +01:00
|
|
|
regionData.add("skin", skin);
|
2021-04-19 19:54:38 +02:00
|
|
|
|
2021-04-19 20:01:38 +02:00
|
|
|
if (!hasType(RegionType.BUILD) || !hasType(RegionType.TESTBLOCK)) {
|
2021-04-19 19:54:38 +02:00
|
|
|
flagStorage.set(Flag.TNT, TNTMode.DENY);
|
|
|
|
}
|
2021-04-18 17:34:02 +02:00
|
|
|
}
|
|
|
|
|
2021-04-18 18:20:27 +02:00
|
|
|
private void generatePrototypeData(Prototype prototype, Point point) {
|
|
|
|
if (prototype == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-04-18 17:34:02 +02:00
|
|
|
this.prototype = prototype;
|
2021-12-22 14:05:44 +01:00
|
|
|
this.skin = prototype.getDefaultSkin();
|
2021-04-18 17:34:02 +02:00
|
|
|
|
2021-04-18 18:20:27 +02:00
|
|
|
this.minPoint = point;
|
2021-04-21 14:24:49 +02:00
|
|
|
this.maxPoint = point.add(prototype.getSizeX() - 1, prototype.getSizeY() - 1, prototype.getSizeZ() - 1);
|
2021-04-18 18:20:27 +02:00
|
|
|
|
2021-04-18 18:27:54 +02:00
|
|
|
if (prototype.getTestblock() != null) {
|
|
|
|
this.minPointTestblock = point.add(prototype.getTestblock().getOffsetX(), prototype.getTestblock().getOffsetY(), prototype.getTestblock().getOffsetZ());
|
2021-04-21 14:24:49 +02:00
|
|
|
this.maxPointTestblock = this.minPointTestblock.add(prototype.getTestblock().getSizeX() - 1, prototype.getTestblock().getSizeY() - 1, prototype.getTestblock().getSizeZ() - 1);
|
2021-04-18 18:20:27 +02:00
|
|
|
|
2021-05-02 20:13:47 +02:00
|
|
|
this.minPointTestblockExtension = this.minPointTestblock.subtract(prototype.getTestblock().getExtensionNegativeX(), prototype.getTestblock().getExtensionNegativeY(), prototype.getTestblock().getExtensionNegativeZ());
|
2021-05-02 12:05:15 +02:00
|
|
|
this.maxPointTestblockExtension = this.maxPointTestblock.add(prototype.getTestblock().getExtensionPositiveX(), prototype.getTestblock().getExtensionPositiveY(), prototype.getTestblock().getExtensionPositiveZ());
|
2021-11-09 20:18:09 +01:00
|
|
|
|
|
|
|
if (prototype.getTestblock().getCopyOffsetX() != 0 || prototype.getTestblock().getCopyOffsetY() != 0 || prototype.getTestblock().getCopyOffsetZ() != 0) {
|
|
|
|
this.testBlockPoint = this.minPointTestblock.add(prototype.getTestblock().getCopyOffsetX(), prototype.getTestblock().getCopyOffsetY(), prototype.getTestblock().getCopyOffsetZ());
|
|
|
|
} else {
|
|
|
|
this.testBlockPoint = this.minPointTestblock.add(prototype.getTestblock().getSizeX() / 2, 0, -1);
|
|
|
|
}
|
2021-04-18 18:27:54 +02:00
|
|
|
}
|
2021-04-18 18:20:27 +02:00
|
|
|
|
2021-04-18 18:27:54 +02:00
|
|
|
if (prototype.getBuild() != null) {
|
|
|
|
this.minPointBuild = point.add(prototype.getBuild().getOffsetX(), prototype.getBuild().getOffsetY(), prototype.getBuild().getOffsetZ());
|
2021-04-21 14:24:49 +02:00
|
|
|
this.maxPointBuild = this.minPointBuild.add(prototype.getBuild().getSizeX() - 1, prototype.getBuild().getSizeY() - 1, prototype.getBuild().getSizeZ() - 1);
|
2021-04-18 18:20:27 +02:00
|
|
|
|
2021-05-02 20:13:47 +02:00
|
|
|
this.minPointBuildExtension = this.minPointBuild.subtract(prototype.getBuild().getExtensionNegativeX(), prototype.getBuild().getExtensionNegativeY(), prototype.getBuild().getExtensionNegativeZ());
|
2021-05-02 12:05:15 +02:00
|
|
|
this.maxPointBuildExtension = this.maxPointBuild.add(prototype.getBuild().getExtensionPositiveX(), prototype.getBuild().getExtensionPositiveY(), prototype.getBuild().getExtensionPositiveZ());
|
2021-11-09 20:18:09 +01:00
|
|
|
|
2021-11-09 20:53:01 +01:00
|
|
|
if (!prototype.getBuild().isHasCopyPoint() && (prototype.getCopyPointOffsetX() != 0 || prototype.getCopyPointOffsetY() != 0 || prototype.getCopyPointOffsetZ() != 0)) {
|
2021-11-09 20:18:09 +01:00
|
|
|
this.copyPoint = minPoint.add(prototype.getCopyPointOffsetX(), prototype.getCopyPointOffsetY(), prototype.getCopyPointOffsetZ());
|
|
|
|
} else if (prototype.getBuild().getCopyOffsetX() != 0 || prototype.getBuild().getCopyOffsetY() != 0 || prototype.getBuild().getCopyOffsetZ() != 0) {
|
|
|
|
this.copyPoint = this.minPointBuild.add(prototype.getBuild().getCopyOffsetX(), prototype.getBuild().getCopyOffsetY(), prototype.getBuild().getCopyOffsetZ());
|
|
|
|
} else {
|
|
|
|
this.copyPoint = this.minPointBuild.add(prototype.getBuild().getSizeX() / 2, 0, prototype.getBuild().getSizeZ());
|
|
|
|
}
|
|
|
|
} else if (prototype.getCopyPointOffsetX() != 0 || prototype.getCopyPointOffsetY() != 0 || prototype.getCopyPointOffsetZ() != 0) {
|
|
|
|
this.copyPoint = minPoint.add(prototype.getCopyPointOffsetX(), prototype.getCopyPointOffsetY(), prototype.getCopyPointOffsetZ());
|
2021-04-18 18:27:54 +02:00
|
|
|
}
|
2021-04-19 17:32:16 +02:00
|
|
|
|
|
|
|
if (prototype.getFloorOffset() != 0) {
|
|
|
|
floorLevel = minPoint.getY() + prototype.getFloorOffset();
|
|
|
|
} else {
|
|
|
|
floorLevel = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prototype.getWaterOffset() != 0) {
|
|
|
|
waterLevel = minPoint.getY() + prototype.getWaterOffset();
|
|
|
|
} else {
|
|
|
|
waterLevel = 0;
|
|
|
|
}
|
2021-04-18 17:34:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean inRegion(Location location, RegionType regionType, RegionExtensionType regionExtensionType) {
|
2021-04-18 17:49:31 +02:00
|
|
|
if (!hasType(regionType)) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-04-18 17:42:46 +02:00
|
|
|
switch (regionType) {
|
|
|
|
case BUILD:
|
|
|
|
Point minBPoint = regionExtensionType == RegionExtensionType.EXTENSION ? minPointBuildExtension : minPointBuild;
|
|
|
|
Point maxBPoint = regionExtensionType == RegionExtensionType.EXTENSION ? maxPointBuildExtension : maxPointBuild;
|
|
|
|
return inRegion(location, minBPoint, maxBPoint);
|
|
|
|
case TESTBLOCK:
|
|
|
|
Point minTBPoint = regionExtensionType == RegionExtensionType.EXTENSION ? minPointTestblockExtension : minPointTestblock;
|
|
|
|
Point maxTBPoint = regionExtensionType == RegionExtensionType.EXTENSION ? maxPointTestblockExtension : maxPointTestblock;
|
|
|
|
return inRegion(location, minTBPoint, maxTBPoint);
|
|
|
|
default:
|
|
|
|
case NORMAL:
|
|
|
|
return inRegion(location, minPoint, maxPoint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean inRegion(Location location, Point minPoint, Point maxPoint) {
|
2021-05-07 10:48:12 +02:00
|
|
|
int blockX = location.getBlockX();
|
|
|
|
int blockY = location.getBlockY();
|
|
|
|
int blockZ = location.getBlockZ();
|
|
|
|
return blockX >= minPoint.getX() && blockX <= maxPoint.getX() &&
|
|
|
|
blockY >= minPoint.getY() && blockY <= maxPoint.getY() &&
|
|
|
|
blockZ >= minPoint.getZ() && blockZ <= maxPoint.getZ();
|
2021-04-18 17:42:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasType(RegionType regionType) {
|
2021-04-20 11:15:35 +02:00
|
|
|
if (prototype == null) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-04-20 11:36:39 +02:00
|
|
|
if (regionType == null) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-04-18 17:42:46 +02:00
|
|
|
switch (regionType) {
|
|
|
|
case BUILD:
|
2021-04-20 11:15:35 +02:00
|
|
|
return prototype.getBuild() != null;
|
2021-04-18 17:42:46 +02:00
|
|
|
case TESTBLOCK:
|
2021-04-20 11:15:35 +02:00
|
|
|
return prototype.getTestblock() != null;
|
2021-04-18 17:42:46 +02:00
|
|
|
default:
|
|
|
|
case NORMAL:
|
2021-04-20 11:15:35 +02:00
|
|
|
return true;
|
2021-04-18 17:42:46 +02:00
|
|
|
}
|
2021-04-18 17:34:02 +02:00
|
|
|
}
|
|
|
|
|
2021-04-20 08:20:53 +02:00
|
|
|
public boolean hasExtensionType(RegionType regionType) {
|
2021-04-20 11:18:57 +02:00
|
|
|
if (!hasType(regionType)) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-04-20 08:20:53 +02:00
|
|
|
switch (regionType) {
|
|
|
|
case BUILD:
|
2021-04-20 11:18:57 +02:00
|
|
|
return prototype.getBuild().isExtensionRegistered();
|
2021-04-20 08:20:53 +02:00
|
|
|
case TESTBLOCK:
|
2021-04-20 11:18:57 +02:00
|
|
|
return prototype.getTestblock().isExtensionRegistered();
|
2021-04-20 08:20:53 +02:00
|
|
|
default:
|
|
|
|
case NORMAL:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-18 17:49:31 +02:00
|
|
|
public String getDisplayName() {
|
2021-12-22 14:05:44 +01:00
|
|
|
return prototype != null ? prototype.getSkinMap().get(skin).getName() : "";
|
2021-04-18 17:49:31 +02:00
|
|
|
}
|
2021-04-18 18:37:32 +02:00
|
|
|
|
2021-04-19 20:33:15 +02:00
|
|
|
private void setLinkedRegion(Predicate<Region> regionConsumer) {
|
2021-04-18 19:00:19 +02:00
|
|
|
if (linkedRegionName == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (linkedRegion != null) {
|
2021-04-19 20:33:15 +02:00
|
|
|
if (regionConsumer.test(linkedRegion)) {
|
2021-04-20 13:46:51 +02:00
|
|
|
RegionUtils.save(linkedRegion);
|
2021-04-19 20:33:15 +02:00
|
|
|
}
|
2021-04-18 19:00:19 +02:00
|
|
|
return;
|
|
|
|
}
|
2021-05-03 16:58:01 +02:00
|
|
|
for (Region region : REGION_MAP.values()) {
|
2021-04-19 20:33:15 +02:00
|
|
|
if (region.name.equals(linkedRegionName)) {
|
2021-04-18 19:00:19 +02:00
|
|
|
linkedRegion = region;
|
2021-04-19 20:33:15 +02:00
|
|
|
if (regionConsumer.test(linkedRegion)) {
|
2021-04-20 13:46:51 +02:00
|
|
|
RegionUtils.save(linkedRegion);
|
2021-04-19 20:33:15 +02:00
|
|
|
}
|
2021-04-18 19:00:19 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-11 22:41:39 +01:00
|
|
|
public Region getLinkedRegion() {
|
|
|
|
if (linkedRegion == null && linkedRegionName != null) {
|
|
|
|
setLinkedRegion(region -> false);
|
|
|
|
}
|
|
|
|
return linkedRegion;
|
|
|
|
}
|
|
|
|
|
2021-07-04 20:49:44 +02:00
|
|
|
public boolean setPrototype(@NonNull Prototype prototype) {
|
2021-12-01 20:18:18 +01:00
|
|
|
if (!prototypes.contains(prototype.getName())) {
|
2021-07-04 20:49:44 +02:00
|
|
|
return false;
|
2021-04-19 20:33:15 +02:00
|
|
|
}
|
2021-11-09 20:18:09 +01:00
|
|
|
return _setPrototype(prototype);
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean _setPrototype(@NonNull Prototype prototype) {
|
2021-04-18 18:37:32 +02:00
|
|
|
generatePrototypeData(prototype, minPoint);
|
2021-04-20 13:46:51 +02:00
|
|
|
RegionUtils.save(this);
|
2021-07-04 20:49:44 +02:00
|
|
|
return true;
|
2021-04-18 18:37:32 +02:00
|
|
|
}
|
|
|
|
|
2021-12-22 14:05:44 +01:00
|
|
|
public boolean setSkin(@NonNull String skinName) {
|
|
|
|
if (!prototype.getSkinMap().containsKey(skinName)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
this.skin = skinName;
|
|
|
|
setLinkedRegion(region -> {
|
|
|
|
region.skin = skinName;
|
|
|
|
return true;
|
|
|
|
});
|
2021-12-22 14:26:26 +01:00
|
|
|
regionData.add("skin", skin);
|
2021-12-22 14:05:44 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-04-18 18:37:32 +02:00
|
|
|
public void set(Flag flagType, Flag.Value<?> value) {
|
|
|
|
if (flagStorage.set(flagType, value)) {
|
2021-04-20 13:46:51 +02:00
|
|
|
RegionUtils.save(this);
|
2021-04-18 18:37:32 +02:00
|
|
|
}
|
2021-04-19 20:33:15 +02:00
|
|
|
setLinkedRegion(region -> region.flagStorage.set(flagType, value));
|
2021-04-18 18:37:32 +02:00
|
|
|
}
|
|
|
|
|
2021-06-28 17:46:13 +02:00
|
|
|
public void set(Tag tag) {
|
|
|
|
if (flagStorage.set(tag)) {
|
|
|
|
RegionUtils.save(this);
|
|
|
|
}
|
|
|
|
setLinkedRegion(region -> region.flagStorage.set(tag));
|
|
|
|
}
|
|
|
|
|
2021-07-05 19:32:10 +02:00
|
|
|
public void remove(Tag tag) {
|
|
|
|
if (flagStorage.remove(tag)) {
|
|
|
|
RegionUtils.save(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-01 17:33:26 +02:00
|
|
|
public Flag.Value<?> get(Flag flagType) {
|
2021-04-18 18:37:32 +02:00
|
|
|
return flagStorage.get(flagType);
|
|
|
|
}
|
2021-04-18 18:53:58 +02:00
|
|
|
|
2021-07-05 19:32:10 +02:00
|
|
|
public boolean get(Tag tagType) {
|
|
|
|
return flagStorage.is(tagType);
|
|
|
|
}
|
|
|
|
|
2021-04-19 17:22:15 +02:00
|
|
|
public <T extends Enum<T> & Flag.Value<T>> T getPlain(Flag flagType) {
|
|
|
|
return (T) flagStorage.get(flagType).getValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T extends Enum<T> & Flag.Value<T>> T getPlain(Flag flagType, Class<T> type) {
|
|
|
|
return (T) flagStorage.get(flagType).getValue();
|
|
|
|
}
|
|
|
|
|
2021-04-20 08:20:53 +02:00
|
|
|
public Point getMinPoint(RegionType regionType, RegionExtensionType regionExtensionType) {
|
|
|
|
switch (regionType) {
|
|
|
|
case TESTBLOCK:
|
|
|
|
return (regionExtensionType == null || regionExtensionType == RegionExtensionType.NORMAL) ? minPointTestblock : minPointTestblockExtension;
|
|
|
|
case BUILD:
|
|
|
|
return (regionExtensionType == null || regionExtensionType == RegionExtensionType.NORMAL) ? minPointBuild : minPointBuildExtension;
|
|
|
|
default:
|
|
|
|
case NORMAL:
|
|
|
|
return minPoint;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Point getMaxPoint(RegionType regionType, RegionExtensionType regionExtensionType) {
|
|
|
|
switch (regionType) {
|
|
|
|
case TESTBLOCK:
|
|
|
|
return (regionExtensionType == null || regionExtensionType == RegionExtensionType.NORMAL) ? maxPointTestblock : maxPointTestblockExtension;
|
|
|
|
case BUILD:
|
|
|
|
return (regionExtensionType == null || regionExtensionType == RegionExtensionType.NORMAL) ? maxPointBuild : maxPointBuildExtension;
|
|
|
|
default:
|
|
|
|
case NORMAL:
|
|
|
|
return maxPoint;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-20 09:24:15 +02:00
|
|
|
boolean hasReset(RegionType regionType) {
|
2021-04-18 18:53:58 +02:00
|
|
|
if (!hasType(regionType)) {
|
2021-04-20 09:24:15 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
switch (regionType) {
|
|
|
|
case TESTBLOCK:
|
2021-12-22 14:05:44 +01:00
|
|
|
return prototype.getSkinMap().get(skin).getTestblockSchematicFile() != null;
|
2021-04-20 09:24:15 +02:00
|
|
|
case BUILD:
|
2021-12-22 14:05:44 +01:00
|
|
|
return prototype.getSkinMap().get(skin).getBuildSchematicFile() != null;
|
2021-04-20 09:24:15 +02:00
|
|
|
default:
|
|
|
|
case NORMAL:
|
2021-12-22 14:05:44 +01:00
|
|
|
return prototype.getSkinMap().get(skin).getSchematicFile() != null;
|
2021-04-20 09:24:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void reset(RegionType regionType) throws IOException {
|
|
|
|
reset(null, regionType);
|
|
|
|
}
|
|
|
|
|
2021-11-30 19:07:12 +01:00
|
|
|
public void reset(SchematicNode schematic, RegionType regionType) throws IOException {
|
2021-04-20 12:24:28 +02:00
|
|
|
reset(schematic, regionType, RegionExtensionType.NORMAL, false);
|
2021-04-20 09:24:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void reset(RegionType regionType, RegionExtensionType regionExtensionType) throws IOException {
|
2021-04-20 12:24:28 +02:00
|
|
|
reset(null, regionType, regionExtensionType, false);
|
2021-04-20 09:24:15 +02:00
|
|
|
}
|
|
|
|
|
2021-11-30 19:07:12 +01:00
|
|
|
public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType) throws IOException {
|
2021-04-20 13:48:17 +02:00
|
|
|
reset(schematic, regionType, regionExtensionType, false);
|
|
|
|
}
|
|
|
|
|
2021-07-10 18:12:30 +02:00
|
|
|
public void reset(File file) {
|
2021-08-01 22:01:25 +02:00
|
|
|
EditSession editSession = paste(file, minPoint.add(prototype.getSizeX() / 2, 0, prototype.getSizeZ() / 2), new PasteOptions(false, false, Color.YELLOW, false, false, getMinPoint(RegionType.NORMAL, RegionExtensionType.NORMAL), getMaxPoint(RegionType.NORMAL, RegionExtensionType.NORMAL), waterLevel));
|
2021-07-10 18:12:30 +02:00
|
|
|
initSessions();
|
|
|
|
undoSessions.push(editSession);
|
|
|
|
}
|
|
|
|
|
2021-11-30 19:07:12 +01:00
|
|
|
public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean ignoreAir) throws IOException {
|
2021-08-01 22:01:25 +02:00
|
|
|
reset(schematic, regionType, regionExtensionType, ignoreAir, false);
|
|
|
|
}
|
|
|
|
|
2021-11-30 19:07:12 +01:00
|
|
|
public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean ignoreAir, boolean onlyColors) throws IOException {
|
2021-04-20 09:24:15 +02:00
|
|
|
if (!hasReset(regionType)) {
|
2021-04-18 18:53:58 +02:00
|
|
|
return;
|
|
|
|
}
|
2021-04-20 09:24:15 +02:00
|
|
|
if (regionExtensionType == RegionExtensionType.EXTENSION && !hasExtensionType(regionType)) {
|
|
|
|
regionExtensionType = RegionExtensionType.NORMAL;
|
|
|
|
}
|
2021-04-20 12:24:28 +02:00
|
|
|
|
2021-11-30 19:07:12 +01:00
|
|
|
PasteOptions pasteOptions = new PasteOptions((schematic != null && (schematic.getSchemtype().fightType() || schematic.getSchemtype().check())), ignoreAir, getPlain(Flag.COLOR, ColorMode.class).getColor(), onlyColors, regionExtensionType == RegionExtensionType.EXTENSION, getMinPoint(regionType, regionExtensionType), getMaxPoint(regionType, regionExtensionType), waterLevel);
|
2021-04-20 12:24:28 +02:00
|
|
|
|
2021-04-21 14:13:01 +02:00
|
|
|
Point pastePoint;
|
|
|
|
File tempFile = null;
|
2021-09-18 14:23:52 +02:00
|
|
|
Clipboard clipboard = null;
|
2021-04-18 18:53:58 +02:00
|
|
|
switch (regionType) {
|
|
|
|
case BUILD:
|
2021-04-21 14:13:01 +02:00
|
|
|
pastePoint = minPointBuild.add(prototype.getBuild().getSizeX() / 2, 0, prototype.getBuild().getSizeZ() / 2);
|
|
|
|
if (schematic == null) {
|
2021-12-22 14:05:44 +01:00
|
|
|
tempFile = prototype.getSkinMap().get(skin).getBuildSchematicFile();
|
2021-04-20 12:24:28 +02:00
|
|
|
}
|
2021-04-20 11:01:19 +02:00
|
|
|
break;
|
2021-04-18 18:53:58 +02:00
|
|
|
case TESTBLOCK:
|
2021-09-18 14:23:52 +02:00
|
|
|
pastePoint = minPointTestblock.add(prototype.getTestblock().getSizeX() / 2, 0, 0);
|
2021-04-21 14:13:01 +02:00
|
|
|
if (schematic == null) {
|
2021-12-22 14:05:44 +01:00
|
|
|
tempFile = prototype.getSkinMap().get(skin).getTestblockSchematicFile();
|
2021-09-18 14:23:52 +02:00
|
|
|
pastePoint = pastePoint.add(0, 0, prototype.getTestblock().getSizeZ() / 2);
|
|
|
|
} else {
|
2022-09-24 20:39:09 +02:00
|
|
|
clipboard = new SchematicData(schematic).load();
|
2021-12-03 16:32:03 +01:00
|
|
|
int dz = Math.abs(clipboard.getOrigin().getZ() - clipboard.getMinimumPoint().getZ());
|
|
|
|
if (dz < 2 || dz > prototype.getTestblock().getSizeZ()) {
|
2021-09-19 21:37:50 +02:00
|
|
|
pastePoint = pastePoint.add(0, 0, prototype.getTestblock().getSizeZ() / 2);
|
2021-12-10 17:12:58 +01:00
|
|
|
} else if (clipboard.getDimensions().getZ() != prototype.getTestblock().getSizeZ()) {
|
2021-09-18 14:23:52 +02:00
|
|
|
pastePoint = pastePoint.add(0, 0, clipboard.getDimensions().getZ() / 2 - (clipboard.getOrigin().getZ() - clipboard.getMinimumPoint().getZ()) - 1);
|
|
|
|
} else {
|
|
|
|
pastePoint = pastePoint.add(0, 0, prototype.getTestblock().getSizeZ() / 2);
|
|
|
|
}
|
2021-12-27 16:40:16 +01:00
|
|
|
if (schematic.getSchemtype().getKuerzel().equalsIgnoreCase("wg")) {
|
2021-12-21 15:29:58 +01:00
|
|
|
pastePoint = pastePoint.add(0, 0, 1);
|
|
|
|
}
|
2021-04-20 12:24:28 +02:00
|
|
|
}
|
2021-04-20 11:01:19 +02:00
|
|
|
break;
|
2021-04-18 18:53:58 +02:00
|
|
|
default:
|
|
|
|
case NORMAL:
|
2021-04-21 14:13:01 +02:00
|
|
|
pastePoint = minPoint.add(prototype.getSizeX() / 2, 0, prototype.getSizeZ() / 2);
|
|
|
|
if (schematic == null) {
|
2021-12-22 14:05:44 +01:00
|
|
|
tempFile = prototype.getSkinMap().get(skin).getSchematicFile();
|
2021-04-20 12:24:28 +02:00
|
|
|
}
|
2021-04-20 11:01:19 +02:00
|
|
|
break;
|
2021-04-18 18:53:58 +02:00
|
|
|
}
|
2021-04-20 13:39:30 +02:00
|
|
|
|
2021-04-21 14:13:01 +02:00
|
|
|
EditSession editSession = null;
|
|
|
|
if (schematic != null) {
|
2022-09-24 20:39:09 +02:00
|
|
|
editSession = paste(clipboard != null ? clipboard : new SchematicData(schematic).load(), pastePoint, pasteOptions);
|
2021-04-21 14:13:01 +02:00
|
|
|
} else {
|
|
|
|
editSession = paste(tempFile, pastePoint, pasteOptions);
|
|
|
|
}
|
|
|
|
|
2021-04-20 13:39:30 +02:00
|
|
|
initSessions();
|
|
|
|
undoSessions.push(editSession);
|
2021-04-18 18:53:58 +02:00
|
|
|
}
|
|
|
|
|
2021-04-20 08:20:53 +02:00
|
|
|
public boolean isGlobal() {
|
|
|
|
return this == GlobalRegion.getInstance();
|
|
|
|
}
|
|
|
|
|
2021-04-20 13:39:30 +02:00
|
|
|
private void initSessions() {
|
|
|
|
if (undoSessions == null) {
|
|
|
|
undoSessions = new SizedStack<>(20);
|
|
|
|
redoSessions = new SizedStack<>(20);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean undo() {
|
|
|
|
initSessions();
|
2022-08-05 12:22:11 +02:00
|
|
|
EditSession session = undoSessions.pop();
|
|
|
|
if (session == null)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) {
|
|
|
|
session.undo(e);
|
|
|
|
redoSessions.push(e);
|
2021-04-20 13:39:30 +02:00
|
|
|
}
|
2022-08-05 12:22:11 +02:00
|
|
|
return true;
|
2021-04-20 13:39:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean redo() {
|
|
|
|
initSessions();
|
2022-08-05 12:32:06 +02:00
|
|
|
EditSession session = redoSessions.pop();
|
|
|
|
if (session == null)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) {
|
|
|
|
session.redo(e);
|
|
|
|
undoSessions.push(e);
|
2021-04-20 13:39:30 +02:00
|
|
|
}
|
2022-08-05 12:32:06 +02:00
|
|
|
return true;
|
2021-04-20 13:39:30 +02:00
|
|
|
}
|
|
|
|
|
2021-07-05 19:32:10 +02:00
|
|
|
public boolean backup() {
|
|
|
|
final File definedBackupFolder = new File(new File(backupFolder, prototype.getName()), name);
|
|
|
|
//noinspection ResultOfMethodCallIgnored
|
|
|
|
definedBackupFolder.mkdirs();
|
2021-07-10 17:46:30 +02:00
|
|
|
|
|
|
|
File[] currentBackups = definedBackupFolder.listFiles();
|
2021-08-05 17:24:58 +02:00
|
|
|
if (currentBackups != null && currentBackups.length >= 20) {
|
2021-07-10 17:46:30 +02:00
|
|
|
List<File> files = new ArrayList<>(Arrays.asList(currentBackups));
|
|
|
|
files.sort(Comparator.comparingLong(File::lastModified));
|
|
|
|
while (files.size() >= 20) files.remove(0).delete();
|
|
|
|
}
|
|
|
|
|
2021-07-05 19:32:10 +02:00
|
|
|
final File backupFile = new File(definedBackupFolder, LocalDateTime.now().format(formatter) + ".schem");
|
2022-01-29 15:28:28 +01:00
|
|
|
return FlatteningWrapper.impl.backup(minPoint, maxPoint, backupFile);
|
2021-07-05 19:32:10 +02:00
|
|
|
}
|
2021-07-06 11:34:02 +02:00
|
|
|
|
2021-12-23 15:52:29 +01:00
|
|
|
public static boolean copy(Point minPoint, Point maxPoint, File file) {
|
2022-01-29 15:28:28 +01:00
|
|
|
return FlatteningWrapper.impl.backup(minPoint, maxPoint, file);
|
2021-12-23 15:52:29 +01:00
|
|
|
}
|
|
|
|
|
2021-07-06 11:34:02 +02:00
|
|
|
public List<String> listBackup() {
|
|
|
|
final File definedBackupFolder = new File(new File(backupFolder, prototype.getName()), name);
|
|
|
|
//noinspection ResultOfMethodCallIgnored
|
|
|
|
definedBackupFolder.mkdirs();
|
2021-08-05 17:24:58 +02:00
|
|
|
|
|
|
|
File[] currentBackups = definedBackupFolder.listFiles();
|
|
|
|
List<File> files = new ArrayList<>(Arrays.asList(currentBackups));
|
|
|
|
files.sort(Comparator.comparingLong(File::lastModified));
|
|
|
|
return files.stream().map(File::getName).collect(Collectors.toList());
|
2021-07-06 11:34:02 +02:00
|
|
|
}
|
2021-07-10 18:12:30 +02:00
|
|
|
|
|
|
|
public File getBackupFile(String backupName) {
|
|
|
|
final File definedBackupFolder = new File(new File(backupFolder, prototype.getName()), name);
|
|
|
|
//noinspection ResultOfMethodCallIgnored
|
|
|
|
definedBackupFolder.mkdirs();
|
|
|
|
File[] files = definedBackupFolder.listFiles((dir, name) -> name.equals(backupName + ".schem"));
|
|
|
|
if (files == null || files.length == 0) return null;
|
|
|
|
return files[0];
|
|
|
|
}
|
2022-07-29 22:36:41 +02:00
|
|
|
|
|
|
|
public void forEachChunk(ObjIntConsumer<Integer> executor) {
|
|
|
|
for (int x = (int) Math.floor(minPoint.getX() / 16.0); x <= (int) Math.ceil(maxPoint.getX() / 16.0); x++) {
|
|
|
|
for (int z = (int) Math.floor(minPoint.getZ() / 16.0); z <= (int) Math.ceil(maxPoint.getZ() / 16.0); z++) {
|
|
|
|
executor.accept(x, z);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-28 17:15:39 +02:00
|
|
|
public boolean buildChunkOutside(int chunkX, int chunkY) {
|
|
|
|
if (!hasType(RegionType.BUILD)) {
|
|
|
|
return Math.floor(minPoint.getX() / 16.0) > chunkX || chunkX >= Math.ceil(maxPoint.getX() / 16.0) ||
|
|
|
|
Math.floor(minPoint.getZ() / 16.0) > chunkY || chunkY >= Math.ceil(maxPoint.getZ() / 16.0);
|
|
|
|
}
|
|
|
|
if (!hasExtensionType(RegionType.BUILD)) {
|
|
|
|
return Math.floor(minPointBuild.getX() / 16.0) > chunkX || chunkX >= Math.ceil(maxPointBuild.getX() / 16.0) ||
|
|
|
|
Math.floor(minPointBuild.getZ() / 16.0) > chunkY || chunkY >= Math.ceil(maxPointBuild.getZ() / 16.0);
|
|
|
|
}
|
|
|
|
return Math.floor(minPointBuildExtension.getX() / 16.0) > chunkX || chunkX >= Math.ceil(maxPointBuildExtension.getX() / 16.0) ||
|
|
|
|
Math.floor(minPointBuildExtension.getZ() / 16.0) > chunkY || chunkY >= Math.ceil(maxPointBuildExtension.getZ() / 16.0);
|
2022-07-29 22:36:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public File gameModeConfig() {
|
|
|
|
File baseFile = new File(BauSystem.getInstance().getDataFolder().getParentFile(), "FightSystem");
|
2022-07-29 23:30:22 +02:00
|
|
|
for (int version = Core.getVersion(); version >= 15; version--) {
|
2022-10-02 17:02:45 +02:00
|
|
|
File specific = new File(baseFile, prototype.getDisplayName() + version + ".yml");
|
2022-07-29 22:36:41 +02:00
|
|
|
if (specific.exists()) return specific;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2021-04-18 18:20:27 +02:00
|
|
|
}
|