diff --git a/BauSystem_12/src/de/steamwar/bausystem/world/Region_12.java b/BauSystem_12/src/de/steamwar/bausystem/world/regions/Region_12.java similarity index 73% rename from BauSystem_12/src/de/steamwar/bausystem/world/Region_12.java rename to BauSystem_12/src/de/steamwar/bausystem/world/regions/Region_12.java index d95b106..db8cb37 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/world/Region_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/world/regions/Region_12.java @@ -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 . + */ - 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 . -*/ - -package de.steamwar.bausystem.world; +package de.steamwar.bausystem.world.regions; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.Vector; diff --git a/BauSystem_15/src/de/steamwar/bausystem/world/Region_15.java b/BauSystem_15/src/de/steamwar/bausystem/world/regions/Region_15.java similarity index 74% rename from BauSystem_15/src/de/steamwar/bausystem/world/Region_15.java rename to BauSystem_15/src/de/steamwar/bausystem/world/regions/Region_15.java index 76da59d..9e735cb 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/world/Region_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/world/regions/Region_15.java @@ -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 . + */ - 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 . -*/ - -package de.steamwar.bausystem.world; +package de.steamwar.bausystem.world.regions; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.WorldEdit; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java index 0c9d5c2..8295088 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java @@ -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; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index 2baeb2a..2531ccd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -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; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java index b2fa3db..69a51fc 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java @@ -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 -> { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java index 93873dc..0eb78c1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java @@ -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; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java index fed21f5..65c602f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java @@ -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; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRegion.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRegion.java index 7ed72ff..bb28fc8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRegion.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRegion.java @@ -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; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java index 05d3988..0847c11 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java @@ -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; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index b57d083..0e510cf 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -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; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java index f90e8cb..bcc9a00 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java @@ -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; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionUtils.java index 7c2cc3a..1d9dc60 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionUtils.java @@ -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))); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java index ccdc312..5ba1eb3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -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; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java deleted file mode 100644 index 5363d9d..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ /dev/null @@ -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 . -*/ - -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 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 undosessions; - private SizedStack 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 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 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); - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java index cf084e2..542f134 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java @@ -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; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/regions/GlobalRegion.java b/BauSystem_Main/src/de/steamwar/bausystem/world/regions/GlobalRegion.java new file mode 100644 index 0000000..e16d048 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/regions/GlobalRegion.java @@ -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 . + */ + +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; + } +} \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Point.java b/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Point.java new file mode 100644 index 0000000..b3f7f07 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Point.java @@ -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 . + */ + +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); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Prototype.java b/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Prototype.java new file mode 100644 index 0000000..0c8a658 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Prototype.java @@ -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 . + */ + +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 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)); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Region.java new file mode 100644 index 0000000..3959bc5 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Region.java @@ -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 . + */ + +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 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 undosessions; + private SizedStack 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 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(); + } + } + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/regions/RegionExtensionType.java b/BauSystem_Main/src/de/steamwar/bausystem/world/regions/RegionExtensionType.java new file mode 100644 index 0000000..b2194e0 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/regions/RegionExtensionType.java @@ -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 . + */ + +package de.steamwar.bausystem.world.regions; + +public enum RegionExtensionType { + NORMAL, + EXTENSION +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/regions/RegionType.java b/BauSystem_Main/src/de/steamwar/bausystem/world/regions/RegionType.java new file mode 100644 index 0000000..2b9fbaf --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/regions/RegionType.java @@ -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 . + */ + +package de.steamwar.bausystem.world.regions; + +public enum RegionType { + NORMAL, + BUILD_AREA, + TESTBLOCK +}