forked from SteamWar/SteamWar
Add BauSystem module
Fix ci java version Fix LinkageProcessor
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.region.tags.Tag;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.linkage.api.Enable;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
|
||||
@Linked
|
||||
public class BackupScheduler implements Enable {
|
||||
|
||||
private static final long INITIAL = 20 * 60 * 5;
|
||||
private static final long PERIOD = 20 * 60 * 30;
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final Iterator<Region> regions = Region.getREGION_MAP().values().stream().filter(region -> region.get(Tag.CHANGED)).iterator();
|
||||
BackupScheduler.this.doBackup(regions);
|
||||
}
|
||||
}.runTaskTimer(BauSystem.getInstance(), INITIAL, PERIOD);
|
||||
}
|
||||
|
||||
public void doBackup(final Iterator<Region> regionIterator) {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!regionIterator.hasNext()) {
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
final Region region = regionIterator.next();
|
||||
if (region.backup()) {
|
||||
region.remove(Tag.CHANGED);
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(BauSystem.getInstance(), 0, 20 * 60);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
public enum Color {
|
||||
WHITE,
|
||||
ORANGE,
|
||||
MAGENTA,
|
||||
LIGHT_BLUE,
|
||||
YELLOW,
|
||||
LIME,
|
||||
PINK,
|
||||
GRAY,
|
||||
LIGHT_GRAY,
|
||||
CYAN,
|
||||
PURPLE,
|
||||
BLUE,
|
||||
BROWN,
|
||||
GREEN,
|
||||
RED,
|
||||
BLACK;
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import de.steamwar.bausystem.region.tags.Tag;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Tags and Flags are not allowed to have overlaping names.
|
||||
*/
|
||||
public class FlagStorage {
|
||||
|
||||
public static FlagStorage createStorage(YAPIONObject yapionObject) {
|
||||
FlagStorage flagStorage = new FlagStorage();
|
||||
for (final Flag flag : Flag.getFlags()) {
|
||||
try {
|
||||
String s = yapionObject.getPlainValue(flag.name());
|
||||
flagStorage.set(flag, flag.getFlagValueOf(s));
|
||||
} catch (Exception e) {
|
||||
flagStorage.set(flag, flag.getDefaultValue());
|
||||
}
|
||||
}
|
||||
for (final Tag tag : Tag.values()) {
|
||||
if (yapionObject.containsKey(tag.name())) {
|
||||
flagStorage.set(tag);
|
||||
}
|
||||
}
|
||||
return flagStorage;
|
||||
}
|
||||
|
||||
public static YAPIONObject toYAPION(FlagStorage flagStorage) {
|
||||
YAPIONObject yapionObject = new YAPIONObject();
|
||||
for (final Flag flag : Flag.getFlags()) {
|
||||
if (flag.getDefaultValue() == flagStorage.flags.getOrDefault(flag, flag.getDefaultValue())) {
|
||||
yapionObject.remove(flag.name());
|
||||
} else {
|
||||
yapionObject.add(flag.name(), flagStorage.get(flag).getValue().name());
|
||||
}
|
||||
}
|
||||
for (Tag tag : Tag.values()) {
|
||||
if (flagStorage.tagSet.contains(tag)) {
|
||||
yapionObject.add(tag.name(), "");
|
||||
} else {
|
||||
yapionObject.remove(tag.name());
|
||||
}
|
||||
}
|
||||
return yapionObject;
|
||||
}
|
||||
|
||||
protected Map<Flag, Flag.Value<?>> flags;
|
||||
protected Set<Tag> tagSet;
|
||||
|
||||
public FlagStorage() {
|
||||
flags = new EnumMap<>(Flag.class);
|
||||
tagSet = new HashSet<>();
|
||||
readKeys();
|
||||
}
|
||||
|
||||
public boolean set(final Flag flagType, final Flag.Value<?> value) {
|
||||
return flags.put(flagType, value) != value;
|
||||
}
|
||||
|
||||
public Flag.Value<?> get(final Flag flagType) {
|
||||
return flags.getOrDefault(flagType, flagType.getDefaultValue());
|
||||
}
|
||||
|
||||
public boolean set(final Tag tag) {
|
||||
return tagSet.add(tag);
|
||||
}
|
||||
|
||||
public boolean remove(final Tag tag) {
|
||||
return tagSet.remove(tag);
|
||||
}
|
||||
|
||||
public boolean is(final Tag tag) {
|
||||
return tagSet.contains(tag);
|
||||
}
|
||||
|
||||
private void readKeys() {
|
||||
for (final Flag flag : Flag.getFlags()) {
|
||||
flags.put(flag, flag.getDefaultValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
||||
import de.steamwar.bausystem.region.utils.RegionType;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Location;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
|
||||
public class GlobalRegion extends Region {
|
||||
|
||||
@Getter
|
||||
static GlobalRegion instance;
|
||||
|
||||
public GlobalRegion(FlagStorage flagStorage, YAPIONObject regionData) {
|
||||
super("global", null, new YAPIONObject(), flagStorage, regionData);
|
||||
instance = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inRegion(Location location, RegionType regionType, RegionExtensionType regionExtensionType) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
@AllArgsConstructor
|
||||
public class Point {
|
||||
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
|
||||
public static Point fromLocation(final Location location) {
|
||||
return new Point(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
}
|
||||
|
||||
public static Point fromBlockVector3(final BlockVector3 blockVector3) {
|
||||
return new Point(blockVector3.getBlockX(), blockVector3.getBlockY(), blockVector3.getBlockZ());
|
||||
}
|
||||
|
||||
public Point add(int x, int y, int z) {
|
||||
return new Point(this.x + x, this.y + y, this.z + z);
|
||||
}
|
||||
|
||||
public Point subtract(int x, int y, int z) {
|
||||
return new Point(this.x - x, this.y - y, this.z - z);
|
||||
}
|
||||
|
||||
public Point divide(int factor) {
|
||||
return new Point(x / factor, y / factor, z / factor);
|
||||
}
|
||||
|
||||
public Location toLocation(World world) {
|
||||
return new Location(world, x, y, z);
|
||||
}
|
||||
|
||||
public Location toLocation(World world, double dx, double dy, double dz) {
|
||||
return new Location(world, x + dx, y + dy, z + dz);
|
||||
}
|
||||
|
||||
public Location toLocation(Player player) {
|
||||
return new Location(player.getWorld(), x, y, z, player.getLocation().getYaw(), player.getLocation().getPitch());
|
||||
}
|
||||
|
||||
public Location toLocation(Player player, double dx, double dy, double dz) {
|
||||
return new Location(player.getWorld(), x + dx, y + dy, z + dz, player.getLocation().getYaw(), player.getLocation().getPitch());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
import yapion.hierarchy.types.YAPIONType;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
public class Prototype {
|
||||
|
||||
static final Map<String, Prototype> PROTOTYPE_MAP = new HashMap<>();
|
||||
|
||||
public static Prototype getByName(String name) {
|
||||
return PROTOTYPE_MAP.get(name);
|
||||
}
|
||||
|
||||
public static Prototype getByDisplayName(String name) {
|
||||
return PROTOTYPE_MAP.values().stream().filter(prototype -> prototype.getDisplayName().equals(name)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public static List<Prototype> getPrototypes() {
|
||||
return new ArrayList<>(PROTOTYPE_MAP.values());
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public static class Skin {
|
||||
private final String name;
|
||||
private final String creator; // Nullable
|
||||
private final File schematicFile;
|
||||
private final File testblockSchematicFile; // Nullable
|
||||
private final File buildSchematicFile; // Nullable
|
||||
}
|
||||
|
||||
private final String name;
|
||||
private final String displayName;
|
||||
private final String defaultSkin;
|
||||
private final Map<String, Skin> skinMap = new HashMap<>();
|
||||
|
||||
private final int sizeX;
|
||||
private final int sizeY;
|
||||
private final int sizeZ;
|
||||
|
||||
private final int floorOffset;
|
||||
private final int waterOffset;
|
||||
|
||||
private final SubPrototype testblock; // Nullable
|
||||
private final SubPrototype build; // Nullable
|
||||
|
||||
private final int copyPointOffsetX;
|
||||
private final int copyPointOffsetY;
|
||||
private final int copyPointOffsetZ;
|
||||
|
||||
public Prototype(String name, YAPIONObject yapionObject) {
|
||||
this.name = name;
|
||||
displayName = yapionObject.getPlainValueOrDefault("displayName", name);
|
||||
|
||||
sizeX = yapionObject.getPlainValue("sizeX");
|
||||
sizeY = yapionObject.getPlainValue("sizeY");
|
||||
sizeZ = yapionObject.getPlainValue("sizeZ");
|
||||
|
||||
copyPointOffsetX = yapionObject.getPlainValueOrDefault("copyOffsetX", 0);
|
||||
copyPointOffsetY = yapionObject.getPlainValueOrDefault("copyOffsetY", 0);
|
||||
copyPointOffsetZ = yapionObject.getPlainValueOrDefault("copyOffsetZ", 0);
|
||||
|
||||
floorOffset = yapionObject.getPlainValueOrDefault("floorOffset", 0);
|
||||
waterOffset = yapionObject.getPlainValueOrDefault("waterOffset", 0);
|
||||
|
||||
if (yapionObject.containsKey("testblock", YAPIONType.OBJECT)) {
|
||||
testblock = new SubPrototype(yapionObject.getObject("testblock"));
|
||||
} else {
|
||||
testblock = null;
|
||||
}
|
||||
if (yapionObject.containsKey("build", YAPIONType.OBJECT)) {
|
||||
build = new SubPrototype(yapionObject.getObject("build"));
|
||||
} else {
|
||||
build = null;
|
||||
}
|
||||
|
||||
this.defaultSkin = yapionObject.getPlainValueOrDefault("defaultSkin", displayName);
|
||||
if (yapionObject.containsKey("skins", YAPIONType.ARRAY)) {
|
||||
yapionObject.getArray("skins").forEach(yapionAnyType -> {
|
||||
YAPIONObject skinObject = (YAPIONObject) yapionAnyType;
|
||||
String skinName = skinObject.getPlainValue("name");
|
||||
String skinCreator = skinObject.getPlainValueOrDefault("creator", null);
|
||||
String schematicFileName = skinObject.getPlainValue("schematic");
|
||||
String testblockSchematicFileName = skinObject.getPlainValueOrDefault("testblockSchematic", null);
|
||||
String buildSchematicFileName = skinObject.getPlainValueOrDefault("buildSchematic", null);
|
||||
boolean disabled = skinObject.getPlainValueOrDefault("disabled", false);
|
||||
if (disabled) {
|
||||
return;
|
||||
}
|
||||
skinMap.put(skinName, new Skin(skinName, skinCreator, new File(schematicFileName), testblockSchematicFileName == null ? null : new File(testblockSchematicFileName), buildSchematicFileName == null ? null : new File(buildSchematicFileName)));
|
||||
});
|
||||
} else {
|
||||
String s = yapionObject.getPlainValueOrDefault("schematic", null);
|
||||
File schematicFile = s == null ? null : new File(s);
|
||||
File testblockSchematicFile = testblock != null ? testblock.getSchematicFile() : null;
|
||||
File buildSchematicFile = build != null ? build.getSchematicFile() : null;
|
||||
skinMap.put(displayName, new Skin(defaultSkin, null, schematicFile, testblockSchematicFile, buildSchematicFile));
|
||||
}
|
||||
|
||||
if (PROTOTYPE_MAP.containsKey(name)) {
|
||||
Region.getRegion(PROTOTYPE_MAP.remove(name)).forEach(region -> {
|
||||
region._setPrototype(this);
|
||||
});
|
||||
}
|
||||
PROTOTYPE_MAP.put(name, this);
|
||||
}
|
||||
|
||||
@Getter
|
||||
public static class SubPrototype {
|
||||
|
||||
private final int offsetX;
|
||||
private final int offsetY;
|
||||
private final int offsetZ;
|
||||
|
||||
private final int sizeX;
|
||||
private final int sizeY;
|
||||
private final int sizeZ;
|
||||
|
||||
private final File schematicFile; // Nullable
|
||||
|
||||
private final int extensionNegativeX;
|
||||
private final int extensionPositiveX;
|
||||
private final int extensionNegativeY;
|
||||
private final int extensionPositiveY;
|
||||
private final int extensionNegativeZ;
|
||||
private final int extensionPositiveZ;
|
||||
|
||||
private boolean extensionRegistered;
|
||||
|
||||
private final boolean hasCopyPoint;
|
||||
private final int copyOffsetX;
|
||||
private final int copyOffsetY;
|
||||
private final int copyOffsetZ;
|
||||
|
||||
private SubPrototype(YAPIONObject yapionObject) {
|
||||
offsetX = yapionObject.getPlainValueOrDefault("offsetX", 0);
|
||||
offsetY = yapionObject.getPlainValueOrDefault("offsetY", 0);
|
||||
offsetZ = yapionObject.getPlainValueOrDefault("offsetZ", 0);
|
||||
|
||||
sizeX = yapionObject.getPlainValue("sizeX");
|
||||
sizeY = yapionObject.getPlainValue("sizeY");
|
||||
sizeZ = yapionObject.getPlainValue("sizeZ");
|
||||
|
||||
if (yapionObject.containsKey("schematic", String.class)) {
|
||||
schematicFile = new File(yapionObject.getValue("schematic", String.class).get());
|
||||
} else {
|
||||
schematicFile = null;
|
||||
}
|
||||
|
||||
if (yapionObject.containsKey("extensionX", Integer.class)) {
|
||||
extensionNegativeX = yapionObject.getPlainValue("extensionX");
|
||||
extensionPositiveX = yapionObject.getPlainValue("extensionX");
|
||||
} else {
|
||||
extensionNegativeX = yapionObject.getPlainValueOrDefault("extensionNegativeX", 0);
|
||||
extensionPositiveX = yapionObject.getPlainValueOrDefault("extensionPositiveX", 0);
|
||||
}
|
||||
|
||||
if (yapionObject.containsKey("extensionY", Integer.class)) {
|
||||
extensionNegativeY = yapionObject.getPlainValue("extensionY");
|
||||
extensionPositiveY = yapionObject.getPlainValue("extensionY");
|
||||
} else {
|
||||
extensionNegativeY = yapionObject.getPlainValueOrDefault("extensionNegativeY", 0);
|
||||
extensionPositiveY = yapionObject.getPlainValueOrDefault("extensionPositiveY", 0);
|
||||
}
|
||||
|
||||
if (yapionObject.containsKey("extensionZ", Integer.class)) {
|
||||
extensionNegativeZ = yapionObject.getPlainValue("extensionZ");
|
||||
extensionPositiveZ = yapionObject.getPlainValue("extensionZ");
|
||||
} else {
|
||||
extensionNegativeZ = yapionObject.getPlainValueOrDefault("extensionNegativeZ", 0);
|
||||
extensionPositiveZ = yapionObject.getPlainValueOrDefault("extensionPositiveZ", 0);
|
||||
}
|
||||
|
||||
extensionRegistered = extensionNegativeX != 0 || extensionPositiveX != 0 || extensionNegativeY != 0 || extensionPositiveY != 0 || extensionNegativeZ != 0 || extensionPositiveZ != 0;
|
||||
|
||||
copyOffsetX = yapionObject.getPlainValueOrDefault("copyOffsetX", 0);
|
||||
copyOffsetY = yapionObject.getPlainValueOrDefault("copyOffsetY", 0);
|
||||
copyOffsetZ = yapionObject.getPlainValueOrDefault("copyOffsetZ", 0);
|
||||
hasCopyPoint = yapionObject.containsKey("copyOffsetX") || yapionObject.containsKey("copyOffsetY") || yapionObject.containsKey("copyOffsetZ");
|
||||
}
|
||||
}
|
||||
|
||||
public static Region generateRegion(String name, YAPIONObject regionConfig, YAPIONObject regionData) {
|
||||
Prototype prototype;
|
||||
if (regionData.containsKey("prototype", String.class)) {
|
||||
prototype = PROTOTYPE_MAP.get(regionData.getPlainValue("prototype"));
|
||||
} else {
|
||||
prototype = PROTOTYPE_MAP.get(regionConfig.getPlainValue("prototype"));
|
||||
}
|
||||
FlagStorage flagStorage;
|
||||
if (regionData.containsKey("flagStorage", YAPIONType.OBJECT)) {
|
||||
flagStorage = FlagStorage.createStorage(regionData.getObject("flagStorage"));
|
||||
} else {
|
||||
flagStorage = new FlagStorage();
|
||||
}
|
||||
return new Region(name, prototype, regionConfig, flagStorage, regionData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,584 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import de.steamwar.bausystem.region.flags.flagvalues.TNTMode;
|
||||
import de.steamwar.bausystem.region.tags.Tag;
|
||||
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
||||
import de.steamwar.bausystem.region.utils.RegionType;
|
||||
import de.steamwar.bausystem.shared.SizedStack;
|
||||
import de.steamwar.bausystem.utils.FlatteningWrapper;
|
||||
import de.steamwar.bausystem.utils.PasteBuilder;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.sql.SchematicType;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
import yapion.hierarchy.types.YAPIONType;
|
||||
import yapion.hierarchy.types.YAPIONValue;
|
||||
|
||||
import java.io.File;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.function.ObjIntConsumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
public class Region {
|
||||
|
||||
@Getter
|
||||
private static final Map<String, Region> REGION_MAP = new HashMap<>();
|
||||
private static final File backupFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "backup");
|
||||
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy.MM.dd' 'HH:mm:ss");
|
||||
|
||||
public static Region getRegion(Location location) {
|
||||
return REGION_MAP.values().stream()
|
||||
.filter(r -> r.inRegion(location, r.minPoint, r.maxPoint))
|
||||
.findFirst()
|
||||
.orElse(GlobalRegion.instance);
|
||||
}
|
||||
|
||||
public static Set<Region> getRegion(Prototype prototype) {
|
||||
return REGION_MAP.values().stream()
|
||||
.filter(r -> r.getPrototype() == prototype)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
public static void setGlobal(Flag flagType, Flag.Value<?> value) {
|
||||
REGION_MAP.values().forEach(region -> region.set(flagType, value));
|
||||
}
|
||||
|
||||
YAPIONObject regionData;
|
||||
|
||||
private String name;
|
||||
private Prototype prototype;
|
||||
private Set<String> prototypes;
|
||||
private String skin;
|
||||
|
||||
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;
|
||||
|
||||
private int floorLevel;
|
||||
private int waterLevel;
|
||||
|
||||
private Point copyPoint; // Nullable
|
||||
private Point testBlockPoint; // Nullable
|
||||
|
||||
private String linkedRegionName = null; // Nullable
|
||||
private Region linkedRegion = null; // Nullable
|
||||
|
||||
private FlagStorage flagStorage;
|
||||
|
||||
@Getter(AccessLevel.PRIVATE)
|
||||
private SizedStack<EditSession> undoSessions;
|
||||
|
||||
@Getter(AccessLevel.PRIVATE)
|
||||
private SizedStack<EditSession> redoSessions;
|
||||
|
||||
public Region(String name, Prototype prototype, YAPIONObject regionConfig, FlagStorage flagStorage, YAPIONObject regionData) {
|
||||
this.name = name;
|
||||
this.regionData = regionData;
|
||||
if (prototype != null) {
|
||||
REGION_MAP.put(name, this);
|
||||
}
|
||||
|
||||
linkedRegionName = regionConfig.getPlainValueOrDefault("optionsLinkedWith", null);
|
||||
|
||||
prototypes = new HashSet<>();
|
||||
if (regionConfig.containsKey("prototypes", YAPIONType.ARRAY)) {
|
||||
regionConfig.getArray("prototypes").forEach(yapionAnyType -> {
|
||||
if (yapionAnyType instanceof YAPIONValue) {
|
||||
prototypes.add(((YAPIONValue<String>) yapionAnyType).get());
|
||||
}
|
||||
});
|
||||
}
|
||||
if (regionConfig.containsKey("prototype")) {
|
||||
prototypes.add(regionConfig.getPlainValue("prototype"));
|
||||
}
|
||||
|
||||
this.flagStorage = flagStorage;
|
||||
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"));
|
||||
}
|
||||
if (prototype != null && prototypes.contains(prototype.getName())) {
|
||||
generatePrototypeData(prototype, point);
|
||||
} else if (regionConfig.containsKey("prototype")) {
|
||||
generatePrototypeData(Prototype.getByName(regionConfig.getPlainValue("prototype")), point);
|
||||
}
|
||||
if (prototype != null) {
|
||||
skin = regionData.getPlainValueOrDefault("skin", prototype.getDefaultSkin());
|
||||
if (!prototype.getSkinMap().containsKey(skin)) {
|
||||
skin = prototype.getDefaultSkin();
|
||||
}
|
||||
}
|
||||
regionData.add("skin", skin);
|
||||
|
||||
if (!hasType(RegionType.BUILD) || !hasType(RegionType.TESTBLOCK)) {
|
||||
flagStorage.set(Flag.TNT, TNTMode.DENY);
|
||||
}
|
||||
}
|
||||
|
||||
private void generatePrototypeData(Prototype prototype, Point point) {
|
||||
if (prototype == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.prototype = prototype;
|
||||
this.skin = prototype.getDefaultSkin();
|
||||
|
||||
this.minPoint = point;
|
||||
this.maxPoint = point.add(prototype.getSizeX() - 1, prototype.getSizeY() - 1, prototype.getSizeZ() - 1);
|
||||
|
||||
if (prototype.getTestblock() != null) {
|
||||
this.minPointTestblock = point.add(prototype.getTestblock().getOffsetX(), prototype.getTestblock().getOffsetY(), prototype.getTestblock().getOffsetZ());
|
||||
this.maxPointTestblock = this.minPointTestblock.add(prototype.getTestblock().getSizeX() - 1, prototype.getTestblock().getSizeY() - 1, prototype.getTestblock().getSizeZ() - 1);
|
||||
|
||||
this.minPointTestblockExtension = this.minPointTestblock.subtract(prototype.getTestblock().getExtensionNegativeX(), prototype.getTestblock().getExtensionNegativeY(), prototype.getTestblock().getExtensionNegativeZ());
|
||||
this.maxPointTestblockExtension = this.maxPointTestblock.add(prototype.getTestblock().getExtensionPositiveX(), prototype.getTestblock().getExtensionPositiveY(), prototype.getTestblock().getExtensionPositiveZ());
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
if (prototype.getBuild() != null) {
|
||||
this.minPointBuild = point.add(prototype.getBuild().getOffsetX(), prototype.getBuild().getOffsetY(), prototype.getBuild().getOffsetZ());
|
||||
this.maxPointBuild = this.minPointBuild.add(prototype.getBuild().getSizeX() - 1, prototype.getBuild().getSizeY() - 1, prototype.getBuild().getSizeZ() - 1);
|
||||
|
||||
this.minPointBuildExtension = this.minPointBuild.subtract(prototype.getBuild().getExtensionNegativeX(), prototype.getBuild().getExtensionNegativeY(), prototype.getBuild().getExtensionNegativeZ());
|
||||
this.maxPointBuildExtension = this.maxPointBuild.add(prototype.getBuild().getExtensionPositiveX(), prototype.getBuild().getExtensionPositiveY(), prototype.getBuild().getExtensionPositiveZ());
|
||||
|
||||
if (!prototype.getBuild().isHasCopyPoint() && (prototype.getCopyPointOffsetX() != 0 || prototype.getCopyPointOffsetY() != 0 || prototype.getCopyPointOffsetZ() != 0)) {
|
||||
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());
|
||||
}
|
||||
|
||||
if (prototype.getFloorOffset() != 0) {
|
||||
floorLevel = minPoint.getY() + prototype.getFloorOffset();
|
||||
} else {
|
||||
floorLevel = 0;
|
||||
}
|
||||
|
||||
if (prototype.getWaterOffset() != 0) {
|
||||
waterLevel = minPoint.getY() + prototype.getWaterOffset();
|
||||
} else {
|
||||
waterLevel = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean inRegion(Location location, RegionType regionType, RegionExtensionType regionExtensionType) {
|
||||
if (!hasType(regionType)) {
|
||||
return false;
|
||||
}
|
||||
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) {
|
||||
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();
|
||||
}
|
||||
|
||||
public boolean hasType(RegionType regionType) {
|
||||
if (prototype == null) {
|
||||
return false;
|
||||
}
|
||||
if (regionType == null) {
|
||||
return false;
|
||||
}
|
||||
switch (regionType) {
|
||||
case BUILD:
|
||||
return prototype.getBuild() != null;
|
||||
case TESTBLOCK:
|
||||
return prototype.getTestblock() != null;
|
||||
default:
|
||||
case NORMAL:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasExtensionType(RegionType regionType) {
|
||||
if (!hasType(regionType)) {
|
||||
return false;
|
||||
}
|
||||
switch (regionType) {
|
||||
case BUILD:
|
||||
return prototype.getBuild().isExtensionRegistered();
|
||||
case TESTBLOCK:
|
||||
return prototype.getTestblock().isExtensionRegistered();
|
||||
default:
|
||||
case NORMAL:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return prototype != null ? prototype.getSkinMap().get(skin).getName() : "";
|
||||
}
|
||||
|
||||
private void setLinkedRegion(Predicate<Region> regionConsumer) {
|
||||
if (linkedRegionName == null) {
|
||||
return;
|
||||
}
|
||||
if (linkedRegion != null) {
|
||||
if (regionConsumer.test(linkedRegion)) {
|
||||
RegionUtils.save(linkedRegion);
|
||||
}
|
||||
return;
|
||||
}
|
||||
for (Region region : REGION_MAP.values()) {
|
||||
if (region.name.equals(linkedRegionName)) {
|
||||
linkedRegion = region;
|
||||
if (regionConsumer.test(linkedRegion)) {
|
||||
RegionUtils.save(linkedRegion);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Region getLinkedRegion() {
|
||||
if (linkedRegion == null && linkedRegionName != null) {
|
||||
setLinkedRegion(region -> false);
|
||||
}
|
||||
return linkedRegion;
|
||||
}
|
||||
|
||||
public boolean setPrototype(@NonNull Prototype prototype) {
|
||||
if (!prototypes.contains(prototype.getName())) {
|
||||
return false;
|
||||
}
|
||||
return _setPrototype(prototype);
|
||||
}
|
||||
|
||||
boolean _setPrototype(@NonNull Prototype prototype) {
|
||||
generatePrototypeData(prototype, minPoint);
|
||||
RegionUtils.save(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean setSkin(@NonNull String skinName) {
|
||||
if (!prototype.getSkinMap().containsKey(skinName)) {
|
||||
return false;
|
||||
}
|
||||
this.skin = skinName;
|
||||
setLinkedRegion(region -> {
|
||||
region.skin = skinName;
|
||||
return true;
|
||||
});
|
||||
regionData.add("skin", skin);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void set(Flag flagType, Flag.Value<?> value) {
|
||||
if (flagStorage.set(flagType, value)) {
|
||||
RegionUtils.save(this);
|
||||
}
|
||||
setLinkedRegion(region -> region.flagStorage.set(flagType, value));
|
||||
}
|
||||
|
||||
public void set(Tag tag) {
|
||||
if (flagStorage.set(tag)) {
|
||||
RegionUtils.save(this);
|
||||
}
|
||||
setLinkedRegion(region -> region.flagStorage.set(tag));
|
||||
}
|
||||
|
||||
public void remove(Tag tag) {
|
||||
if (flagStorage.remove(tag)) {
|
||||
RegionUtils.save(this);
|
||||
}
|
||||
}
|
||||
|
||||
public Flag.Value<?> get(Flag flagType) {
|
||||
return flagStorage.get(flagType);
|
||||
}
|
||||
|
||||
public boolean get(Tag tagType) {
|
||||
return flagStorage.is(tagType);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
boolean hasReset(RegionType regionType) {
|
||||
if (!hasType(regionType)) {
|
||||
return false;
|
||||
}
|
||||
switch (regionType) {
|
||||
case TESTBLOCK:
|
||||
return prototype.getSkinMap().get(skin).getTestblockSchematicFile() != null;
|
||||
case BUILD:
|
||||
return prototype.getSkinMap().get(skin).getBuildSchematicFile() != null;
|
||||
default:
|
||||
case NORMAL:
|
||||
return prototype.getSkinMap().get(skin).getSchematicFile() != null;
|
||||
}
|
||||
}
|
||||
|
||||
public File getResetFile(RegionType regionType) {
|
||||
if (!hasReset(regionType)) {
|
||||
return null;
|
||||
}
|
||||
switch (regionType) {
|
||||
case TESTBLOCK:
|
||||
return prototype.getSkinMap().get(skin).getTestblockSchematicFile();
|
||||
case BUILD:
|
||||
return prototype.getSkinMap().get(skin).getBuildSchematicFile();
|
||||
default:
|
||||
case NORMAL:
|
||||
return prototype.getSkinMap().get(skin).getSchematicFile();
|
||||
}
|
||||
}
|
||||
|
||||
public void reset(PasteBuilder pasteBuilder, RegionType regionType, RegionExtensionType regionExtensionType) {
|
||||
if (!hasReset(regionType)) {
|
||||
return;
|
||||
}
|
||||
if (regionExtensionType == RegionExtensionType.EXTENSION && !hasExtensionType(regionType)) {
|
||||
regionExtensionType = RegionExtensionType.NORMAL;
|
||||
}
|
||||
|
||||
pasteBuilder.reset(regionExtensionType == RegionExtensionType.EXTENSION)
|
||||
.minPoint(getMinPoint(regionType, regionExtensionType))
|
||||
.maxPoint(getMaxPoint(regionType, regionExtensionType))
|
||||
.waterLevel(waterLevel);
|
||||
if (pasteBuilder.getClipboardProvider().is(PasteBuilder.SchematicProvider.class)) {
|
||||
SchematicType schematicType = pasteBuilder.getClipboardProvider().as(PasteBuilder.SchematicProvider.class).getSchematic().getSchemtype();
|
||||
pasteBuilder.rotate(schematicType.fightType() || schematicType.check());
|
||||
}
|
||||
|
||||
switch (regionType) {
|
||||
case BUILD:
|
||||
pasteBuilder.pastePoint(minPointBuild.add(prototype.getBuild().getSizeX() / 2, 0, prototype.getBuild().getSizeZ() / 2));
|
||||
break;
|
||||
case TESTBLOCK:
|
||||
Point pastePoint = minPointTestblock.add(prototype.getTestblock().getSizeX() / 2, 0, prototype.getTestblock().getSizeZ() / 2);
|
||||
if (pasteBuilder.getClipboardProvider().is(PasteBuilder.SchematicProvider.class)) {
|
||||
SchematicType schematicType = pasteBuilder.getClipboardProvider().as(PasteBuilder.SchematicProvider.class).getSchematic().getSchemtype();
|
||||
if (schematicType.getKuerzel().equalsIgnoreCase("wg")) {
|
||||
pastePoint = pastePoint.add(0, 0, 1);
|
||||
}
|
||||
if (schematicType.getKuerzel().equalsIgnoreCase("ws")) {
|
||||
pastePoint = pastePoint.add(-1, 0, 1);
|
||||
}
|
||||
if (schematicType.getKuerzel().equalsIgnoreCase("as")) {
|
||||
pastePoint = pastePoint.add(-1, 0, 1);
|
||||
}
|
||||
}
|
||||
pasteBuilder.pastePoint(pastePoint);
|
||||
break;
|
||||
default:
|
||||
case NORMAL:
|
||||
pasteBuilder.pastePoint(minPoint.add(prototype.getSizeX() / 2, 0, prototype.getSizeZ() / 2));
|
||||
break;
|
||||
}
|
||||
|
||||
initSessions();
|
||||
undoSessions.push(pasteBuilder.run());
|
||||
}
|
||||
|
||||
public void remember(EditSession editSession) {
|
||||
initSessions();
|
||||
undoSessions.push(editSession);
|
||||
}
|
||||
|
||||
public boolean isGlobal() {
|
||||
return this == GlobalRegion.getInstance();
|
||||
}
|
||||
|
||||
private void initSessions() {
|
||||
if (undoSessions == null) {
|
||||
undoSessions = new SizedStack<>(20);
|
||||
redoSessions = new SizedStack<>(20);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean undo() {
|
||||
initSessions();
|
||||
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);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean redo() {
|
||||
initSessions();
|
||||
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);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean backup() {
|
||||
final File definedBackupFolder = new File(new File(backupFolder, prototype.getName()), name);
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
definedBackupFolder.mkdirs();
|
||||
|
||||
File[] currentBackups = definedBackupFolder.listFiles();
|
||||
if (currentBackups != null && currentBackups.length >= 20) {
|
||||
List<File> files = new ArrayList<>(Arrays.asList(currentBackups));
|
||||
files.sort(Comparator.comparingLong(File::lastModified));
|
||||
while (files.size() >= 20) files.remove(0).delete();
|
||||
}
|
||||
|
||||
final File backupFile = new File(definedBackupFolder, LocalDateTime.now().format(formatter) + ".schem");
|
||||
return FlatteningWrapper.impl.backup(minPoint, maxPoint, backupFile);
|
||||
}
|
||||
|
||||
public static boolean copy(Point minPoint, Point maxPoint, File file) {
|
||||
return FlatteningWrapper.impl.backup(minPoint, maxPoint, file);
|
||||
}
|
||||
|
||||
public List<String> listBackup() {
|
||||
final File definedBackupFolder = new File(new File(backupFolder, prototype.getName()), name);
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
definedBackupFolder.mkdirs();
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public File gameModeConfig() {
|
||||
File baseFile = new File(BauSystem.getInstance().getDataFolder().getParentFile(), "FightSystem");
|
||||
for (int version = Core.getVersion(); version >= 15; version--) {
|
||||
File specific = new File(baseFile, prototype.getDisplayName() + version + ".yml");
|
||||
if (specific.exists()) return specific;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
||||
import de.steamwar.bausystem.region.utils.RegionType;
|
||||
import de.steamwar.bausystem.utils.FlatteningWrapper;
|
||||
import de.steamwar.bausystem.worlddata.WorldData;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
|
||||
@UtilityClass
|
||||
public class RegionUtils {
|
||||
|
||||
public void actionBar(Region region, String s, Object... objects) {
|
||||
Bukkit.getOnlinePlayers()
|
||||
.stream()
|
||||
.filter(player -> region.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL))
|
||||
.filter(player -> !region.isGlobal() || Region.getRegion(player.getLocation()).isGlobal())
|
||||
.forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(BauSystem.MESSAGE.parse(s, player, objects))));
|
||||
}
|
||||
|
||||
public static void message(Region region, String message, Object... objects) {
|
||||
Bukkit.getOnlinePlayers()
|
||||
.stream()
|
||||
.filter(player -> region.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL))
|
||||
.filter(player -> !region.isGlobal() || Region.getRegion(player.getLocation()).isGlobal())
|
||||
.forEach(player -> BauSystem.MESSAGE.send(message, player, objects));
|
||||
}
|
||||
|
||||
public static void message(Region region, Function<Player, String> function) {
|
||||
Bukkit.getOnlinePlayers()
|
||||
.stream()
|
||||
.filter(player -> region.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL))
|
||||
.filter(player -> !region.isGlobal() || Region.getRegion(player.getLocation()).isGlobal())
|
||||
.forEach(player -> {
|
||||
String message = function.apply(player);
|
||||
if (message == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
player.sendMessage(message);
|
||||
});
|
||||
}
|
||||
|
||||
public static void message(Region region, Consumer<Player> function) {
|
||||
Bukkit.getOnlinePlayers()
|
||||
.stream()
|
||||
.filter(player -> region.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL))
|
||||
.filter(player -> !region.isGlobal() || Region.getRegion(player.getLocation()).isGlobal())
|
||||
.forEach(player -> {
|
||||
function.accept(player);
|
||||
});
|
||||
}
|
||||
|
||||
static void save(Region region) {
|
||||
if (region.getPrototype() != null) {
|
||||
region.regionData.add("prototype", region.getPrototype().getName());
|
||||
}
|
||||
region.regionData.add("flagStorage", FlagStorage.toYAPION(region.getFlagStorage()));
|
||||
WorldData.write();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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.flags;
|
||||
|
||||
import de.steamwar.bausystem.region.flags.flagvalues.*;
|
||||
import de.steamwar.bausystem.shared.EnumDisplay;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
|
||||
@Getter
|
||||
public enum Flag implements EnumDisplay {
|
||||
|
||||
COLOR("FLAG_COLOR", ColorMode.class, ColorMode.YELLOW),
|
||||
TNT("FLAG_TNT", TNTMode.class, TNTMode.ONLY_TB),
|
||||
FIRE("FLAG_FIRE", FireMode.class, FireMode.ALLOW),
|
||||
FREEZE("FLAG_FREEZE", FreezeMode.class, FreezeMode.INACTIVE),
|
||||
PROTECT("FLAG_PROTECT", ProtectMode.class, ProtectMode.ACTIVE),
|
||||
ITEMS("FLAG_ITEMS", ItemMode.class, ItemMode.INACTIVE),
|
||||
NO_GRAVITY("FLAG_NO_GRAVITY", NoGravityMode.class, NoGravityMode.INACTIVE),
|
||||
;
|
||||
|
||||
@Getter
|
||||
private static final Set<Flag> flags;
|
||||
|
||||
static {
|
||||
flags = EnumSet.allOf(Flag.class);
|
||||
}
|
||||
|
||||
private final String chatValue;
|
||||
private final Class<? extends Value<?>> valueType;
|
||||
private final Flag.Value<?> defaultValue;
|
||||
private final Value<?>[] values;
|
||||
|
||||
<T extends Enum<T> & Value<T>> Flag(String chatValue, final Class<? extends Value<T>> valueType, final Flag.Value<T> defaultValue) {
|
||||
this.chatValue = chatValue;
|
||||
this.valueType = valueType;
|
||||
this.defaultValue = defaultValue;
|
||||
this.values = defaultValue.getValues();
|
||||
}
|
||||
|
||||
public Value<?> getFlagValueOf(final String name) {
|
||||
return this.defaultValue.getValueOf(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name().toLowerCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getChatValue() {
|
||||
return chatValue;
|
||||
}
|
||||
|
||||
public interface Value<T extends Enum<T> & Value<T>> extends EnumDisplay {
|
||||
|
||||
T getValue();
|
||||
|
||||
T getValueOf(final String name);
|
||||
|
||||
T[] getValues();
|
||||
|
||||
default String getName() {
|
||||
return this.getValue().name().toLowerCase();
|
||||
}
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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.flags.flagvalues;
|
||||
|
||||
import de.steamwar.bausystem.region.Color;
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum ColorMode implements Flag.Value<ColorMode> {
|
||||
WHITE("FLAG_COLOR_WHITE", Color.WHITE),
|
||||
ORANGE("FLAG_COLOR_ORANGE", Color.ORANGE),
|
||||
MAGENTA("FLAG_COLOR_MAGENTA", Color.MAGENTA),
|
||||
LIGHT_BLUE("FLAG_COLOR_LIGHT_BLUE", Color.LIGHT_BLUE),
|
||||
YELLOW("FLAG_COLOR_YELLOW", Color.YELLOW),
|
||||
LIME("FLAG_COLOR_LIME", Color.LIME),
|
||||
PINK("FLAG_COLOR_PINK", Color.PINK),
|
||||
GRAY("FLAG_COLOR_GRAY", Color.GRAY),
|
||||
LIGHT_GRAY("FLAG_COLOR_LIGHT_GRAY", Color.LIGHT_GRAY),
|
||||
CYAN("FLAG_COLOR_CYAN", Color.CYAN),
|
||||
PURPLE("FLAG_COLOR_PURPLE", Color.PURPLE),
|
||||
BLUE("FLAG_COLOR_BLUE", Color.BLUE),
|
||||
BROWN("FLAG_COLOR_BROWN", Color.BROWN),
|
||||
GREEN("FLAG_COLOR_GREEN", Color.GREEN),
|
||||
RED("FLAG_COLOR_RED", Color.RED),
|
||||
BLACK("FLAG_COLOR_BLACK", Color.BLACK);
|
||||
|
||||
private static ColorMode[] values;
|
||||
private final String chatValue;
|
||||
private final Color color;
|
||||
|
||||
@Override
|
||||
public ColorMode[] getValues() {
|
||||
if (ColorMode.values == null) {
|
||||
ColorMode.values = ColorMode.values(); //NOSONAR
|
||||
}
|
||||
return ColorMode.values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ColorMode getValue() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ColorMode getValueOf(final String name) {
|
||||
try {
|
||||
return ColorMode.valueOf(name.toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
return ColorMode.YELLOW;
|
||||
}
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.flags.flagvalues;
|
||||
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum FireMode implements Flag.Value<FireMode> {
|
||||
|
||||
ALLOW("FLAG_FIRE_ALLOW"),
|
||||
DENY("FLAG_FIRE_DENY");
|
||||
|
||||
private static FireMode[] values;
|
||||
private final String chatValue;
|
||||
|
||||
@Override
|
||||
public FireMode[] getValues() {
|
||||
if (FireMode.values == null) {
|
||||
FireMode.values = FireMode.values(); //NOSONAR
|
||||
}
|
||||
return FireMode.values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FireMode getValue() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FireMode getValueOf(final String name) {
|
||||
try {
|
||||
return FireMode.valueOf(name.toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
if (name.equalsIgnoreCase("false")) {
|
||||
return FireMode.DENY;
|
||||
}
|
||||
return FireMode.ALLOW;
|
||||
}
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.flags.flagvalues;
|
||||
|
||||
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum FreezeMode implements Flag.Value<FreezeMode> {
|
||||
|
||||
ACTIVE("FLAG_FREEZE_ACTIVE"),
|
||||
INACTIVE("FLAG_FREEZE_INACTIVE");
|
||||
|
||||
private static FreezeMode[] values;
|
||||
private final String chatValue;
|
||||
|
||||
@Override
|
||||
public FreezeMode[] getValues() {
|
||||
if (FreezeMode.values == null) {
|
||||
FreezeMode.values = FreezeMode.values(); //NOSONAR
|
||||
}
|
||||
return FreezeMode.values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FreezeMode getValue() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FreezeMode getValueOf(final String name) {
|
||||
try {
|
||||
return FreezeMode.valueOf(name.toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
if (name.equalsIgnoreCase("false")) {
|
||||
return FreezeMode.INACTIVE;
|
||||
}
|
||||
return FreezeMode.INACTIVE;
|
||||
}
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.flags.flagvalues;
|
||||
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum ItemMode implements Flag.Value<ItemMode> {
|
||||
|
||||
ACTIVE("FLAG_ITEMS_ACTIVE"),
|
||||
INACTIVE("FLAG_ITEMS_INACTIVE");
|
||||
|
||||
private static ItemMode[] values;
|
||||
private final String chatValue;
|
||||
|
||||
@Override
|
||||
public ItemMode[] getValues() {
|
||||
if (ItemMode.values == null) {
|
||||
ItemMode.values = ItemMode.values(); //NOSONAR
|
||||
}
|
||||
return ItemMode.values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemMode getValue() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemMode getValueOf(final String name) {
|
||||
try {
|
||||
return ItemMode.valueOf(name.toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
if (name.equalsIgnoreCase("false")) {
|
||||
return ItemMode.INACTIVE;
|
||||
}
|
||||
return ItemMode.ACTIVE;
|
||||
}
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.flags.flagvalues;
|
||||
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum NoGravityMode implements Flag.Value<NoGravityMode> {
|
||||
|
||||
ACTIVE("FLAG_NO_GRAVITY_ACTIVE"),
|
||||
INACTIVE("FLAG_NO_GRAVITY_INACTIVE");
|
||||
|
||||
private static NoGravityMode[] values;
|
||||
private final String chatValue;
|
||||
|
||||
@Override
|
||||
public NoGravityMode[] getValues() {
|
||||
if (NoGravityMode.values == null) {
|
||||
NoGravityMode.values = NoGravityMode.values(); //NOSONAR
|
||||
}
|
||||
return NoGravityMode.values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NoGravityMode getValue() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NoGravityMode getValueOf(final String name) {
|
||||
try {
|
||||
return NoGravityMode.valueOf(name.toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
if (name.equalsIgnoreCase("false")) {
|
||||
return NoGravityMode.INACTIVE;
|
||||
}
|
||||
return NoGravityMode.ACTIVE;
|
||||
}
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.flags.flagvalues;
|
||||
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum ProtectMode implements Flag.Value<ProtectMode> {
|
||||
|
||||
ACTIVE("FLAG_PROTECT_ACTIVE"),
|
||||
INACTIVE("FLAG_PROTECT_INACTIVE");
|
||||
|
||||
private static ProtectMode[] values;
|
||||
private final String chatValue;
|
||||
|
||||
@Override
|
||||
public ProtectMode[] getValues() {
|
||||
if (ProtectMode.values == null) {
|
||||
ProtectMode.values = ProtectMode.values(); //NOSONAR
|
||||
}
|
||||
return ProtectMode.values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtectMode getValue() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtectMode getValueOf(final String name) {
|
||||
try {
|
||||
return ProtectMode.valueOf(name.toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
if (name.equalsIgnoreCase("false")) {
|
||||
return ProtectMode.INACTIVE;
|
||||
}
|
||||
return ProtectMode.ACTIVE;
|
||||
}
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.flags.flagvalues;
|
||||
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum TNTMode implements Flag.Value<TNTMode> {
|
||||
|
||||
ALLOW("FLAG_TNT_ALLOW"),
|
||||
DENY("FLAG_TNT_DENY"),
|
||||
ONLY_TB("FLAG_TNT_ONLY_TB"),
|
||||
ONLY_BUILD("FLAG_TNT_ONLY_BUILD");
|
||||
|
||||
private static TNTMode[] values;
|
||||
private final String chatValue;
|
||||
|
||||
@Override
|
||||
public TNTMode[] getValues() {
|
||||
if (TNTMode.values == null) {
|
||||
TNTMode.values = TNTMode.values(); //NOSONAR
|
||||
}
|
||||
return TNTMode.values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TNTMode getValue() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TNTMode getValueOf(final String name) {
|
||||
try {
|
||||
return TNTMode.valueOf(name.toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
return TNTMode.ALLOW;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.loader;
|
||||
|
||||
import de.steamwar.bausystem.region.Prototype;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Bukkit;
|
||||
import yapion.hierarchy.diff.DiffDelete;
|
||||
import yapion.hierarchy.diff.YAPIONDiff;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
import yapion.parser.YAPIONParser;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
@UtilityClass
|
||||
public class PrototypeLoader {
|
||||
|
||||
private YAPIONObject loaded = null;
|
||||
public static final File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "prototypes.yapion");
|
||||
|
||||
public void load() {
|
||||
YAPIONObject yapionObject = null;
|
||||
try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file))) {
|
||||
yapionObject = YAPIONParser.parse(bufferedInputStream);
|
||||
} catch (IOException e) {
|
||||
throw new SecurityException(e.getMessage(), e);
|
||||
}
|
||||
|
||||
if (loaded != null && new YAPIONDiff(loaded, yapionObject).getDiffs().stream().anyMatch(DiffDelete.class::isInstance)) {
|
||||
throw new SecurityException("Version was not the specified version needed.");
|
||||
}
|
||||
loaded = yapionObject;
|
||||
|
||||
yapionObject.forEach((key, yapionAnyType) -> {
|
||||
if (yapionAnyType instanceof YAPIONObject) {
|
||||
new Prototype(key, (YAPIONObject) yapionAnyType);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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.loader;
|
||||
|
||||
import de.steamwar.bausystem.region.FlagStorage;
|
||||
import de.steamwar.bausystem.region.GlobalRegion;
|
||||
import de.steamwar.bausystem.region.Prototype;
|
||||
import de.steamwar.bausystem.worlddata.WorldData;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Bukkit;
|
||||
import yapion.hierarchy.diff.DiffChange;
|
||||
import yapion.hierarchy.diff.YAPIONDiff;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
import yapion.hierarchy.types.YAPIONType;
|
||||
import yapion.parser.YAPIONParser;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
@UtilityClass
|
||||
public class RegionLoader {
|
||||
|
||||
private YAPIONObject loaded = null;
|
||||
public static final File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "regions.yapion");
|
||||
|
||||
public void load() {
|
||||
YAPIONObject yapionObject = null;
|
||||
try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file))) {
|
||||
yapionObject = YAPIONParser.parse(bufferedInputStream);
|
||||
} catch (IOException e) {
|
||||
throw new SecurityException(e.getMessage(), e);
|
||||
}
|
||||
|
||||
if (loaded != null && new YAPIONDiff(loaded, yapionObject).getDiffs().stream().anyMatch(diffBase -> !(diffBase instanceof DiffChange))) {
|
||||
throw new SecurityException("Version was not the specified version needed.");
|
||||
}
|
||||
loaded = yapionObject;
|
||||
|
||||
YAPIONObject optionsYapionObject = WorldData.getRegionsData();
|
||||
yapionObject.forEach((key, yapionAnyType) -> {
|
||||
if (key.equals("global")) {
|
||||
return;
|
||||
}
|
||||
if (!(yapionAnyType instanceof YAPIONObject)) {
|
||||
return;
|
||||
}
|
||||
|
||||
YAPIONObject regionConfig = (YAPIONObject) yapionAnyType;
|
||||
YAPIONObject regionData = new YAPIONObject();
|
||||
if (optionsYapionObject.containsKey(key, YAPIONType.OBJECT)) {
|
||||
regionData = optionsYapionObject.getObject(key);
|
||||
} else {
|
||||
optionsYapionObject.add(key, regionData);
|
||||
}
|
||||
|
||||
Prototype.generateRegion(key, regionConfig, regionData);
|
||||
});
|
||||
|
||||
YAPIONObject globalOptions = optionsYapionObject.getObject("global");
|
||||
if (globalOptions == null) {
|
||||
globalOptions = new YAPIONObject();
|
||||
optionsYapionObject.add("global", globalOptions);
|
||||
}
|
||||
FlagStorage flagStorage;
|
||||
if (globalOptions.containsKey("flagStorage", YAPIONType.OBJECT)) {
|
||||
flagStorage = FlagStorage.createStorage(globalOptions.getObject("flagStorage"));
|
||||
} else {
|
||||
flagStorage = new FlagStorage();
|
||||
}
|
||||
new GlobalRegion(flagStorage, globalOptions);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.loader;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class Updater {
|
||||
|
||||
private long lastUpdate;
|
||||
|
||||
public Updater(File file, Runnable updaterCode) {
|
||||
this.lastUpdate = file.lastModified();
|
||||
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
|
||||
if (file.lastModified() > lastUpdate + 10) {
|
||||
try {
|
||||
updaterCode.run();
|
||||
Bukkit.getLogger().log(Level.INFO, "Update complete of " + file.getAbsolutePath());
|
||||
} catch (Exception e) {
|
||||
Bukkit.getLogger().log(Level.INFO, "Error while loading file " + file.getAbsolutePath() + " for config: " + e.getMessage(), e);
|
||||
}
|
||||
lastUpdate = file.lastModified();
|
||||
}
|
||||
}, 20, 20);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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.tags;
|
||||
|
||||
public enum Tag {
|
||||
CHANGED,
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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.utils;
|
||||
|
||||
public enum RegionExtensionType {
|
||||
NORMAL,
|
||||
EXTENSION
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package de.steamwar.bausystem.region.utils;
|
||||
|
||||
public enum RegionSelectionType {
|
||||
LOCAL,
|
||||
GLOBAL
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.utils;
|
||||
|
||||
import de.steamwar.bausystem.shared.EnumDisplay;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@AllArgsConstructor
|
||||
public enum RegionType implements EnumDisplay {
|
||||
NORMAL("REGION_TYPE_NORMAL"),
|
||||
BUILD("REGION_TYPE_BUILD"),
|
||||
TESTBLOCK("REGION_TYPE_ONLY_TB");
|
||||
|
||||
@Getter
|
||||
private String chatValue;
|
||||
}
|
||||
Reference in New Issue
Block a user