SteamWar/BauSystem
Archiviert
13
0

RegionFix #240

Manuell gemergt
YoyoNow hat 34 Commits von RegionFix nach master 2021-04-05 16:57:57 +02:00 zusammengeführt
21 geänderte Dateien mit 686 neuen und 557 gelöschten Zeilen
Nur Änderungen aus Commit bdc9e44e2a werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -1,23 +1,23 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
/*
* 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/>.
*/
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;
package de.steamwar.bausystem.world.regions;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;

Datei anzeigen

@ -1,23 +1,23 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
/*
* 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/>.
*/
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;
package de.steamwar.bausystem.world.regions;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEdit;

Datei anzeigen

@ -21,7 +21,7 @@ package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.world.Region;
import de.steamwar.bausystem.world.regions.Region;
import de.steamwar.bausystem.world.Welt;
import de.steamwar.command.SWCommand;
import org.bukkit.Bukkit;

Datei anzeigen

@ -21,7 +21,7 @@ package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.world.Region;
import de.steamwar.bausystem.world.regions.Region;
import de.steamwar.bausystem.world.Welt;
import de.steamwar.command.SWCommand;
import de.steamwar.core.Core;

Datei anzeigen

@ -25,6 +25,8 @@ import de.steamwar.bausystem.SWUtils;
import de.steamwar.bausystem.tracer.record.RecordStateMachine;
import de.steamwar.bausystem.tracer.show.TraceShowManager;
import de.steamwar.bausystem.world.*;
import de.steamwar.bausystem.world.regions.GlobalRegion;
import de.steamwar.bausystem.world.regions.Region;
import de.steamwar.command.SWCommand;
import de.steamwar.core.Core;
import de.steamwar.inventory.SWAnvilInv;
@ -190,7 +192,7 @@ public class CommandGUI extends SWCommand implements Listener {
anvilInv.open();
});
if (Region.GlobalRegion.isGlobalRegion(region)) {
if (GlobalRegion.isGlobalRegion(region)) {
inv.setItem(9, Material.BARRIER, "§eKeine Region", clickType -> {
});
inv.setItem(18, Material.BARRIER, "§eKeine Region", clickType -> {

Datei anzeigen

@ -20,7 +20,7 @@
package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.world.Region;
import de.steamwar.bausystem.world.regions.Region;
import de.steamwar.bausystem.world.TPSUtils;
import de.steamwar.command.SWCommand;
import de.steamwar.core.TPSWatcher;

Datei anzeigen

@ -21,7 +21,7 @@ package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.world.Region;
import de.steamwar.bausystem.world.regions.Region;
import de.steamwar.bausystem.world.Welt;
import de.steamwar.command.SWCommand;
import de.steamwar.sql.Schematic;

Datei anzeigen

@ -2,7 +2,8 @@ package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.world.Region;
import de.steamwar.bausystem.world.regions.GlobalRegion;
import de.steamwar.bausystem.world.regions.Region;
import de.steamwar.bausystem.world.Welt;
import de.steamwar.command.SWCommand;
import org.bukkit.entity.Player;
@ -51,7 +52,7 @@ public class CommandRegion extends SWCommand {
}
static boolean checkGlobalRegion(Region region, Player p) {
if(Region.GlobalRegion.isGlobalRegion(region)) {
if(GlobalRegion.isGlobalRegion(region)) {
p.sendMessage(BauSystem.PREFIX + "§cDu bist in keiner Region");
return true;
}

Datei anzeigen

@ -21,7 +21,8 @@ package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.world.Region;
import de.steamwar.bausystem.world.regions.GlobalRegion;
import de.steamwar.bausystem.world.regions.Region;
import de.steamwar.bausystem.world.Welt;
import de.steamwar.command.SWCommand;
import de.steamwar.sql.Schematic;
@ -86,7 +87,7 @@ public class CommandReset extends SWCommand {
private Region regionCheck(Player player) {
Region region = Region.getRegion(player.getLocation());
if (region == Region.GlobalRegion.getInstance()) {
if (region == GlobalRegion.getInstance()) {
player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner Region");
return null;
}

Datei anzeigen

@ -21,8 +21,10 @@ package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.world.Region;
import de.steamwar.bausystem.world.regions.Region;
import de.steamwar.bausystem.world.Welt;
import de.steamwar.bausystem.world.regions.RegionExtensionType;
import de.steamwar.bausystem.world.regions.RegionType;
import de.steamwar.command.SWCommand;
import de.steamwar.command.SWCommandUtils;
import de.steamwar.command.TypeMapper;
@ -157,11 +159,11 @@ public class CommandTNT extends SWCommand implements Listener {
event.blockList().removeIf(block -> {
Region region = Region.getRegion(block.getLocation());
if (region.getTntMode() == TNTMode.ON) return false;
if (region.hasBuildRegion() && region.inRegion(block.getLocation(), Region.RegionType.BUILD_AREA, Region.RegionExtensionType.NORMAL)) {
if (region.hasBuildRegion() && region.inRegion(block.getLocation(), RegionType.BUILD_AREA, RegionExtensionType.NORMAL)) {
RegionUtils.actionBar(region, "§cEine Explosion hätte Blöcke im Baubereich zerstört");
return true;
}
if (region.hasBuildRegion() && region.inRegion(block.getLocation(), Region.RegionType.BUILD_AREA, Region.RegionExtensionType.EXTENSION)) {
if (region.hasBuildRegion() && region.inRegion(block.getLocation(), RegionType.BUILD_AREA, RegionExtensionType.EXTENSION)) {
RegionUtils.actionBar(region, "§cEine Explosion hätte Blöcke im Ausfahrbereich zerstört");
return true;
}

Datei anzeigen

@ -21,7 +21,7 @@ package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.world.Region;
import de.steamwar.bausystem.world.regions.Region;
import de.steamwar.bausystem.world.Welt;
import de.steamwar.command.SWCommand;
import de.steamwar.sql.Schematic;

Datei anzeigen

@ -19,7 +19,10 @@
package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.world.Region;
import de.steamwar.bausystem.world.regions.GlobalRegion;
import de.steamwar.bausystem.world.regions.Region;
import de.steamwar.bausystem.world.regions.RegionExtensionType;
import de.steamwar.bausystem.world.regions.RegionType;
import lombok.experimental.UtilityClass;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
@ -29,10 +32,10 @@ import org.bukkit.Bukkit;
public class RegionUtils {
public static void actionBar(Region region, String s) {
if (Region.GlobalRegion.isGlobalRegion(region)) {
if (GlobalRegion.isGlobalRegion(region)) {
Bukkit.getOnlinePlayers().stream().filter(player -> Region.getRegion(player.getLocation()) == null).forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s)));
} else {
Bukkit.getOnlinePlayers().stream().filter(player -> region.inRegion(player.getLocation(), Region.RegionType.NORMAL, Region.RegionExtensionType.NORMAL)).forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s)));
Bukkit.getOnlinePlayers().stream().filter(player -> region.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)).forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s)));
}
}

Datei anzeigen

@ -21,6 +21,7 @@ package de.steamwar.bausystem.world;
import de.steamwar.bausystem.commands.CommandTPSLimiter;
import de.steamwar.bausystem.tracer.record.RecordStateMachine;
import de.steamwar.bausystem.world.regions.Region;
import de.steamwar.core.TPSWatcher;
import de.steamwar.scoreboard.SWScoreboard;
import de.steamwar.scoreboard.ScoreboardCallback;

Datei anzeigen

@ -1,503 +0,0 @@
/*
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;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.math.BlockVector3;
import de.steamwar.bausystem.commands.CommandTNT.TNTMode;
import de.steamwar.core.VersionedCallable;
import de.steamwar.sql.NoClipboardException;
import de.steamwar.sql.Schematic;
import lombok.AllArgsConstructor;
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.IOException;
import java.util.*;
import java.util.function.Consumer;
import java.util.logging.Level;
public class Region {
private static final List<Region> regions = new ArrayList<>();
private static boolean buildArea = false;
private static boolean extensionArea = false;
static {
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();
}
private final String name;
private 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 TNTMode tntMode = Region.buildAreaEnabled() ? TNTMode.ONLY_TB : TNTMode.OFF;
private boolean freeze = false;
private boolean fire = false;
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);
}
public Region(String name) {
this.name = name;
this.minPoint = new Point(0, 0, 0);
this.prototype = null;
this.optionsLinkedWith = null;
tntMode = TNTMode.OFF;
}
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 TNTMode getTntMode() {
return tntMode;
}
public void setTntMode(TNTMode tntMode) {
this.tntMode = tntMode;
setLinkedRegion(region -> region.tntMode = tntMode);
}
public boolean isFreeze() {
return freeze;
}
public void setFreeze(boolean freeze) {
this.freeze = freeze;
setLinkedRegion(region -> region.freeze = freeze);
}
public boolean isFire() {
return fire;
}
public void setFire(boolean fire) {
this.fire = fire;
setLinkedRegion(region -> region.fire = fire);
}
public Point getMinPoint(RegionType regionType, RegionExtensionType regionExtensionType) {
switch (regionType) {
case BUILD_AREA:
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_AREA:
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_AREA:
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() throws IOException {
initSessions();
undosessions.push(prototype.reset(this, null));
}
public void reset(Schematic schem) throws IOException, NoClipboardException {
initSessions();
undosessions.push(prototype.reset(this, schem));
}
public boolean hasTestblock() {
return prototype.hasTestblock();
}
public void resetTestblock(Schematic schem) throws IOException, NoClipboardException {
initSessions();
undosessions.push(prototype.resetTestblock(this, schem));
}
public boolean hasProtection() {
return prototype.hasProtection();
}
public void protect(Schematic schem) throws IOException, NoClipboardException {
initSessions();
undosessions.push(prototype.protect(this, schem));
}
public boolean hasExtensionAreaRegistered() {
return prototype.extensionPrototypeArea;
}
public boolean hasTestblockExtensionAreaRegistered() {
return prototype.testblock.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.flushSession();
}
}
}
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.flushSession();
}
}
}
public static 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 hasExtensionAreaRegistered() {
return false;
}
@Override
public boolean hasTestblockExtensionAreaRegistered() {
return false;
}
}
public static class Prototype {
private 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;
private final boolean extensionPrototypeArea;
private final int waterLevel;
private final String schematic;
private final boolean rotate;
private final Prototype testblock; //nullable
private final Prototype buildArea; //nullable
private final String protectSchematic; //nullable
private 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")) {
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),
region.minPoint.getY() + offsetY + sizeY + extensionPositiveY,
region.minPoint.getZ() + offsetZ - extensionNegativeZ + (sizeZ + extensionNegativeZ + extensionPositiveZ)
);
default:
case NORMAL:
return new Point(
region.minPoint.getX() + offsetX + sizeX,
region.minPoint.getY() + offsetY + sizeY,
region.minPoint.getZ() + offsetZ + sizeZ
);
}
}
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, Schematic schem) throws IOException, NoClipboardException {
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, rotate);
else
return paste(schem.load(), x, y, z, rotate);
}
public boolean hasProtection() {
return protectSchematic != null;
}
public EditSession protect(Region region, Schematic 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, rotate);
else
return paste(schem.load(), x, y, z, rotate);
}
public boolean hasTestblock() {
return testblock != null;
}
public EditSession resetTestblock(Region region, Schematic schem) throws IOException, NoClipboardException {
return testblock.reset(region, schem);
}
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, boolean rotate) { //Type of protect
return (EditSession) VersionedCallable.call(new VersionedCallable(() -> Region_12.paste(file, x, y, z, rotate), 8),
new VersionedCallable(() -> Region_15.paste(file, x, y, z, rotate), 15));
}
private static EditSession paste(Clipboard clipboard, int x, int y, int z, boolean rotate) {
return (EditSession) VersionedCallable.call(new VersionedCallable(() -> Region_12.paste(clipboard, x, y, z, rotate), 8),
new VersionedCallable(() -> Region_15.paste(clipboard, x, y, z, rotate), 15));
}
}
public enum RegionType {
NORMAL,
BUILD_AREA,
TESTBLOCK
}
public enum RegionExtensionType {
NORMAL,
EXTENSION
}
@Getter
@AllArgsConstructor
public static class Point {
final int x;
final int y;
final int z;
public BlockVector3 toBlockVector3() {
return BlockVector3.at(this.x, this.y, this.z);
}
}
}

Datei anzeigen

@ -23,6 +23,7 @@ import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.commands.CommandScript;
import de.steamwar.bausystem.commands.CommandTNT;
import de.steamwar.bausystem.tracer.record.RecordStateMachine;
import de.steamwar.bausystem.world.regions.Region;
import de.steamwar.core.VersionedCallable;
import de.steamwar.inventory.SWAnvilInv;
import org.bukkit.Bukkit;

Datei anzeigen

@ -0,0 +1,69 @@
/*
* 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 hasBuildAreaExtensionAreaRegistered() {
return false;
}
@Override
public boolean hasTestblockExtensionAreaRegistered() {
return false;
}
}

Datei anzeigen

@ -0,0 +1,37 @@
/*
* 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.math.BlockVector3;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public class Point {
final int x;
final int y;
final int z;
public BlockVector3 toBlockVector3() {
return BlockVector3.at(this.x, this.y, this.z);
}
}

Datei anzeigen

@ -0,0 +1,191 @@
/*
* 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.core.VersionedCallable;
import de.steamwar.sql.NoClipboardException;
import de.steamwar.sql.Schematic;
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),
region.minPoint.getY() + offsetY + sizeY + extensionPositiveY,
region.minPoint.getZ() + offsetZ - extensionNegativeZ + (sizeZ + extensionNegativeZ + extensionPositiveZ)
);
default:
case NORMAL:
return new Point(
region.minPoint.getX() + offsetX + sizeX,
region.minPoint.getY() + offsetY + sizeY,
region.minPoint.getZ() + offsetZ + sizeZ
);
}
}
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, Schematic schem) throws IOException, NoClipboardException {
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, rotate);
else
return paste(schem.load(), x, y, z, rotate);
}
public boolean hasProtection() {
return protectSchematic != null;
}
public EditSession protect(Region region, Schematic 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, rotate);
else
return paste(schem.load(), x, y, z, rotate);
}
public boolean hasTestblock() {
return testblock != null;
}
public EditSession resetTestblock(Region region, Schematic schem) throws IOException, NoClipboardException {
return testblock.reset(region, schem);
}
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, boolean rotate) { //Type of protect
return (EditSession) VersionedCallable.call(new VersionedCallable(() -> Region_12.paste(file, x, y, z, rotate), 8),
new VersionedCallable(() -> Region_15.paste(file, x, y, z, rotate), 15));
}
private static EditSession paste(Clipboard clipboard, int x, int y, int z, boolean rotate) {
return (EditSession) VersionedCallable.call(new VersionedCallable(() -> Region_12.paste(clipboard, x, y, z, rotate), 8),
new VersionedCallable(() -> Region_15.paste(clipboard, x, y, z, rotate), 15));
}
}

Datei anzeigen

@ -0,0 +1,273 @@
/*
* 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.commands.CommandTNT.TNTMode;
import de.steamwar.bausystem.world.SizedStack;
import de.steamwar.core.VersionedCallable;
import de.steamwar.sql.NoClipboardException;
import de.steamwar.sql.Schematic;
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.IOException;
import java.util.*;
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;
static {
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();
}
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 TNTMode tntMode = Region.buildAreaEnabled() ? TNTMode.ONLY_TB : TNTMode.OFF;
private boolean freeze = false;
private boolean fire = false;
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);
}
public Region(String name) {
this.name = name;
this.minPoint = new Point(0, 0, 0);
this.prototype = null;
this.optionsLinkedWith = null;
tntMode = TNTMode.OFF;
}
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 TNTMode getTntMode() {
return tntMode;
}
public void setTntMode(TNTMode tntMode) {
this.tntMode = tntMode;
setLinkedRegion(region -> region.tntMode = tntMode);
}
public boolean isFreeze() {
return freeze;
}
public void setFreeze(boolean freeze) {
this.freeze = freeze;
setLinkedRegion(region -> region.freeze = freeze);
}
public boolean isFire() {
return fire;
}
public void setFire(boolean fire) {
this.fire = fire;
setLinkedRegion(region -> region.fire = fire);
}
public Point getMinPoint(RegionType regionType, RegionExtensionType regionExtensionType) {
switch (regionType) {
case BUILD_AREA:
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_AREA:
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_AREA:
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() throws IOException {
initSessions();
undosessions.push(prototype.reset(this, null));
}
public void reset(Schematic schem) throws IOException, NoClipboardException {
initSessions();
undosessions.push(prototype.reset(this, schem));
}
public boolean hasTestblock() {
return prototype.hasTestblock();
}
public void resetTestblock(Schematic schem) throws IOException, NoClipboardException {
initSessions();
undosessions.push(prototype.resetTestblock(this, schem));
}
public boolean hasProtection() {
return prototype.hasProtection();
}
public void protect(Schematic schem) throws IOException, NoClipboardException {
initSessions();
undosessions.push(prototype.protect(this, schem));
}
public boolean hasBuildAreaExtensionAreaRegistered() {
return prototype.buildArea.extensionPrototypeArea;
}
public boolean hasTestblockExtensionAreaRegistered() {
return prototype.testblock.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.flushSession();
}
}
}
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.flushSession();
}
}
}
}

Datei anzeigen

@ -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
}

Datei anzeigen

@ -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_AREA,
TESTBLOCK
}