forked from SteamWar/SteamWar
Add LegacyBauSystem with adaptions to current SpigotCore
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.world.regions;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class GlobalRegion extends Region {
|
||||
|
||||
private static final GlobalRegion GLOBAL_REGION = new GlobalRegion();
|
||||
|
||||
public static GlobalRegion getInstance() {
|
||||
return GLOBAL_REGION;
|
||||
}
|
||||
|
||||
public static boolean isGlobalRegion(Region region) {
|
||||
return region == GLOBAL_REGION;
|
||||
}
|
||||
|
||||
public GlobalRegion() {
|
||||
super("Global");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inRegion(Location l, RegionType regionType, RegionExtensionType regionExtensionType) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBuildRegion() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTestblock() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasProtection() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasExtensionArea(RegionType regionType) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* 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.world.regions;
|
||||
|
||||
import de.steamwar.bausystem.world.Color;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class PasteOptions {
|
||||
|
||||
/**
|
||||
* Used in 1.12 and 1.15
|
||||
*/
|
||||
private boolean rotate = false;
|
||||
|
||||
/**
|
||||
* Used in 1.12 and 1.15
|
||||
*/
|
||||
private boolean ignoreAir = false;
|
||||
|
||||
/**
|
||||
* Used in 1.15
|
||||
*/
|
||||
private Color color = Color.YELLOW;
|
||||
|
||||
/**
|
||||
* Used in 1.15
|
||||
*/
|
||||
private boolean reset = false;
|
||||
|
||||
/**
|
||||
* Used in 1.15
|
||||
*/
|
||||
private Point minPoint = null;
|
||||
|
||||
/**
|
||||
* Used in 1.15
|
||||
*/
|
||||
private Point maxPoint = null;
|
||||
|
||||
/**
|
||||
* Used in 1.15
|
||||
*/
|
||||
private int waterLevel = 0;
|
||||
|
||||
public PasteOptions(boolean rotate) {
|
||||
this.rotate = rotate;
|
||||
}
|
||||
|
||||
public PasteOptions(boolean rotate, Color color) {
|
||||
this.rotate = rotate;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public PasteOptions(boolean rotate, boolean ignoreAir) {
|
||||
this.rotate = rotate;
|
||||
this.ignoreAir = ignoreAir;
|
||||
}
|
||||
|
||||
public PasteOptions(boolean rotate, boolean ignoreAir, boolean reset) {
|
||||
this.rotate = rotate;
|
||||
this.ignoreAir = ignoreAir;
|
||||
this.reset = reset;
|
||||
}
|
||||
|
||||
public PasteOptions(boolean rotate, Color color, boolean reset) {
|
||||
this.rotate = rotate;
|
||||
this.color = color;
|
||||
this.reset = reset;
|
||||
}
|
||||
|
||||
public PasteOptions(boolean rotate, boolean ignoreAir, Color color) {
|
||||
this.rotate = rotate;
|
||||
this.ignoreAir = ignoreAir;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.world.regions;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class Point {
|
||||
final int x;
|
||||
final int y;
|
||||
final int z;
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
/*
|
||||
* 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.world.regions;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import de.steamwar.bausystem.WorldeditWrapper;
|
||||
import de.steamwar.bausystem.world.Color;
|
||||
import de.steamwar.sql.NoClipboardException;
|
||||
import de.steamwar.sql.SchematicData;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Prototype {
|
||||
static final Map<String, Prototype> prototypes = new HashMap<>();
|
||||
|
||||
private final int sizeX;
|
||||
private final int sizeY;
|
||||
private final int sizeZ;
|
||||
|
||||
private final int offsetX;
|
||||
private final int offsetY;
|
||||
private final int offsetZ;
|
||||
|
||||
private final int extensionPositiveZ;
|
||||
private final int extensionNegativeZ;
|
||||
private final int extensionPositiveY;
|
||||
private final int extensionAxisX;
|
||||
final boolean extensionPrototypeArea;
|
||||
|
||||
private final int waterLevel;
|
||||
|
||||
private final String schematic;
|
||||
private final boolean rotate;
|
||||
|
||||
final Prototype testblock; //nullable
|
||||
final Prototype buildArea; //nullable
|
||||
|
||||
private final String protectSchematic; //nullable
|
||||
|
||||
Prototype(ConfigurationSection config) {
|
||||
sizeX = config.getInt("sizeX");
|
||||
sizeY = config.getInt("sizeY");
|
||||
sizeZ = config.getInt("sizeZ");
|
||||
schematic = config.getString("schematic");
|
||||
offsetX = config.getInt("offsetX", 0);
|
||||
offsetY = config.getInt("offsetY", 0);
|
||||
offsetZ = config.getInt("offsetZ", 0);
|
||||
extensionPositiveZ = config.getInt("extensionPositiveZ", 0);
|
||||
extensionNegativeZ = config.getInt("extensionNegativeZ", 0);
|
||||
extensionPositiveY = config.getInt("extensionPositiveY", 0);
|
||||
extensionAxisX = config.getInt("extensionAxisX", 0);
|
||||
if (config.contains("extensionPositiveZ") || config.contains("extensionNegativeZ") || config.contains("extensionPositiveY") || config.contains("extensionAxisX")) {
|
||||
Region.extensionArea = true;
|
||||
}
|
||||
extensionPrototypeArea = extensionNegativeZ != 0 || extensionPositiveZ != 0 || extensionPositiveY != 0 || extensionAxisX != 0;
|
||||
waterLevel = config.getInt("waterLevel", 0);
|
||||
rotate = config.getBoolean("rotate", false);
|
||||
|
||||
ConfigurationSection testblockSection = config.getConfigurationSection("testblock");
|
||||
testblock = testblockSection != null ? new Prototype(testblockSection) : null;
|
||||
|
||||
ConfigurationSection buildAreaSection = config.getConfigurationSection("buildArea");
|
||||
buildArea = buildAreaSection != null ? new Prototype(buildAreaSection) : null;
|
||||
if (buildArea != null) {
|
||||
Region.buildArea = true;
|
||||
}
|
||||
|
||||
protectSchematic = config.getString("protection", null);
|
||||
|
||||
if (!config.getName().equals("testblock") && !config.getName().equals("buildArea"))
|
||||
prototypes.put(config.getName(), this);
|
||||
}
|
||||
|
||||
public Point getMinPoint(Region region, RegionExtensionType regionExtensionType) {
|
||||
switch (regionExtensionType) {
|
||||
case EXTENSION:
|
||||
return new Point(
|
||||
region.minPoint.getX() + offsetX - extensionAxisX,
|
||||
region.minPoint.getY() + offsetY,
|
||||
region.minPoint.getZ() + offsetZ - extensionNegativeZ
|
||||
);
|
||||
default:
|
||||
case NORMAL:
|
||||
return new Point(
|
||||
region.minPoint.getX() + offsetX,
|
||||
region.minPoint.getY() + offsetY,
|
||||
region.minPoint.getZ() + offsetZ
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public Point getMaxPoint(Region region, RegionExtensionType regionExtensionType) {
|
||||
switch (regionExtensionType) {
|
||||
case EXTENSION:
|
||||
return new Point(
|
||||
region.minPoint.getX() + offsetX - extensionAxisX + (sizeX + extensionAxisX * 2) - 1,
|
||||
region.minPoint.getY() + offsetY + sizeY + extensionPositiveY - 1,
|
||||
region.minPoint.getZ() + offsetZ - extensionNegativeZ + (sizeZ + extensionNegativeZ + extensionPositiveZ) - 1
|
||||
);
|
||||
default:
|
||||
case NORMAL:
|
||||
return new Point(
|
||||
region.minPoint.getX() + offsetX + sizeX - 1,
|
||||
region.minPoint.getY() + offsetY + sizeY - 1,
|
||||
region.minPoint.getZ() + offsetZ + sizeZ - 1
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean inRegion(Region region, Location l, RegionExtensionType regionExtensionType) {
|
||||
switch (regionExtensionType) {
|
||||
case EXTENSION:
|
||||
return inRange(l.getX(), region.minPoint.getX() + offsetX - extensionAxisX, sizeX + extensionAxisX * 2) &&
|
||||
inRange(l.getY(), region.minPoint.getY() + offsetY, sizeY + extensionPositiveY) &&
|
||||
inRange(l.getZ(), region.minPoint.getZ() + offsetZ - extensionNegativeZ, sizeZ + extensionNegativeZ + extensionPositiveZ);
|
||||
default:
|
||||
case NORMAL:
|
||||
return inRange(l.getX(), region.minPoint.getX() + offsetX, sizeX) &&
|
||||
inRange(l.getY(), region.minPoint.getY() + offsetY, sizeY) &&
|
||||
inRange(l.getZ(), region.minPoint.getZ() + offsetZ, sizeZ);
|
||||
}
|
||||
}
|
||||
|
||||
public EditSession reset(Region region, SchematicNode schem, boolean ignoreAir, Color color) throws IOException, NoClipboardException {
|
||||
return reset(region, schem, ignoreAir, color, false);
|
||||
}
|
||||
|
||||
public EditSession reset(Region region, SchematicNode schem, boolean ignoreAir, Color color, boolean reset) throws IOException, NoClipboardException {
|
||||
PasteOptions pasteOptions;
|
||||
if (reset) {
|
||||
pasteOptions = new PasteOptions(rotate ^ (schem != null && (schem.getSchemtype().fightType() || schem.getSchemtype().check())), ignoreAir, color, true, getMinPoint(region, RegionExtensionType.EXTENSION), getMaxPoint(region, RegionExtensionType.EXTENSION), waterLevel);
|
||||
} else {
|
||||
pasteOptions = new PasteOptions(rotate ^ (schem != null && (schem.getSchemtype().fightType() || schem.getSchemtype().check())), ignoreAir, color);
|
||||
}
|
||||
|
||||
int x = region.minPoint.getX() + offsetX + sizeX / 2;
|
||||
int y = region.minPoint.getY() + offsetY;
|
||||
int z = region.minPoint.getZ() + offsetZ + sizeZ / 2;
|
||||
if (schem == null) {
|
||||
return paste(new File(schematic), x, y, z, pasteOptions);
|
||||
} else {
|
||||
return paste(new SchematicData(schem).load(), x, y, z, pasteOptions);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasProtection() {
|
||||
return protectSchematic != null;
|
||||
}
|
||||
|
||||
public EditSession protect(Region region, SchematicNode schem) throws IOException, NoClipboardException {
|
||||
int x = region.minPoint.getX() + offsetX + sizeX / 2;
|
||||
int y = region.minPoint.getY() + testblock.offsetY - 1;
|
||||
int z = region.minPoint.getZ() + offsetZ + sizeZ / 2;
|
||||
if (schem == null) {
|
||||
return paste(new File(protectSchematic), x, y, z, new PasteOptions(rotate, false, Color.YELLOW));
|
||||
} else {
|
||||
return paste(new SchematicData(schem).load(), x, y, z, new PasteOptions(rotate, false, Color.YELLOW));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasTestblock() {
|
||||
return testblock != null;
|
||||
}
|
||||
|
||||
public EditSession resetTestblock(Region region, SchematicNode schem, Color color, boolean reset) throws IOException, NoClipboardException {
|
||||
return testblock.reset(region, schem, false, color, reset && waterLevel == 0);
|
||||
}
|
||||
|
||||
private static boolean inRange(double l, int min, int size) {
|
||||
return min <= l && l < min + size;
|
||||
}
|
||||
|
||||
private static EditSession paste(File file, int x, int y, int z, PasteOptions pasteOptions) { //Type of protect
|
||||
return WorldeditWrapper.impl.paste(file, x, y, z, pasteOptions);
|
||||
}
|
||||
|
||||
private static EditSession paste(Clipboard clipboard, int x, int y, int z, PasteOptions pasteOptions) {
|
||||
return WorldeditWrapper.impl.paste(clipboard, x, y, z, pasteOptions);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,388 @@
|
||||
/*
|
||||
* 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.world.regions;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import de.steamwar.bausystem.commands.CommandTNT.TNTMode;
|
||||
import de.steamwar.bausystem.world.Color;
|
||||
import de.steamwar.bausystem.world.SizedStack;
|
||||
import de.steamwar.sql.NoClipboardException;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class Region {
|
||||
|
||||
private static final List<Region> regions = new ArrayList<>();
|
||||
static boolean buildArea = false;
|
||||
static boolean extensionArea = false;
|
||||
private static JsonObject regionsObject = new JsonObject();
|
||||
|
||||
static {
|
||||
File regionsFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "regions.json");
|
||||
if (regionsFile.exists()) {
|
||||
try {
|
||||
regionsObject = new JsonParser().parse(new FileReader(regionsFile)).getAsJsonObject();
|
||||
} catch (JsonSyntaxException | IOException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Item JSON error");
|
||||
}
|
||||
}
|
||||
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
try {
|
||||
config.load(new File(Bukkit.getWorlds().get(0).getWorldFolder(), "sections.yml"));
|
||||
} catch (InvalidConfigurationException | IOException e) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Failed to load sections.yml", e);
|
||||
}
|
||||
|
||||
ConfigurationSection prototypes = config.getConfigurationSection("prototypes");
|
||||
assert prototypes != null;
|
||||
for (String prototype : prototypes.getKeys(false)) {
|
||||
new Prototype(Objects.requireNonNull(prototypes.getConfigurationSection(prototype)));
|
||||
}
|
||||
|
||||
ConfigurationSection regions = config.getConfigurationSection("regions");
|
||||
assert regions != null;
|
||||
for (String region : regions.getKeys(false)) {
|
||||
new Region(Objects.requireNonNull(regions.getConfigurationSection(region)));
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean buildAreaEnabled() {
|
||||
return buildArea;
|
||||
}
|
||||
|
||||
public static boolean extensionAreaEnabled() {
|
||||
return extensionArea;
|
||||
}
|
||||
|
||||
public static Region getRegion(Location location) {
|
||||
for (Region region : regions) {
|
||||
if (region.inRegion(location, RegionType.NORMAL, RegionExtensionType.NORMAL)) {
|
||||
return region;
|
||||
}
|
||||
}
|
||||
return GlobalRegion.getInstance();
|
||||
}
|
||||
|
||||
public static void setGlobalColor(Color color) {
|
||||
for (Region region : regions) {
|
||||
region.setColor(color);
|
||||
}
|
||||
}
|
||||
|
||||
public static void save() {
|
||||
File colorsFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "regions.json");
|
||||
if (!colorsFile.exists()) {
|
||||
try {
|
||||
colorsFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
}
|
||||
try (FileOutputStream fileOutputStream = new FileOutputStream(colorsFile)) {
|
||||
fileOutputStream.write(regionsObject.toString().getBytes());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
// Ignored
|
||||
}
|
||||
}
|
||||
|
||||
private final String name;
|
||||
final Point minPoint;
|
||||
private final Prototype prototype;
|
||||
private final String optionsLinkedWith; // nullable
|
||||
private Region linkedRegion = null; // nullable
|
||||
private SizedStack<EditSession> undosessions;
|
||||
private SizedStack<EditSession> redosessions;
|
||||
|
||||
private JsonObject regionOptions = new JsonObject();
|
||||
|
||||
@Getter
|
||||
private TNTMode tntMode = Region.buildAreaEnabled() ? TNTMode.ONLY_TB : TNTMode.OFF;
|
||||
|
||||
@Getter
|
||||
private boolean freeze = false;
|
||||
|
||||
@Getter
|
||||
private boolean fire = false;
|
||||
|
||||
@Getter
|
||||
private boolean protect = false;
|
||||
|
||||
@Getter
|
||||
private Color color = Color.YELLOW;
|
||||
|
||||
private Region(ConfigurationSection config) {
|
||||
name = config.getName();
|
||||
minPoint = new Point(config.getInt("minX"), config.getInt("minY"), config.getInt("minZ"));
|
||||
prototype = Prototype.prototypes.get(config.getString("prototype"));
|
||||
optionsLinkedWith = config.getString("optionsLinkedWith", null);
|
||||
if (!hasTestblock()) tntMode = TNTMode.OFF;
|
||||
regions.add(this);
|
||||
load();
|
||||
}
|
||||
|
||||
public Region(String name) {
|
||||
this.name = name;
|
||||
this.minPoint = new Point(0, 0, 0);
|
||||
this.prototype = null;
|
||||
this.optionsLinkedWith = null;
|
||||
tntMode = TNTMode.OFF;
|
||||
load();
|
||||
}
|
||||
|
||||
private void load() {
|
||||
if (regionsObject.has(name)) {
|
||||
regionOptions = regionsObject.getAsJsonObject(name);
|
||||
if (regionOptions.has("tnt")) {
|
||||
String tntName = regionsObject.getAsJsonObject(name).getAsJsonPrimitive("tnt").getAsString();
|
||||
try {
|
||||
tntMode = TNTMode.valueOf(tntName);
|
||||
} catch (Exception e) {
|
||||
// Ignored
|
||||
}
|
||||
}
|
||||
|
||||
if (regionOptions.has("fire")) {
|
||||
fire = regionOptions.getAsJsonPrimitive("fire").getAsBoolean();
|
||||
}
|
||||
|
||||
if (regionOptions.has("freeze")) {
|
||||
freeze = regionOptions.getAsJsonPrimitive("freeze").getAsBoolean();
|
||||
}
|
||||
|
||||
if (regionOptions.has("protect")) {
|
||||
protect = regionOptions.getAsJsonPrimitive("protect").getAsBoolean();
|
||||
}
|
||||
|
||||
if (regionOptions.has("color")) {
|
||||
String colorName = regionOptions.getAsJsonPrimitive("color").getAsString();
|
||||
try {
|
||||
color = Color.valueOf(colorName);
|
||||
} catch (Exception e) {
|
||||
// Ignored
|
||||
}
|
||||
}
|
||||
} else {
|
||||
regionsObject.add(name, regionOptions);
|
||||
}
|
||||
}
|
||||
|
||||
public void setColor(Color color) {
|
||||
this.color = color;
|
||||
regionOptions.add("color", new JsonPrimitive(color.name()));
|
||||
}
|
||||
|
||||
private void setLinkedRegion(Consumer<Region> regionConsumer) {
|
||||
if (optionsLinkedWith == null) {
|
||||
return;
|
||||
}
|
||||
if (linkedRegion != null) {
|
||||
regionConsumer.accept(linkedRegion);
|
||||
return;
|
||||
}
|
||||
for (Region region : regions) {
|
||||
if (region.name.equals(name)) {
|
||||
linkedRegion = region;
|
||||
regionConsumer.accept(linkedRegion);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setTntMode(TNTMode tntMode) {
|
||||
this.tntMode = tntMode;
|
||||
setLinkedRegion(region -> {
|
||||
region.tntMode = tntMode;
|
||||
region.regionOptions.add("tnt", new JsonPrimitive(tntMode.name()));
|
||||
});
|
||||
regionOptions.add("tnt", new JsonPrimitive(tntMode.name()));
|
||||
}
|
||||
|
||||
public void setFreeze(boolean freeze) {
|
||||
this.freeze = freeze;
|
||||
setLinkedRegion(region -> {
|
||||
region.freeze = freeze;
|
||||
region.regionOptions.add("freeze", new JsonPrimitive(freeze));
|
||||
});
|
||||
regionOptions.add("freeze", new JsonPrimitive(freeze));
|
||||
}
|
||||
|
||||
public void setFire(boolean fire) {
|
||||
this.fire = fire;
|
||||
setLinkedRegion(region -> {
|
||||
region.fire = fire;
|
||||
region.regionOptions.add("fire", new JsonPrimitive(fire));
|
||||
});
|
||||
regionOptions.add("fire", new JsonPrimitive(fire));
|
||||
}
|
||||
|
||||
public void setProtect(boolean protect) {
|
||||
this.protect = protect;
|
||||
setLinkedRegion(region -> {
|
||||
region.protect = protect;
|
||||
region.regionOptions.add("protect", new JsonPrimitive(protect));
|
||||
});
|
||||
regionOptions.add("protect", new JsonPrimitive(protect));
|
||||
}
|
||||
|
||||
public Point getMinPoint(RegionType regionType, RegionExtensionType regionExtensionType) {
|
||||
switch (regionType) {
|
||||
case BUILD:
|
||||
return prototype.buildArea.getMinPoint(this, regionExtensionType);
|
||||
case TESTBLOCK:
|
||||
return prototype.testblock.getMinPoint(this, regionExtensionType);
|
||||
default:
|
||||
case NORMAL:
|
||||
return prototype.getMinPoint(this, regionExtensionType);
|
||||
}
|
||||
}
|
||||
|
||||
public Point getMaxPoint(RegionType regionType, RegionExtensionType regionExtensionType) {
|
||||
switch (regionType) {
|
||||
case BUILD:
|
||||
return prototype.buildArea.getMaxPoint(this, regionExtensionType);
|
||||
case TESTBLOCK:
|
||||
return prototype.testblock.getMaxPoint(this, regionExtensionType);
|
||||
default:
|
||||
case NORMAL:
|
||||
return prototype.getMaxPoint(this, regionExtensionType);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean inRegion(Location l, RegionType regionType, RegionExtensionType regionExtensionType) {
|
||||
switch (regionType) {
|
||||
case BUILD:
|
||||
return prototype.buildArea.inRegion(this, l, regionExtensionType);
|
||||
case TESTBLOCK:
|
||||
return prototype.testblock.inRegion(this, l, regionExtensionType);
|
||||
default:
|
||||
case NORMAL:
|
||||
return prototype.inRegion(this, l, regionExtensionType);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasBuildRegion() {
|
||||
return prototype.buildArea != null;
|
||||
}
|
||||
|
||||
public void reset(SchematicNode schem, boolean ignoreAir) throws IOException, NoClipboardException {
|
||||
initSessions();
|
||||
undosessions.push(prototype.reset(this, schem, ignoreAir, color));
|
||||
}
|
||||
|
||||
public boolean hasTestblock() {
|
||||
return prototype.hasTestblock();
|
||||
}
|
||||
|
||||
public void resetTestblock(SchematicNode schem, boolean reset) throws IOException, NoClipboardException {
|
||||
initSessions();
|
||||
undosessions.push(prototype.resetTestblock(this, schem, color, reset));
|
||||
}
|
||||
|
||||
public boolean hasProtection() {
|
||||
return prototype.hasProtection();
|
||||
}
|
||||
|
||||
public void protect(SchematicNode schem) throws IOException, NoClipboardException {
|
||||
initSessions();
|
||||
undosessions.push(prototype.protect(this, schem));
|
||||
}
|
||||
|
||||
public int getProtectYLevel() {
|
||||
return getMinPoint(RegionType.TESTBLOCK, RegionExtensionType.NORMAL).getY();
|
||||
}
|
||||
|
||||
public boolean hasExtensionArea(RegionType regionType) {
|
||||
switch (regionType) {
|
||||
case BUILD:
|
||||
return prototype.buildArea.extensionPrototypeArea;
|
||||
case TESTBLOCK:
|
||||
return prototype.testblock.extensionPrototypeArea;
|
||||
default:
|
||||
case NORMAL:
|
||||
return prototype.extensionPrototypeArea;
|
||||
}
|
||||
}
|
||||
|
||||
private void initSessions() {
|
||||
if (undosessions == null) {
|
||||
undosessions = new SizedStack<>(20);
|
||||
redosessions = new SizedStack<>(20);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean undo() {
|
||||
initSessions();
|
||||
EditSession session = null;
|
||||
try {
|
||||
session = undosessions.pop();
|
||||
if (session == null) {
|
||||
return false;
|
||||
}
|
||||
session.undo(session);
|
||||
redosessions.push(session);
|
||||
return true;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.flushQueue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean redo() {
|
||||
initSessions();
|
||||
EditSession session = null;
|
||||
try {
|
||||
session = redosessions.pop();
|
||||
if (session == null) {
|
||||
return false;
|
||||
}
|
||||
session.redo(session);
|
||||
undosessions.push(session);
|
||||
return true;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.flushQueue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.world.regions;
|
||||
|
||||
public enum RegionExtensionType {
|
||||
NORMAL,
|
||||
EXTENSION
|
||||
}
|
||||
@@ -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.world.regions;
|
||||
|
||||
public enum RegionSelectionType {
|
||||
GLOBAL,
|
||||
LOCAL
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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.world.regions;
|
||||
|
||||
public enum RegionType {
|
||||
NORMAL,
|
||||
BUILD,
|
||||
TESTBLOCK
|
||||
}
|
||||
Reference in New Issue
Block a user