From 6822dc796fe6d25f03860eac3e200c49ae784834 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sat, 21 Dec 2024 19:30:31 +0100 Subject: [PATCH] Update Region System of BauSystem --- .../bausystem/utils/FlatteningWrapper15.java | 2 +- .../features/autostart/AutostartListener.java | 8 +- .../features/backup/BackupCommand.java | 8 +- .../features/cannon/CannonDetector.java | 5 +- .../features/cannon/depth/Depth.java | 4 +- .../features/countingwand/Countingwand.java | 2 +- .../countingwand/CountingwandListener.java | 2 +- .../endstone/DesignEndStoneCommand.java | 3 +- .../killchecker/KillcheckerVisualizer.java | 2 +- .../features/observer/ObserverTracer.java | 2 +- .../features/region/RegionCommand.java | 2 +- .../region/items/ColorBauGuiItem.java | 2 +- .../features/script/lua/libs/LuaLib.java | 2 +- .../script/lua/libs/WorldEditLib.java | 2 +- .../features/simulator/data/tnt/TNTPhase.java | 3 +- .../features/slaves/laufbau/Cuboid.java | 2 +- .../laufbau/states/CreatingLaufState.java | 2 +- .../laufbau/states/ProcessingTracesState.java | 2 +- .../bausystem/features/team/SkinCommand.java | 6 +- .../team/boundary/BoundaryViewer.java | 9 +- .../blockcounter/BlockCounterListener.java | 8 +- .../bausystem/features/tracer/TNTPoint.java | 12 +- .../features/util/KillAllCommand.java | 10 +- .../features/util/SelectCommand.java | 2 +- .../features/world/BauScoreboard.java | 9 +- .../worldedit/ColorReplaceCommand.java | 2 +- .../bausystem/region/BackupScheduler.java | 42 +- .../{regionnew => region}/Color.java | 41 +- .../bausystem/region/FlagStorage.java | 110 +--- .../bausystem/region/GlobalRegion.java | 42 -- .../{regionnew => region}/Point.java | 2 +- .../de/steamwar/bausystem/region/Region.java | 613 +++--------------- .../RegionFlagPolicy.java | 6 +- .../{regionnew => region}/RegionSystem.java | 6 +- .../{regionnew => region}/RegionType.java | 4 +- .../bausystem/region/RegionUtils.java | 100 +-- .../flags/ChangedMode.java | 2 +- .../flags/ColorMode.java | 4 +- .../{regionnew => region}/flags/FireMode.java | 2 +- .../steamwar/bausystem/region/flags/Flag.java | 134 ++-- .../flags/FreezeMode.java | 2 +- .../{regionnew => region}/flags/ItemMode.java | 2 +- .../flags/NoGravityMode.java | 2 +- .../flags/ProtectMode.java | 2 +- .../{regionnew => region}/flags/TNTMode.java | 2 +- .../flags/TestblockMode.java | 2 +- .../region/flags/flagvalues/ColorMode.java | 72 -- .../region/flags/flagvalues/FireMode.java | 60 -- .../region/flags/flagvalues/FreezeMode.java | 61 -- .../region/flags/flagvalues/ItemMode.java | 60 -- .../flags/flagvalues/NoGravityMode.java | 60 -- .../region/flags/flagvalues/ProtectMode.java | 60 -- .../region/flags/flagvalues/TNTMode.java | 59 -- .../steamwar/bausystem/region/tags/Tag.java | 24 - .../region/utils/RegionExtensionType.java | 25 - .../region/utils/RegionSelectionType.java | 3 +- .../bausystem/region/utils/RegionType.java | 34 - .../bausystem/regionnew/FlagStorage.java | 29 - .../steamwar/bausystem/regionnew/Region.java | 85 --- .../bausystem/regionnew/RegionSide.java | 25 - .../bausystem/regionnew/flags/Flag.java | 102 --- .../Prototype.java.txt} | 0 .../bausystem/regionold/Region.java.txt | 584 +++++++++++++++++ .../loader/PrototypeLoader.java.txt} | 0 .../loader/RegionLoader.java.txt} | 0 .../loader/Updater.java.txt} | 0 .../bausystem/utils/FlatteningWrapper.java | 2 +- .../bausystem/utils/PasteBuilder.java | 4 +- .../utils/bossbar/GlobalBossbar.java | 4 +- .../FixedFlagStorage.java | 10 +- .../FixedGlobalRegion.java | 62 +- .../{regionnew => region}/FixedRegion.java | 63 +- .../FixedRegionSystem.java | 2 +- 73 files changed, 927 insertions(+), 1796 deletions(-) rename BauSystem/BauSystem_Main/src/de/steamwar/bausystem/{regionnew => region}/Color.java (65%) delete mode 100644 BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/GlobalRegion.java rename BauSystem/BauSystem_Main/src/de/steamwar/bausystem/{regionnew => region}/Point.java (98%) rename BauSystem/BauSystem_Main/src/de/steamwar/bausystem/{regionnew => region}/RegionFlagPolicy.java (90%) rename BauSystem/BauSystem_Main/src/de/steamwar/bausystem/{regionnew => region}/RegionSystem.java (94%) rename BauSystem/BauSystem_Main/src/de/steamwar/bausystem/{regionnew => region}/RegionType.java (93%) rename BauSystem/BauSystem_Main/src/de/steamwar/bausystem/{regionnew => region}/flags/ChangedMode.java (97%) rename BauSystem/BauSystem_Main/src/de/steamwar/bausystem/{regionnew => region}/flags/ColorMode.java (96%) rename BauSystem/BauSystem_Main/src/de/steamwar/bausystem/{regionnew => region}/flags/FireMode.java (96%) rename BauSystem/BauSystem_Main/src/de/steamwar/bausystem/{regionnew => region}/flags/FreezeMode.java (97%) rename BauSystem/BauSystem_Main/src/de/steamwar/bausystem/{regionnew => region}/flags/ItemMode.java (97%) rename BauSystem/BauSystem_Main/src/de/steamwar/bausystem/{regionnew => region}/flags/NoGravityMode.java (97%) rename BauSystem/BauSystem_Main/src/de/steamwar/bausystem/{regionnew => region}/flags/ProtectMode.java (97%) rename BauSystem/BauSystem_Main/src/de/steamwar/bausystem/{regionnew => region}/flags/TNTMode.java (96%) rename BauSystem/BauSystem_Main/src/de/steamwar/bausystem/{regionnew => region}/flags/TestblockMode.java (97%) delete mode 100644 BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/ColorMode.java delete mode 100644 BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/FireMode.java delete mode 100644 BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/FreezeMode.java delete mode 100644 BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/ItemMode.java delete mode 100644 BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/NoGravityMode.java delete mode 100644 BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/ProtectMode.java delete mode 100644 BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/TNTMode.java delete mode 100644 BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/tags/Tag.java delete mode 100644 BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/utils/RegionExtensionType.java delete mode 100644 BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/utils/RegionType.java delete mode 100644 BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/FlagStorage.java delete mode 100644 BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/Region.java delete mode 100644 BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/RegionSide.java delete mode 100644 BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/flags/Flag.java rename BauSystem/BauSystem_Main/src/de/steamwar/bausystem/{region/Prototype.java => regionold/Prototype.java.txt} (100%) create mode 100644 BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionold/Region.java.txt rename BauSystem/BauSystem_Main/src/de/steamwar/bausystem/{region/loader/PrototypeLoader.java => regionold/loader/PrototypeLoader.java.txt} (100%) rename BauSystem/BauSystem_Main/src/de/steamwar/bausystem/{region/loader/RegionLoader.java => regionold/loader/RegionLoader.java.txt} (100%) rename BauSystem/BauSystem_Main/src/de/steamwar/bausystem/{region/loader/Updater.java => regionold/loader/Updater.java.txt} (100%) rename BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/{regionnew => region}/FixedFlagStorage.java (86%) rename BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/{regionnew => region}/FixedGlobalRegion.java (65%) rename BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/{regionnew => region}/FixedRegion.java (61%) rename BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/{regionnew => region}/FixedRegionSystem.java (97%) diff --git a/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java b/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java index 69872f57..266326e0 100644 --- a/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java +++ b/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java @@ -42,7 +42,7 @@ import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockTypes; -import de.steamwar.bausystem.regionnew.Point; +import de.steamwar.bausystem.region.Point; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.Block; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java index 28126ec5..3185c66c 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java @@ -44,7 +44,6 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; import java.io.File; -import java.text.SimpleDateFormat; import java.util.*; @Linked @@ -106,11 +105,11 @@ public class AutostartListener implements Listener { public void activate(Player player) { Region region = Region.getRegion(player.getLocation()); - if (region.isGlobal()) { + if (region.getType().isGlobal()) { BauSystem.MESSAGE.send("AUTOSTART_MESSAGE_NO_REGION", player); return; } - if (!region.hasType(RegionType.TESTBLOCK)) { + if (region.getTestblockArea().isPresent()) { BauSystem.MESSAGE.send("AUTOSTART_MESSAGE_NO_REGION", player); return; } @@ -131,8 +130,7 @@ public class AutostartListener implements Listener { event.blockList().forEach(block -> { Region region = Region.getRegion(block.getLocation()); if (!regionStartTime.containsKey(region)) return; - if (!region.hasType(RegionType.TESTBLOCK)) return; - if (!region.inRegion(block.getLocation(), RegionType.TESTBLOCK, RegionExtensionType.EXTENSION)) return; + if (!region.getTestblockArea().inRegion(block.getLocation(), true)) return; long tickDiff = TPSUtils.currentRealTick.get() - regionStartTime.remove(region); long preFightDurationInSeconds = getPreFightDurationInSeconds(region); RegionUtils.message(region, "AUTOSTART_MESSAGE_RESULT1", tickDiff); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/backup/BackupCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/backup/BackupCommand.java index 6abe927a..919c08cd 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/backup/BackupCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/backup/BackupCommand.java @@ -22,7 +22,7 @@ package de.steamwar.bausystem.features.backup; import com.sk89q.worldedit.EditSession; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.Region; -import de.steamwar.bausystem.region.tags.Tag; +import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.utils.PasteBuilder; import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommandUtils; @@ -49,7 +49,7 @@ public class BackupCommand extends SWCommand { } static boolean checkGlobalRegion(Region region, Player p) { - if (region.isGlobal()) { + if (region.getType().isGlobal()) { BauSystem.MESSAGE.send("BACKUP_REGION_NO_REGION", p); return true; } @@ -62,11 +62,11 @@ public class BackupCommand extends SWCommand { if (checkGlobalRegion(region, p)) { return; } - if (!region.get(Tag.CHANGED)) { + if (region.getFlag(Flag.CHANGED).isPresent()) { BauSystem.MESSAGE.send("BACKUP_CREATE_NO_CHANGE", p); return; } - if (region.backup()) { + if (region.backup(false)) { BauSystem.MESSAGE.send("BACKUP_CREATE_SUCCESS", p); } else { BauSystem.MESSAGE.send("BACKUP_CREATE_FAILURE", p); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/cannon/CannonDetector.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/cannon/CannonDetector.java index 3ab4fe70..7c73888d 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/cannon/CannonDetector.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/cannon/CannonDetector.java @@ -23,7 +23,6 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.cannon.depth.Depth; import de.steamwar.bausystem.features.cannon.depth.DepthManager; import de.steamwar.bausystem.region.Region; -import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.linkage.Linked; import org.bukkit.Bukkit; import org.bukkit.entity.TNTPrimed; @@ -85,8 +84,8 @@ public class CannonDetector implements Listener { grouped.forEach((cannonKey, tntPrimeds) -> { if (tntPrimeds.size() <= 5) return; Region region = Region.getRegion(tntPrimeds.get(0).getLocation()); - if (region.isGlobal()) return; - if (!region.hasType(RegionType.TESTBLOCK)) return; + if (region.getType().isGlobal()) return; + if (region.getTestblockArea().isEmpty()) return; Depth depth = new Depth(region); DepthManager.init(tntPrimeds, depth); }); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/cannon/depth/Depth.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/cannon/depth/Depth.java index 22ce7fde..4cfacb98 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/cannon/depth/Depth.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/cannon/depth/Depth.java @@ -23,8 +23,6 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.configplayer.Config; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.RegionUtils; -import de.steamwar.bausystem.region.utils.RegionExtensionType; -import de.steamwar.bausystem.region.utils.RegionType; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.TextComponent; @@ -50,7 +48,7 @@ public class Depth { public void update(List blocks) { List blocksList = blocks.stream() - .filter(block -> region.inRegion(block.getLocation(), RegionType.TESTBLOCK, RegionExtensionType.EXTENSION)) + .filter(block -> region.getTestblockArea().inRegion(block.getLocation(), true)) .collect(Collectors.toList()); tntCount++; for (Block block : blocksList) { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/countingwand/Countingwand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/countingwand/Countingwand.java index 6c667ba7..fb9316b9 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/countingwand/Countingwand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/countingwand/Countingwand.java @@ -20,7 +20,7 @@ package de.steamwar.bausystem.features.countingwand; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.regionnew.Point; +import de.steamwar.bausystem.region.Point; import de.steamwar.bausystem.shared.Pair; import de.steamwar.bausystem.utils.ItemUtils; import de.steamwar.inventory.SWItem; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/countingwand/CountingwandListener.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/countingwand/CountingwandListener.java index 9d811f28..7233670a 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/countingwand/CountingwandListener.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/countingwand/CountingwandListener.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.features.countingwand; -import de.steamwar.bausystem.regionnew.Point; +import de.steamwar.bausystem.region.Point; import de.steamwar.linkage.Linked; import org.bukkit.FluidCollisionMode; import org.bukkit.event.EventHandler; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStoneCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStoneCommand.java index 92934c23..e50541a8 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStoneCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStoneCommand.java @@ -21,7 +21,6 @@ package de.steamwar.bausystem.features.design.endstone; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.Region; -import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.bausystem.utils.BauMemberUpdateEvent; import de.steamwar.command.SWCommand; import de.steamwar.linkage.Linked; @@ -49,7 +48,7 @@ public class DesignEndStoneCommand extends SWCommand implements Listener { @Register(description = "DESIGN_ENDSTONE_COMMAND_HELP") public void genericCommand(@Validator Player player) { Region region = Region.getRegion(player.getLocation()); - if (!region.hasType(RegionType.BUILD)) { + if (region.getBuildArea().isEmpty()) { BauSystem.MESSAGE.send("DESIGN_ENDSTONE_REGION_ERROR", player); return; } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java index d7145f37..04822aa8 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java @@ -20,7 +20,7 @@ package de.steamwar.bausystem.features.killchecker; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.regionnew.Point; +import de.steamwar.bausystem.region.Point; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracer.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracer.java index e4aedd0a..c1e08fcf 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracer.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracer.java @@ -20,7 +20,7 @@ package de.steamwar.bausystem.features.observer; import de.steamwar.Reflection; -import de.steamwar.bausystem.regionnew.Point; +import de.steamwar.bausystem.region.Point; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Particle; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java index e7cedc22..6d8d6f4d 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java @@ -28,7 +28,7 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.session.ClipboardHolder; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.util.SelectCommand; -import de.steamwar.bausystem.regionnew.Point; +import de.steamwar.bausystem.region.Point; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.RegionUtils; import de.steamwar.bausystem.region.flags.Flag; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/ColorBauGuiItem.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/ColorBauGuiItem.java index b886e756..a38c397f 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/ColorBauGuiItem.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/ColorBauGuiItem.java @@ -22,7 +22,7 @@ package de.steamwar.bausystem.features.region.items; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.linkage.specific.BauGuiItem; -import de.steamwar.bausystem.regionnew.Color; +import de.steamwar.bausystem.region.Color; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.flagvalues.ColorMode; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/LuaLib.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/LuaLib.java index a86542df..a4af0d3a 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/LuaLib.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/LuaLib.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.features.script.lua.libs; -import de.steamwar.bausystem.regionnew.Point; +import de.steamwar.bausystem.region.Point; import lombok.AllArgsConstructor; import org.bukkit.entity.Player; import org.luaj.vm2.*; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/WorldEditLib.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/WorldEditLib.java index 7f0cac4d..87d1f9fb 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/WorldEditLib.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/WorldEditLib.java @@ -22,7 +22,7 @@ package de.steamwar.bausystem.features.script.lua.libs; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.bukkit.BukkitPlayer; import com.sk89q.worldedit.math.BlockVector3; -import de.steamwar.bausystem.regionnew.Point; +import de.steamwar.bausystem.region.Point; import de.steamwar.bausystem.utils.FlatteningWrapper; import de.steamwar.linkage.Linked; import org.bukkit.entity.Player; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTPhase.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTPhase.java index 29f59d93..20fe8d41 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTPhase.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTPhase.java @@ -23,7 +23,6 @@ import de.steamwar.bausystem.features.simulator.data.SimulatorPhase; import de.steamwar.bausystem.features.simulator.execute.SimulatorAction; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.flags.Flag; -import de.steamwar.bausystem.region.flags.flagvalues.FreezeMode; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -65,7 +64,7 @@ public final class TNTPhase extends SimulatorPhase { @Override public void accept(World world) { Location location = position.toLocation(world); - if (Region.getRegion(location).get(Flag.FREEZE) == FreezeMode.ACTIVE) return; + if (Region.getRegion(location).getFlag(Flag.FREEZE).isPresent()) return; TNTPrimed tnt = world.spawn(location, TNTPrimed.class); if (!xJump) tnt.setVelocity(tnt.getVelocity().setX(0)); if (!yJump) tnt.setVelocity(tnt.getVelocity().setY(0)); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/Cuboid.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/Cuboid.java index e5699aaa..c31653a5 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/Cuboid.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/Cuboid.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.features.slaves.laufbau; -import de.steamwar.bausystem.regionnew.Point; +import de.steamwar.bausystem.region.Point; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/CreatingLaufState.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/CreatingLaufState.java index 369ca0d9..e4ed312b 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/CreatingLaufState.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/CreatingLaufState.java @@ -27,7 +27,7 @@ import com.sk89q.worldedit.world.block.BlockTypes; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.slaves.laufbau.BlockBoundingBox; import de.steamwar.bausystem.features.slaves.laufbau.Cuboid; -import de.steamwar.bausystem.regionnew.Point; +import de.steamwar.bausystem.region.Point; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/ProcessingTracesState.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/ProcessingTracesState.java index 04c43fd3..94eb6549 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/ProcessingTracesState.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/ProcessingTracesState.java @@ -26,7 +26,7 @@ import de.steamwar.bausystem.features.slaves.laufbau.Cuboid; import de.steamwar.bausystem.features.tracer.TNTPoint; import de.steamwar.bausystem.features.tracer.Trace; import de.steamwar.bausystem.features.tracer.TraceManager; -import de.steamwar.bausystem.regionnew.Point; +import de.steamwar.bausystem.region.Point; import de.steamwar.bausystem.utils.FlatteningWrapper; import org.bukkit.Location; import org.bukkit.World; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/team/SkinCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/team/SkinCommand.java index 8394691e..ae466066 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/team/SkinCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/team/SkinCommand.java @@ -21,9 +21,7 @@ package de.steamwar.bausystem.features.team; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.team.boundary.BoundaryViewer; -import de.steamwar.bausystem.region.Prototype; import de.steamwar.bausystem.region.Region; -import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; @@ -69,14 +67,14 @@ public class SkinCommand extends SWCommand { return; } Region region = Region.getRegion(p.getLocation()); - if (region.isGlobal()) { + if (region.getType().isGlobal()) { BauSystem.MESSAGE.send("SKIN_NO_REGION", p); return; } String name = String.join(" ", names); File arenaFile = new File("sections19/" + name + "/" + typeKuerzel + "Arena.schem"); - File testblockFile = region.hasType(RegionType.TESTBLOCK) ? new File("sections19/" + name + "/" + typeKuerzel + "Testblock.schem") : null; + File testblockFile = region.getTestblockArea().isPresent() ? new File("sections19/" + name + "/" + typeKuerzel + "Testblock.schem") : null; arenaFile.getParentFile().mkdirs(); if (testblockFile != null) { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/team/boundary/BoundaryViewer.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/team/boundary/BoundaryViewer.java index 808e6398..4d2b34a7 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/team/boundary/BoundaryViewer.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/team/boundary/BoundaryViewer.java @@ -48,21 +48,18 @@ public class BoundaryViewer implements Listener { } viewers.forEach(player -> { Region region = Region.getRegion(player.getLocation()); - if (region.isGlobal()) return; + if (region.getType().isGlobal()) return; showRegion(region, player); - if (region.getLinkedRegion() != null) { - showRegion(region.getLinkedRegion(), player); - } }); }, 20, 20); } private void showRegion(Region region, Player player) { drawCuboid(player, TrickyParticleWrapper.impl.getVillagerHappy(), region.getMinPoint(), region.getMaxPoint()); - if (region.hasType(RegionType.TESTBLOCK)) { + if (region.getTestblockArea().isPresent()) { drawCuboid(player, Particle.END_ROD, region.getMinPointTestblockExtension(), region.getMaxPointTestblockExtension()); } - if (region.hasType(RegionType.BUILD)) { + if (region.getBuildArea().isPresent()) { drawCuboid(player, Particle.END_ROD, region.getMinPointBuildExtension(), region.getMaxPointBuildExtension()); } } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounterListener.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounterListener.java index 979e5fe3..a891b76f 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounterListener.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounterListener.java @@ -20,8 +20,6 @@ package de.steamwar.bausystem.features.testblock.blockcounter; import de.steamwar.bausystem.region.Region; -import de.steamwar.bausystem.region.utils.RegionExtensionType; -import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.linkage.Linked; import org.bukkit.block.Block; import org.bukkit.event.EventHandler; @@ -37,11 +35,13 @@ public class BlockCounterListener implements Listener { @EventHandler public void onEntityExplode(EntityExplodeEvent event) { Region region = Region.getRegion(event.getLocation()); - if (region.isGlobal()) { + if (region.getType().isGlobal()) { return; } List blockList = event.blockList(); - blockList = blockList.stream().filter(block -> region.inRegion(block.getLocation(), RegionType.TESTBLOCK, RegionExtensionType.EXTENSION)).collect(Collectors.toList()); + blockList = blockList.stream() + .filter(block -> region.getTestblockArea().inRegion(block.getLocation(), true)) + .collect(Collectors.toList()); if (blockList.isEmpty()) { return; } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TNTPoint.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TNTPoint.java index a33c52f0..73315d9a 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TNTPoint.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TNTPoint.java @@ -20,8 +20,6 @@ package de.steamwar.bausystem.features.tracer; import de.steamwar.bausystem.region.Region; -import de.steamwar.bausystem.region.utils.RegionExtensionType; -import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.core.Core; import lombok.AccessLevel; import lombok.AllArgsConstructor; @@ -39,7 +37,7 @@ import java.util.Optional; */ @AllArgsConstructor(access = AccessLevel.PACKAGE) @Getter -public class TNTPoint{ +public class TNTPoint { /** * Unique number to identify records being of the same tnt */ @@ -99,7 +97,7 @@ public class TNTPoint{ * Constructor for object creation in trace recording */ protected TNTPoint(int tntId, TNTPrimed tnt, boolean explosion, boolean afterFirstExplosion, long ticksSinceStart, - List history, List destroyedBlocks) { + List history, List destroyedBlocks) { this.tntId = tntId; this.explosion = explosion; if (Core.getVersion() > 15) { @@ -117,12 +115,10 @@ public class TNTPoint{ boolean buildDestroy = false; boolean testblockDestroy = false; for (Block destroyedBlock : destroyedBlocks) { - if (Region.getRegion(destroyedBlock.getLocation()).inRegion(destroyedBlock.getLocation(), RegionType.BUILD, - RegionExtensionType.EXTENSION)) { + if (Region.getRegion(destroyedBlock.getLocation()).getBuildArea().inRegion(destroyedBlock.getLocation(), true)) { buildDestroy = true; } - if (Region.getRegion(destroyedBlock.getLocation()).inRegion(destroyedBlock.getLocation(), - RegionType.TESTBLOCK, RegionExtensionType.EXTENSION)) { + if (Region.getRegion(destroyedBlock.getLocation()).getTestblockArea().inRegion(destroyedBlock.getLocation(), true)) { testblockDestroy = true; } } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/KillAllCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/KillAllCommand.java index e08b40c0..c0d99689 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/KillAllCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/KillAllCommand.java @@ -21,12 +21,9 @@ package de.steamwar.bausystem.features.util; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.SWUtils; -import de.steamwar.bausystem.region.GlobalRegion; import de.steamwar.bausystem.region.Region; -import de.steamwar.bausystem.region.RegionUtils; -import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionSelectionType; -import de.steamwar.bausystem.region.utils.RegionType; +import de.steamwar.bausystem.region.RegionUtils; import de.steamwar.command.SWCommand; import de.steamwar.linkage.Linked; import org.bukkit.Bukkit; @@ -53,7 +50,7 @@ public class KillAllCommand extends SWCommand { public void genericCommand(@Validator Player player, RegionSelectionType regionSelectionType) { Region region = Region.getRegion(player.getLocation()); AtomicLong count = new AtomicLong(0); - if (regionSelectionType == RegionSelectionType.GLOBAL || GlobalRegion.getInstance() == region) { + if (regionSelectionType == RegionSelectionType.GLOBAL || region.getType().isGlobal()) { WORLD.getEntities() .stream() .filter(e -> !(e instanceof Player)) @@ -66,7 +63,7 @@ public class KillAllCommand extends SWCommand { WORLD.getEntities() .stream() .filter(e -> !(e instanceof Player)) - .filter(e -> region.inRegion(e.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) + .filter(e -> region.inRegion(e.getLocation())) .forEach(entity -> { entity.remove(); count.incrementAndGet(); @@ -74,5 +71,4 @@ public class KillAllCommand extends SWCommand { RegionUtils.actionBar(region, "OTHER_KILLALL_REGION", count.get()); } } - } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/SelectCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/SelectCommand.java index 4f1df1af..7a11d678 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/SelectCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/SelectCommand.java @@ -1,7 +1,7 @@ package de.steamwar.bausystem.features.util; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.regionnew.Point; +import de.steamwar.bausystem.region.Point; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java index 5bd1e06d..38aa4039 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java @@ -1,7 +1,5 @@ package de.steamwar.bausystem.features.world; -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.region.GlobalRegion; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.utils.ScoreboardElement; @@ -101,8 +99,11 @@ public class BauScoreboard implements Listener { @Override public String getTitle() { Region region = Region.getRegion(player.getLocation()); - if (GlobalRegion.getInstance() == region) return "§eSteam§8War"; - String colorCode = BauSystem.MESSAGE.parse(region.get(Flag.COLOR).getChatValue(), player).substring(0, 2); + if (region.getType().isGlobal()) return "§eSteam§8War"; + String colorCode = "§e"; + if (region.hasFlag(Flag.COLOR).isReadable()) { + colorCode = "§" + region.getFlag(Flag.COLOR).get().getColor().getColorCode(); + } return colorCode + "■ §eSteam§8War " + colorCode + "■"; // ■ } }); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/ColorReplaceCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/ColorReplaceCommand.java index 3df0755c..6b6659ba 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/ColorReplaceCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/ColorReplaceCommand.java @@ -28,7 +28,7 @@ import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import de.steamwar.bausystem.features.world.WorldEditListener; import de.steamwar.bausystem.features.worldedit.utils.SpecialReplace; -import de.steamwar.bausystem.regionnew.Color; +import de.steamwar.bausystem.region.Color; import de.steamwar.bausystem.shared.Pair; import de.steamwar.bausystem.utils.WorldEditUtils; import de.steamwar.command.PreviousArguments; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/BackupScheduler.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/BackupScheduler.java index 44b57332..eb57e09f 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/BackupScheduler.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/BackupScheduler.java @@ -1,33 +1,14 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - package de.steamwar.bausystem.region; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.region.tags.Tag; +import de.steamwar.bausystem.region.flags.ChangedMode; +import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.linkage.Linked; import de.steamwar.linkage.api.Enable; import org.bukkit.scheduler.BukkitRunnable; import java.util.Iterator; - @Linked public class BackupScheduler implements Enable { @@ -39,26 +20,29 @@ public class BackupScheduler implements Enable { new BukkitRunnable() { @Override public void run() { - final Iterator regions = Region.getREGION_MAP().values().stream().filter(region -> region.get(Tag.CHANGED)).iterator(); - BackupScheduler.this.doBackup(regions); + Iterator regionsToBackup = RegionSystem.INSTANCE.getRegions() + .filter(region -> region.isFlag(Flag.CHANGED, ChangedMode.HAS_CHANGE)) + .iterator(); + if (!regionsToBackup.hasNext()) return; + doBackup(regionsToBackup); } }.runTaskTimer(BauSystem.getInstance(), INITIAL, PERIOD); } - public void doBackup(final Iterator regionIterator) { + private void doBackup(Iterator regionsToBackup) { new BukkitRunnable() { @Override public void run() { - if (!regionIterator.hasNext()) { + if (!regionsToBackup.hasNext()) { this.cancel(); return; } - final Region region = regionIterator.next(); - if (region.backup()) { - region.remove(Tag.CHANGED); + Region region = regionsToBackup.next(); + if (region.backup(true)) { + region.setFlag(Flag.CHANGED, ChangedMode.NO_CHANGE); } } }.runTaskTimer(BauSystem.getInstance(), 0, 20 * 60); } -} \ No newline at end of file +} diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/Color.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Color.java similarity index 65% rename from BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/Color.java rename to BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Color.java index 6292fbe1..72052d74 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/Color.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Color.java @@ -17,23 +17,30 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.regionnew; +package de.steamwar.bausystem.region; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +@Getter public enum Color { - WHITE, - ORANGE, - MAGENTA, - LIGHT_BLUE, - YELLOW, - LIME, - PINK, - GRAY, - LIGHT_GRAY, - CYAN, - PURPLE, - BLUE, - BROWN, - GREEN, - RED, - BLACK; + WHITE('f'), + ORANGE('6'), + MAGENTA('5'), + LIGHT_BLUE('b'), + YELLOW('e'), + LIME('a'), + PINK('d'), + GRAY('8'), + LIGHT_GRAY('7'), + CYAN('3'), + PURPLE('5'), + BLUE('9'), + BROWN('e'), + GREEN('2'), + RED('c'), + BLACK('1'); + + private final char colorCode; } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/FlagStorage.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/FlagStorage.java index e0ee43a5..3ca76ace 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/FlagStorage.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/FlagStorage.java @@ -1,107 +1,29 @@ /* - * This file is a part of the SteamWar software. + * This file is a part of the SteamWar software. * - * Copyright (C) 2021 SteamWar.de-Serverteam + * Copyright (C) 2024 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 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. + * 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 . + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . */ package de.steamwar.bausystem.region; import de.steamwar.bausystem.region.flags.Flag; -import de.steamwar.bausystem.region.tags.Tag; -import yapion.hierarchy.types.YAPIONObject; -import java.util.EnumMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; +public interface FlagStorage { -/** - * Tags and Flags are not allowed to have overlaping names. - */ -public class FlagStorage { + & Flag.Value> boolean set(Flag flag, T value); - public static FlagStorage createStorage(YAPIONObject yapionObject) { - FlagStorage flagStorage = new FlagStorage(); - for (final Flag flag : Flag.getFlags()) { - try { - String s = yapionObject.getPlainValue(flag.name()); - flagStorage.set(flag, flag.getFlagValueOf(s)); - } catch (Exception e) { - flagStorage.set(flag, flag.getDefaultValue()); - } - } - for (final Tag tag : Tag.values()) { - if (yapionObject.containsKey(tag.name())) { - flagStorage.set(tag); - } - } - return flagStorage; - } - - public static YAPIONObject toYAPION(FlagStorage flagStorage) { - YAPIONObject yapionObject = new YAPIONObject(); - for (final Flag flag : Flag.getFlags()) { - if (flag.getDefaultValue() == flagStorage.flags.getOrDefault(flag, flag.getDefaultValue())) { - yapionObject.remove(flag.name()); - } else { - yapionObject.add(flag.name(), flagStorage.get(flag).getValue().name()); - } - } - for (Tag tag : Tag.values()) { - if (flagStorage.tagSet.contains(tag)) { - yapionObject.add(tag.name(), ""); - } else { - yapionObject.remove(tag.name()); - } - } - return yapionObject; - } - - protected Map> flags; - protected Set tagSet; - - public FlagStorage() { - flags = new EnumMap<>(Flag.class); - tagSet = new HashSet<>(); - readKeys(); - } - - public boolean set(final Flag flagType, final Flag.Value value) { - return flags.put(flagType, value) != value; - } - - public Flag.Value get(final Flag flagType) { - return flags.getOrDefault(flagType, flagType.getDefaultValue()); - } - - public boolean set(final Tag tag) { - return tagSet.add(tag); - } - - public boolean remove(final Tag tag) { - return tagSet.remove(tag); - } - - public boolean is(final Tag tag) { - return tagSet.contains(tag); - } - - private void readKeys() { - for (final Flag flag : Flag.getFlags()) { - flags.put(flag, flag.getDefaultValue()); - } - } -} \ No newline at end of file + & Flag.Value> T get(Flag flag); +} diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/GlobalRegion.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/GlobalRegion.java deleted file mode 100644 index 83623989..00000000 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/GlobalRegion.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.region; - -import de.steamwar.bausystem.region.utils.RegionExtensionType; -import de.steamwar.bausystem.region.utils.RegionType; -import lombok.Getter; -import org.bukkit.Location; -import yapion.hierarchy.types.YAPIONObject; - -public class GlobalRegion extends Region { - - @Getter - static GlobalRegion instance; - - public GlobalRegion(FlagStorage flagStorage, YAPIONObject regionData) { - super("global", null, new YAPIONObject(), flagStorage, regionData); - instance = this; - } - - @Override - public boolean inRegion(Location location, RegionType regionType, RegionExtensionType regionExtensionType) { - return true; - } -} diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/Point.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Point.java similarity index 98% rename from BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/Point.java rename to BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Point.java index a9f3534c..3dad7a51 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/Point.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Point.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.regionnew; +package de.steamwar.bausystem.region; import com.sk89q.worldedit.math.BlockVector3; import lombok.AllArgsConstructor; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java index bf8477e9..72a007a0 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java @@ -1,585 +1,128 @@ /* - * This file is a part of the SteamWar software. + * This file is a part of the SteamWar software. * - * Copyright (C) 2021 SteamWar.de-Serverteam + * Copyright (C) 2024 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 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. + * 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 . + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . */ package de.steamwar.bausystem.region; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.bukkit.BukkitWorld; -import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.flags.Flag; -import de.steamwar.bausystem.region.flags.flagvalues.TNTMode; -import de.steamwar.bausystem.region.tags.Tag; -import de.steamwar.bausystem.region.utils.RegionExtensionType; -import de.steamwar.bausystem.region.utils.RegionType; -import de.steamwar.bausystem.regionnew.Point; -import de.steamwar.bausystem.shared.SizedStack; -import de.steamwar.bausystem.utils.FlatteningWrapper; -import de.steamwar.bausystem.utils.PasteBuilder; -import de.steamwar.core.Core; -import de.steamwar.sql.SchematicType; -import lombok.AccessLevel; -import lombok.Getter; +import de.steamwar.sql.SchematicNode; import lombok.NonNull; -import org.bukkit.Bukkit; import org.bukkit.Location; -import yapion.hierarchy.types.YAPIONObject; -import yapion.hierarchy.types.YAPIONType; -import yapion.hierarchy.types.YAPIONValue; +import javax.annotation.Nullable; import java.io.File; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.*; -import java.util.function.ObjIntConsumer; -import java.util.function.Predicate; -import java.util.stream.Collectors; +import java.util.Optional; -@Getter -public class Region { +public interface Region { - @Getter - private static final Map REGION_MAP = new HashMap<>(); - private static final File backupFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "backup"); - private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy.MM.dd' 'HH:mm:ss"); - - public static Region getRegion(Location location) { - return REGION_MAP.values().stream() - .filter(r -> r.inRegion(location, r.minPoint, r.maxPoint)) - .findFirst() - .orElse(GlobalRegion.instance); + static Region getRegion(Location location) { + return RegionSystem.INSTANCE.get(location); } - public static Set getRegion(Prototype prototype) { - return REGION_MAP.values().stream() - .filter(r -> r.getPrototype() == prototype) - .collect(Collectors.toSet()); + RegionType getType(); + + & Flag.Value> RegionFlagPolicy hasFlag(@NonNull Flag flag); + + & Flag.Value> boolean setFlag(@NonNull Flag flag, T value); + + & Flag.Value> Optional getFlag(@NonNull Flag flag); + + default & Flag.Value> boolean isFlag(@NonNull Flag flag, T value) { + if (hasFlag(flag).isReadable()) { + Optional optional = getFlag(flag); + return optional.isPresent() && optional.get() == value; + } + return false; } - public static void setGlobal(Flag flagType, Flag.Value value) { - REGION_MAP.values().forEach(region -> region.set(flagType, value)); - } + Point getMinPoint(); - YAPIONObject regionData; + Point getMaxPoint(); - private String name; - private Prototype prototype; - private Set prototypes; - private String skin; + boolean inRegion(Location location); - private Point minPoint; - private Point maxPoint; + Inner getBuildArea(); - private Point minPointTestblock; - private Point maxPointTestblock; + Inner getTestblockArea(); - private Point minPointTestblockExtension; - private Point maxPointTestblockExtension; + // TODO: Add forEachChunk and getChunkOutsidePredicate - private Point minPointBuild; - private Point maxPointBuild; + Optional getGameModeConfig(); - private Point minPointBuildExtension; - private Point maxPointBuildExtension; + boolean backup(boolean automatic); - private int floorLevel; - private int waterLevel; + Optional copy(); - private Point copyPoint; // Nullable - private Point testBlockPoint; // Nullable + void reset(); - private String linkedRegionName = null; // Nullable - private Region linkedRegion = null; // Nullable + void remember(EditSession editSession); - private FlagStorage flagStorage; + boolean undo(); - @Getter(AccessLevel.PRIVATE) - private SizedStack undoSessions; + boolean redo(); - @Getter(AccessLevel.PRIVATE) - private SizedStack redoSessions; + interface Inner { - public Region(String name, Prototype prototype, YAPIONObject regionConfig, FlagStorage flagStorage, YAPIONObject regionData) { - this.name = name; - this.regionData = regionData; - if (prototype != null) { - REGION_MAP.put(name, this); - } + Inner EMPTY = new Inner() { + private static final Point ZERO = new Point(0, 0, 0); - linkedRegionName = regionConfig.getPlainValueOrDefault("optionsLinkedWith", null); - - prototypes = new HashSet<>(); - if (regionConfig.containsKey("prototypes", YAPIONType.ARRAY)) { - regionConfig.getArray("prototypes").forEach(yapionAnyType -> { - if (yapionAnyType instanceof YAPIONValue) { - prototypes.add(((YAPIONValue) yapionAnyType).get()); - } - }); - } - if (regionConfig.containsKey("prototype")) { - prototypes.add(regionConfig.getPlainValue("prototype")); - } - - this.flagStorage = flagStorage; - Point point = null; - if (regionConfig.containsKey("minX", Integer.class) && regionConfig.containsKey("minY", Integer.class) && regionConfig.containsKey("minZ", Integer.class)) { - point = new Point(regionConfig.getPlainValue("minX"), regionConfig.getPlainValue("minY"), regionConfig.getPlainValue("minZ")); - } - if (prototype != null && prototypes.contains(prototype.getName())) { - generatePrototypeData(prototype, point); - } else if (regionConfig.containsKey("prototype")) { - generatePrototypeData(Prototype.getByName(regionConfig.getPlainValue("prototype")), point); - } - if (prototype != null) { - skin = regionData.getPlainValueOrDefault("skin", prototype.getDefaultSkin()); - if (!prototype.getSkinMap().containsKey(skin)) { - skin = prototype.getDefaultSkin(); + @Override + public Point getMinPoint(boolean extension) { + return ZERO; } - } - regionData.add("skin", skin); - if (!hasType(RegionType.BUILD) || !hasType(RegionType.TESTBLOCK)) { - flagStorage.set(Flag.TNT, TNTMode.DENY); - } - } - - private void generatePrototypeData(Prototype prototype, Point point) { - if (prototype == null) { - return; - } - - this.prototype = prototype; - this.skin = prototype.getDefaultSkin(); - - this.minPoint = point; - this.maxPoint = point.add(prototype.getSizeX() - 1, prototype.getSizeY() - 1, prototype.getSizeZ() - 1); - - if (prototype.getTestblock() != null) { - this.minPointTestblock = point.add(prototype.getTestblock().getOffsetX(), prototype.getTestblock().getOffsetY(), prototype.getTestblock().getOffsetZ()); - this.maxPointTestblock = this.minPointTestblock.add(prototype.getTestblock().getSizeX() - 1, prototype.getTestblock().getSizeY() - 1, prototype.getTestblock().getSizeZ() - 1); - - this.minPointTestblockExtension = this.minPointTestblock.subtract(prototype.getTestblock().getExtensionNegativeX(), prototype.getTestblock().getExtensionNegativeY(), prototype.getTestblock().getExtensionNegativeZ()); - this.maxPointTestblockExtension = this.maxPointTestblock.add(prototype.getTestblock().getExtensionPositiveX(), prototype.getTestblock().getExtensionPositiveY(), prototype.getTestblock().getExtensionPositiveZ()); - - if (prototype.getTestblock().getCopyOffsetX() != 0 || prototype.getTestblock().getCopyOffsetY() != 0 || prototype.getTestblock().getCopyOffsetZ() != 0) { - this.testBlockPoint = this.minPointTestblock.add(prototype.getTestblock().getCopyOffsetX(), prototype.getTestblock().getCopyOffsetY(), prototype.getTestblock().getCopyOffsetZ()); - } else { - this.testBlockPoint = this.minPointTestblock.add(prototype.getTestblock().getSizeX() / 2, 0, -1); + @Override + public Point getMaxPoint(boolean extension) { + return ZERO; } - } - if (prototype.getBuild() != null) { - this.minPointBuild = point.add(prototype.getBuild().getOffsetX(), prototype.getBuild().getOffsetY(), prototype.getBuild().getOffsetZ()); - this.maxPointBuild = this.minPointBuild.add(prototype.getBuild().getSizeX() - 1, prototype.getBuild().getSizeY() - 1, prototype.getBuild().getSizeZ() - 1); - - this.minPointBuildExtension = this.minPointBuild.subtract(prototype.getBuild().getExtensionNegativeX(), prototype.getBuild().getExtensionNegativeY(), prototype.getBuild().getExtensionNegativeZ()); - this.maxPointBuildExtension = this.maxPointBuild.add(prototype.getBuild().getExtensionPositiveX(), prototype.getBuild().getExtensionPositiveY(), prototype.getBuild().getExtensionPositiveZ()); - - if (!prototype.getBuild().isHasCopyPoint() && (prototype.getCopyPointOffsetX() != 0 || prototype.getCopyPointOffsetY() != 0 || prototype.getCopyPointOffsetZ() != 0)) { - this.copyPoint = minPoint.add(prototype.getCopyPointOffsetX(), prototype.getCopyPointOffsetY(), prototype.getCopyPointOffsetZ()); - } else if (prototype.getBuild().getCopyOffsetX() != 0 || prototype.getBuild().getCopyOffsetY() != 0 || prototype.getBuild().getCopyOffsetZ() != 0) { - this.copyPoint = this.minPointBuild.add(prototype.getBuild().getCopyOffsetX(), prototype.getBuild().getCopyOffsetY(), prototype.getBuild().getCopyOffsetZ()); - } else { - this.copyPoint = this.minPointBuild.add(prototype.getBuild().getSizeX() / 2, 0, prototype.getBuild().getSizeZ()); - } - } else if (prototype.getCopyPointOffsetX() != 0 || prototype.getCopyPointOffsetY() != 0 || prototype.getCopyPointOffsetZ() != 0) { - this.copyPoint = minPoint.add(prototype.getCopyPointOffsetX(), prototype.getCopyPointOffsetY(), prototype.getCopyPointOffsetZ()); - } - - if (prototype.getFloorOffset() != 0) { - floorLevel = minPoint.getY() + prototype.getFloorOffset(); - } else { - floorLevel = 0; - } - - if (prototype.getWaterOffset() != 0) { - waterLevel = minPoint.getY() + prototype.getWaterOffset(); - } else { - waterLevel = 0; - } - } - - public boolean inRegion(Location location, RegionType regionType, RegionExtensionType regionExtensionType) { - if (!hasType(regionType)) { - return false; - } - switch (regionType) { - case BUILD: - Point minBPoint = regionExtensionType == RegionExtensionType.EXTENSION ? minPointBuildExtension : minPointBuild; - Point maxBPoint = regionExtensionType == RegionExtensionType.EXTENSION ? maxPointBuildExtension : maxPointBuild; - return inRegion(location, minBPoint, maxBPoint); - case TESTBLOCK: - Point minTBPoint = regionExtensionType == RegionExtensionType.EXTENSION ? minPointTestblockExtension : minPointTestblock; - Point maxTBPoint = regionExtensionType == RegionExtensionType.EXTENSION ? maxPointTestblockExtension : maxPointTestblock; - return inRegion(location, minTBPoint, maxTBPoint); - default: - case NORMAL: - return inRegion(location, minPoint, maxPoint); - } - } - - private boolean inRegion(Location location, Point minPoint, Point maxPoint) { - int blockX = location.getBlockX(); - int blockY = location.getBlockY(); - int blockZ = location.getBlockZ(); - return blockX >= minPoint.getX() && blockX <= maxPoint.getX() && - blockY >= minPoint.getY() && blockY <= maxPoint.getY() && - blockZ >= minPoint.getZ() && blockZ <= maxPoint.getZ(); - } - - public boolean hasType(RegionType regionType) { - if (prototype == null) { - return false; - } - if (regionType == null) { - return false; - } - switch (regionType) { - case BUILD: - return prototype.getBuild() != null; - case TESTBLOCK: - return prototype.getTestblock() != null; - default: - case NORMAL: - return true; - } - } - - public boolean hasExtensionType(RegionType regionType) { - if (!hasType(regionType)) { - return false; - } - switch (regionType) { - case BUILD: - return prototype.getBuild().isExtensionRegistered(); - case TESTBLOCK: - return prototype.getTestblock().isExtensionRegistered(); - default: - case NORMAL: + @Override + public boolean inRegion(Location location, boolean extension) { return false; - } - } - - public String getDisplayName() { - return prototype != null ? prototype.getSkinMap().get(skin).getName() : ""; - } - - private void setLinkedRegion(Predicate regionConsumer) { - if (linkedRegionName == null) { - return; - } - if (linkedRegion != null) { - if (regionConsumer.test(linkedRegion)) { - RegionUtils.save(linkedRegion); } - return; - } - for (Region region : REGION_MAP.values()) { - if (region.name.equals(linkedRegionName)) { - linkedRegion = region; - if (regionConsumer.test(linkedRegion)) { - RegionUtils.save(linkedRegion); - } - return; + + @Override + public Optional copy(boolean extension) { + return Optional.empty(); } - } - } - public Region getLinkedRegion() { - if (linkedRegion == null && linkedRegionName != null) { - setLinkedRegion(region -> false); - } - return linkedRegion; - } - - public boolean setPrototype(@NonNull Prototype prototype) { - if (!prototypes.contains(prototype.getName())) { - return false; - } - return _setPrototype(prototype); - } - - boolean _setPrototype(@NonNull Prototype prototype) { - generatePrototypeData(prototype, minPoint); - RegionUtils.save(this); - return true; - } - - public boolean setSkin(@NonNull String skinName) { - if (!prototype.getSkinMap().containsKey(skinName)) { - return false; - } - this.skin = skinName; - setLinkedRegion(region -> { - region.skin = skinName; - return true; - }); - regionData.add("skin", skin); - return true; - } - - public void set(Flag flagType, Flag.Value value) { - if (flagStorage.set(flagType, value)) { - RegionUtils.save(this); - } - setLinkedRegion(region -> region.flagStorage.set(flagType, value)); - } - - public void set(Tag tag) { - if (flagStorage.set(tag)) { - RegionUtils.save(this); - } - setLinkedRegion(region -> region.flagStorage.set(tag)); - } - - public void remove(Tag tag) { - if (flagStorage.remove(tag)) { - RegionUtils.save(this); - } - } - - public Flag.Value get(Flag flagType) { - return flagStorage.get(flagType); - } - - public boolean get(Tag tagType) { - return flagStorage.is(tagType); - } - - public & Flag.Value> T getPlain(Flag flagType) { - return (T) flagStorage.get(flagType).getValue(); - } - - public & Flag.Value> T getPlain(Flag flagType, Class type) { - return (T) flagStorage.get(flagType).getValue(); - } - - public Point getMinPoint(RegionType regionType, RegionExtensionType regionExtensionType) { - switch (regionType) { - case TESTBLOCK: - return (regionExtensionType == null || regionExtensionType == RegionExtensionType.NORMAL) ? minPointTestblock : minPointTestblockExtension; - case BUILD: - return (regionExtensionType == null || regionExtensionType == RegionExtensionType.NORMAL) ? minPointBuild : minPointBuildExtension; - default: - case NORMAL: - return minPoint; - } - } - - public Point getMaxPoint(RegionType regionType, RegionExtensionType regionExtensionType) { - switch (regionType) { - case TESTBLOCK: - return (regionExtensionType == null || regionExtensionType == RegionExtensionType.NORMAL) ? maxPointTestblock : maxPointTestblockExtension; - case BUILD: - return (regionExtensionType == null || regionExtensionType == RegionExtensionType.NORMAL) ? maxPointBuild : maxPointBuildExtension; - default: - case NORMAL: - return maxPoint; - } - } - - boolean hasReset(RegionType regionType) { - if (!hasType(regionType)) { - return false; - } - switch (regionType) { - case TESTBLOCK: - return prototype.getSkinMap().get(skin).getTestblockSchematicFile() != null; - case BUILD: - return prototype.getSkinMap().get(skin).getBuildSchematicFile() != null; - default: - case NORMAL: - return prototype.getSkinMap().get(skin).getSchematicFile() != null; - } - } - - public File getResetFile(RegionType regionType) { - if (!hasReset(regionType)) { - return null; - } - switch (regionType) { - case TESTBLOCK: - return prototype.getSkinMap().get(skin).getTestblockSchematicFile(); - case BUILD: - return prototype.getSkinMap().get(skin).getBuildSchematicFile(); - default: - case NORMAL: - return prototype.getSkinMap().get(skin).getSchematicFile(); - } - } - - public void reset(PasteBuilder pasteBuilder, RegionType regionType, RegionExtensionType regionExtensionType) { - if (!hasReset(regionType)) { - return; - } - if (regionExtensionType == RegionExtensionType.EXTENSION && !hasExtensionType(regionType)) { - regionExtensionType = RegionExtensionType.NORMAL; - } - - pasteBuilder.reset(regionExtensionType == RegionExtensionType.EXTENSION) - .minPoint(getMinPoint(regionType, regionExtensionType)) - .maxPoint(getMaxPoint(regionType, regionExtensionType)) - .waterLevel(waterLevel); - if (pasteBuilder.getClipboardProvider().is(PasteBuilder.SchematicProvider.class)) { - SchematicType schematicType = pasteBuilder.getClipboardProvider().as(PasteBuilder.SchematicProvider.class).getSchematic().getSchemtype(); - pasteBuilder.rotate(schematicType.fightType() || schematicType.check()); - } - - switch (regionType) { - case BUILD: - pasteBuilder.pastePoint(minPointBuild.add(prototype.getBuild().getSizeX() / 2, 0, prototype.getBuild().getSizeZ() / 2)); - break; - case TESTBLOCK: - Point pastePoint = minPointTestblock.add(prototype.getTestblock().getSizeX() / 2, 0, prototype.getTestblock().getSizeZ() / 2); - if (pasteBuilder.getClipboardProvider().is(PasteBuilder.SchematicProvider.class)) { - SchematicType schematicType = pasteBuilder.getClipboardProvider().as(PasteBuilder.SchematicProvider.class).getSchematic().getSchemtype(); - if (schematicType.getKuerzel().equalsIgnoreCase("wg")) { - pastePoint = pastePoint.add(0, 0, 1); - } - if (schematicType.getKuerzel().equalsIgnoreCase("ws")) { - pastePoint = pastePoint.add(-1, 0, 1); - } - if (schematicType.getKuerzel().equalsIgnoreCase("as")) { - pastePoint = pastePoint.add(-1, 0, 1); - } - } - pasteBuilder.pastePoint(pastePoint); - break; - default: - case NORMAL: - pasteBuilder.pastePoint(minPoint.add(prototype.getSizeX() / 2, 0, prototype.getSizeZ() / 2)); - break; - } - - initSessions(); - undoSessions.push(pasteBuilder.run()); - } - - public void remember(EditSession editSession) { - initSessions(); - undoSessions.push(editSession); - } - - public boolean isGlobal() { - return this == GlobalRegion.getInstance(); - } - - private void initSessions() { - if (undoSessions == null) { - undoSessions = new SizedStack<>(20); - redoSessions = new SizedStack<>(20); - } - } - - public boolean undo() { - initSessions(); - EditSession session = undoSessions.pop(); - if (session == null) - return false; - - try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) { - session.undo(e); - redoSessions.push(e); - } - return true; - } - - public boolean redo() { - initSessions(); - EditSession session = redoSessions.pop(); - if (session == null) - return false; - - try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) { - session.redo(e); - undoSessions.push(e); - } - return true; - } - - public boolean backup() { - final File definedBackupFolder = new File(new File(backupFolder, prototype.getName()), name); - //noinspection ResultOfMethodCallIgnored - definedBackupFolder.mkdirs(); - - File[] currentBackups = definedBackupFolder.listFiles(); - if (currentBackups != null && currentBackups.length >= 20) { - List files = new ArrayList<>(Arrays.asList(currentBackups)); - files.sort(Comparator.comparingLong(File::lastModified)); - while (files.size() >= 20) files.remove(0).delete(); - } - - final File backupFile = new File(definedBackupFolder, LocalDateTime.now().format(formatter) + ".schem"); - return FlatteningWrapper.impl.backup(minPoint, maxPoint, backupFile); - } - - public static boolean copy(Point minPoint, Point maxPoint, File file) { - return FlatteningWrapper.impl.backup(minPoint, maxPoint, file); - } - - public List listBackup() { - final File definedBackupFolder = new File(new File(backupFolder, prototype.getName()), name); - //noinspection ResultOfMethodCallIgnored - definedBackupFolder.mkdirs(); - - File[] currentBackups = definedBackupFolder.listFiles(); - List files = new ArrayList<>(Arrays.asList(currentBackups)); - files.sort(Comparator.comparingLong(File::lastModified)); - return files.stream().map(File::getName).collect(Collectors.toList()); - } - - public File getBackupFile(String backupName) { - final File definedBackupFolder = new File(new File(backupFolder, prototype.getName()), name); - //noinspection ResultOfMethodCallIgnored - definedBackupFolder.mkdirs(); - File[] files = definedBackupFolder.listFiles((dir, name) -> name.equals(backupName + ".schem")); - if (files == null || files.length == 0) return null; - return files[0]; - } - - public void forEachChunk(ObjIntConsumer executor) { - for (int x = (int) Math.floor(minPoint.getX() / 16.0); x <= (int) Math.ceil(maxPoint.getX() / 16.0); x++) { - for (int z = (int) Math.floor(minPoint.getZ() / 16.0); z <= (int) Math.ceil(maxPoint.getZ() / 16.0); z++) { - executor.accept(x, z); + @Override + public void reset(@Nullable SchematicNode schematicNode, boolean extension) { } - } - } + }; - public boolean buildChunkOutside(int chunkX, int chunkY) { - if (!hasType(RegionType.BUILD)) { - return Math.floor(minPoint.getX() / 16.0) > chunkX || chunkX >= Math.ceil(maxPoint.getX() / 16.0) || - Math.floor(minPoint.getZ() / 16.0) > chunkY || chunkY >= Math.ceil(maxPoint.getZ() / 16.0); + default boolean isEmpty() { + return this == EMPTY; } - if (!hasExtensionType(RegionType.BUILD)) { - return Math.floor(minPointBuild.getX() / 16.0) > chunkX || chunkX >= Math.ceil(maxPointBuild.getX() / 16.0) || - Math.floor(minPointBuild.getZ() / 16.0) > chunkY || chunkY >= Math.ceil(maxPointBuild.getZ() / 16.0); - } - return Math.floor(minPointBuildExtension.getX() / 16.0) > chunkX || chunkX >= Math.ceil(maxPointBuildExtension.getX() / 16.0) || - Math.floor(minPointBuildExtension.getZ() / 16.0) > chunkY || chunkY >= Math.ceil(maxPointBuildExtension.getZ() / 16.0); - } - public File gameModeConfig() { - File baseFile = new File(BauSystem.getInstance().getDataFolder().getParentFile(), "FightSystem"); - for (int version = Core.getVersion(); version >= 15; version--) { - File specific = new File(baseFile, prototype.getDisplayName() + version + ".yml"); - if (specific.exists()) return specific; + default boolean isPresent() { + return this != EMPTY; } - return null; + + Point getMinPoint(boolean extension); + + Point getMaxPoint(boolean extension); + + boolean inRegion(Location location, boolean extension); + + Optional copy(boolean extension); + + void reset(@Nullable SchematicNode schematicNode, boolean extension); } -} \ No newline at end of file +} diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/RegionFlagPolicy.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionFlagPolicy.java similarity index 90% rename from BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/RegionFlagPolicy.java rename to BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionFlagPolicy.java index 7878a79a..ecc3d136 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/RegionFlagPolicy.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionFlagPolicy.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.regionnew; +package de.steamwar.bausystem.region; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -31,4 +31,8 @@ public enum RegionFlagPolicy { private final boolean readable; private final boolean writable; + + public boolean isApplicable() { + return readable || writable; + } } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/RegionSystem.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionSystem.java similarity index 94% rename from BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/RegionSystem.java rename to BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionSystem.java index bbe4960d..9c480219 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/RegionSystem.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionSystem.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.regionnew; +package de.steamwar.bausystem.region; import org.bukkit.Location; @@ -27,7 +27,7 @@ import java.util.stream.Stream; public interface RegionSystem { - RegionSystem REGION_SYSTEM = init(); + RegionSystem INSTANCE = init(); void load(); void save(); @@ -43,7 +43,7 @@ public interface RegionSystem { private static RegionSystem init() { try { - return (RegionSystem) Class.forName("de.steamwar.bausystem.regionnew.FixedRegionSystem").getConstructor().newInstance(); + return (RegionSystem) Class.forName("de.steamwar.bausystem.region.FixedRegionSystem").getConstructor().newInstance(); } catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) { return new RegionSystem() { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/RegionType.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionType.java similarity index 93% rename from BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/RegionType.java rename to BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionType.java index ff91fcd5..dda01029 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/RegionType.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionType.java @@ -17,11 +17,13 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.regionnew; +package de.steamwar.bausystem.region; +import lombok.Getter; import lombok.RequiredArgsConstructor; @RequiredArgsConstructor +@Getter public enum RegionType { GLOBAL(true), diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionUtils.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionUtils.java index e30c3ed9..1559025b 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionUtils.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionUtils.java @@ -1,92 +1,48 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - package de.steamwar.bausystem.region; -import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.extent.clipboard.Clipboard; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.region.utils.RegionExtensionType; -import de.steamwar.bausystem.region.utils.RegionType; -import de.steamwar.bausystem.utils.FlatteningWrapper; -import de.steamwar.bausystem.worlddata.WorldData; import lombok.experimental.UtilityClass; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import java.io.File; import java.util.function.Consumer; import java.util.function.Function; - @UtilityClass public class RegionUtils { public void actionBar(Region region, String s, Object... objects) { + forEachInRegion(region, player -> { + player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(BauSystem.MESSAGE.parse(s, player, objects))); + }); + } + + public void message(Region region, String s, Object... objects) { + forEachInRegion(region, player -> BauSystem.MESSAGE.send(s, player, objects)); + } + + public void message(Region region, Function function) { + forEachInRegion(region, player -> { + String message = function.apply(player); + if (message == null) { + return; + } + + player.sendMessage(message); + }); + } + + public void message(Region region, Consumer consumer) { + forEachInRegion(region, consumer); + } + + public void forEachInRegion(Region region, Consumer consumer) { Bukkit.getOnlinePlayers() .stream() - .filter(player -> region.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) - .filter(player -> !region.isGlobal() || Region.getRegion(player.getLocation()).isGlobal()) - .forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(BauSystem.MESSAGE.parse(s, player, objects)))); + .filter(player -> region.inRegion(player.getLocation())) + .filter(player -> !region.getType().isGlobal() || Region.getRegion(player.getLocation()).getType().isGlobal()) + .forEach(consumer); } - - public static void message(Region region, String message, Object... objects) { - Bukkit.getOnlinePlayers() - .stream() - .filter(player -> region.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) - .filter(player -> !region.isGlobal() || Region.getRegion(player.getLocation()).isGlobal()) - .forEach(player -> BauSystem.MESSAGE.send(message, player, objects)); - } - - public static void message(Region region, Function function) { - Bukkit.getOnlinePlayers() - .stream() - .filter(player -> region.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) - .filter(player -> !region.isGlobal() || Region.getRegion(player.getLocation()).isGlobal()) - .forEach(player -> { - String message = function.apply(player); - if (message == null) { - return; - } - - player.sendMessage(message); - }); - } - - public static void message(Region region, Consumer function) { - Bukkit.getOnlinePlayers() - .stream() - .filter(player -> region.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) - .filter(player -> !region.isGlobal() || Region.getRegion(player.getLocation()).isGlobal()) - .forEach(player -> { - function.accept(player); - }); - } - - static void save(Region region) { - if (region.getPrototype() != null) { - region.regionData.add("prototype", region.getPrototype().getName()); - } - region.regionData.add("flagStorage", FlagStorage.toYAPION(region.getFlagStorage())); - WorldData.write(); - } - } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/flags/ChangedMode.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/ChangedMode.java similarity index 97% rename from BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/flags/ChangedMode.java rename to BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/ChangedMode.java index 85e70f01..ee7e7399 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/flags/ChangedMode.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/ChangedMode.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.regionnew.flags; +package de.steamwar.bausystem.region.flags; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/flags/ColorMode.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/ColorMode.java similarity index 96% rename from BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/flags/ColorMode.java rename to BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/ColorMode.java index 229301c3..e266d874 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/flags/ColorMode.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/ColorMode.java @@ -17,9 +17,9 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.regionnew.flags; +package de.steamwar.bausystem.region.flags; -import de.steamwar.bausystem.regionnew.Color; +import de.steamwar.bausystem.region.Color; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/flags/FireMode.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/FireMode.java similarity index 96% rename from BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/flags/FireMode.java rename to BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/FireMode.java index f628bd47..48deb0b7 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/flags/FireMode.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/FireMode.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.regionnew.flags; +package de.steamwar.bausystem.region.flags; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java index 3c9f3173..7cfa0347 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java @@ -1,85 +1,103 @@ /* - * This file is a part of the SteamWar software. + * This file is a part of the SteamWar software. * - * Copyright (C) 2021 SteamWar.de-Serverteam + * Copyright (C) 2025 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 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. + * 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 . + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . */ package de.steamwar.bausystem.region.flags; -import de.steamwar.bausystem.region.flags.flagvalues.*; import de.steamwar.bausystem.shared.EnumDisplay; import lombok.AllArgsConstructor; import lombok.Getter; -import java.util.EnumSet; +import java.util.HashSet; import java.util.Set; -import java.util.stream.Collectors; +import java.util.concurrent.atomic.AtomicInteger; -@Getter -@AllArgsConstructor -public enum Flag implements EnumDisplay { +public final class Flag & Flag.Value> implements EnumDisplay { - COLOR("FLAG_COLOR", ColorMode.class, ColorMode.YELLOW, false), - TNT("FLAG_TNT", TNTMode.class, TNTMode.ONLY_TB, true), - FIRE("FLAG_FIRE", FireMode.class, FireMode.ALLOW, true), - FREEZE("FLAG_FREEZE", FreezeMode.class, FreezeMode.INACTIVE, true), - PROTECT("FLAG_PROTECT", ProtectMode.class, ProtectMode.ACTIVE, true), - ITEMS("FLAG_ITEMS", ItemMode.class, ItemMode.INACTIVE, true), - NO_GRAVITY("FLAG_NO_GRAVITY", NoGravityMode.class, NoGravityMode.INACTIVE, true), - ; + public static final Flag COLOR = new Flag<>("COLOR", "FLAG_COLOR", ColorMode.class, ColorMode.YELLOW); + public static final Flag TNT = new Flag<>("TNT", "FLAG_TNT", TNTMode.class, TNTMode.ONLY_TB); + public static final Flag FIRE = new Flag<>("FIRE", "FLAG_FIRE", FireMode.class, FireMode.ALLOW); + public static final Flag FREEZE = new Flag<>("FREEZE", "FLAG_FREEZE", FreezeMode.class, FreezeMode.INACTIVE); + public static final Flag PROTECT = new Flag<>("PROTECT", "FLAG_PROTECT", ProtectMode.class, ProtectMode.ACTIVE); + public static final Flag ITEMS = new Flag<>("ITEMS", "FLAG_ITEMS", ItemMode.class, ItemMode.INACTIVE); + public static final Flag NO_GRAVITY = new Flag<>("NO_GRAVITY", "FLAG_NO_GRAVITY", NoGravityMode.class, NoGravityMode.INACTIVE); + public static final Flag TESTBLOCK = new Flag<>("TESTBLOCK", "FLAG_TESTBLOCK", TestblockMode.class, TestblockMode.NO_VALUE); + public static final Flag CHANGED = new Flag<>("CHANGED", "FLAG_CHANGED", ChangedMode.class, ChangedMode.NO_CHANGE); - @Getter - private static final Set flags; - @Getter - private static final Set resetFlags; + @Getter + private static final Set flags = new HashSet<>(); - static { - flags = EnumSet.allOf(Flag.class); - resetFlags = flags.stream().filter(flag -> flag.reset).collect(Collectors.toUnmodifiableSet()); - } + private static AtomicInteger counter = new AtomicInteger(0); - private final String chatValue; - private final Class> valueType; - private final Flag.Value defaultValue; - private final boolean reset; + private String name; + private int ordinal; - public Value getFlagValueOf(final String name) { - return this.defaultValue.getValueOf(name); - } + @Getter + private String chatValue; - @Override - public String toString() { - return this.name().toLowerCase(); - } + @Getter + private final Class> valueType; - @Override - public String getChatValue() { - return chatValue; - } + @Getter + private final Flag.Value defaultValue; - public interface Value & Value> extends EnumDisplay { + @Getter + private final Flag.Value[] values; - T getValue(); + private Flag(String name, String chatValue, Class> valueType, Value defaultValue) { + flags.add(this); - T getValueOf(final String name); + this.name = name; + this.ordinal = counter.getAndIncrement(); + this.chatValue = chatValue; - T[] getValues(); + this.valueType = valueType; + this.defaultValue = defaultValue; + this.values = defaultValue.getValues(); + } - default String getName() { - return this.getValue().name().toLowerCase(); - } - } -} \ No newline at end of file + public String name() { + return name; + } + + public int ordinal() { + return ordinal; + } + + public boolean oneOf(Flag... flags) { + for (Flag flag : flags) { + if (flag == this) { + return true; + } + } + return false; + } + + public interface Value & Value> extends EnumDisplay { + + T getValue(); + + T getValueOf(final String name); + + T[] getValues(); + + default String getName() { + return this.getValue().name().toLowerCase(); + } + } +} diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/flags/FreezeMode.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/FreezeMode.java similarity index 97% rename from BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/flags/FreezeMode.java rename to BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/FreezeMode.java index f3da631c..4f80ca57 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/flags/FreezeMode.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/FreezeMode.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.regionnew.flags; +package de.steamwar.bausystem.region.flags; import lombok.AllArgsConstructor; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/flags/ItemMode.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/ItemMode.java similarity index 97% rename from BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/flags/ItemMode.java rename to BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/ItemMode.java index 7d29899c..a846a53c 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/flags/ItemMode.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/ItemMode.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.regionnew.flags; +package de.steamwar.bausystem.region.flags; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/flags/NoGravityMode.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/NoGravityMode.java similarity index 97% rename from BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/flags/NoGravityMode.java rename to BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/NoGravityMode.java index 68e9fa6b..921d36ea 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/flags/NoGravityMode.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/NoGravityMode.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.regionnew.flags; +package de.steamwar.bausystem.region.flags; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/flags/ProtectMode.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/ProtectMode.java similarity index 97% rename from BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/flags/ProtectMode.java rename to BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/ProtectMode.java index 2f510daa..be4f6132 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/flags/ProtectMode.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/ProtectMode.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.regionnew.flags; +package de.steamwar.bausystem.region.flags; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/flags/TNTMode.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/TNTMode.java similarity index 96% rename from BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/flags/TNTMode.java rename to BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/TNTMode.java index e483a81b..0f73f81b 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/flags/TNTMode.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/TNTMode.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.regionnew.flags; +package de.steamwar.bausystem.region.flags; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/flags/TestblockMode.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/TestblockMode.java similarity index 97% rename from BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/flags/TestblockMode.java rename to BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/TestblockMode.java index e7ff3e7b..ba1b8f61 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/flags/TestblockMode.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/TestblockMode.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.regionnew.flags; +package de.steamwar.bausystem.region.flags; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/ColorMode.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/ColorMode.java deleted file mode 100644 index 6159c959..00000000 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/ColorMode.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.region.flags.flagvalues; - -import de.steamwar.bausystem.regionnew.Color; -import de.steamwar.bausystem.region.flags.Flag; -import lombok.AllArgsConstructor; -import lombok.Getter; - -@Getter -@AllArgsConstructor -public enum ColorMode implements Flag.Value { - WHITE("FLAG_COLOR_WHITE", Color.WHITE), - ORANGE("FLAG_COLOR_ORANGE", Color.ORANGE), - MAGENTA("FLAG_COLOR_MAGENTA", Color.MAGENTA), - LIGHT_BLUE("FLAG_COLOR_LIGHT_BLUE", Color.LIGHT_BLUE), - YELLOW("FLAG_COLOR_YELLOW", Color.YELLOW), - LIME("FLAG_COLOR_LIME", Color.LIME), - PINK("FLAG_COLOR_PINK", Color.PINK), - GRAY("FLAG_COLOR_GRAY", Color.GRAY), - LIGHT_GRAY("FLAG_COLOR_LIGHT_GRAY", Color.LIGHT_GRAY), - CYAN("FLAG_COLOR_CYAN", Color.CYAN), - PURPLE("FLAG_COLOR_PURPLE", Color.PURPLE), - BLUE("FLAG_COLOR_BLUE", Color.BLUE), - BROWN("FLAG_COLOR_BROWN", Color.BROWN), - GREEN("FLAG_COLOR_GREEN", Color.GREEN), - RED("FLAG_COLOR_RED", Color.RED), - BLACK("FLAG_COLOR_BLACK", Color.BLACK); - - private static ColorMode[] values; - private final String chatValue; - private final Color color; - - @Override - public ColorMode[] getValues() { - if (ColorMode.values == null) { - ColorMode.values = ColorMode.values(); //NOSONAR - } - return ColorMode.values; - } - - @Override - public ColorMode getValue() { - return this; - } - - @Override - public ColorMode getValueOf(final String name) { - try { - return ColorMode.valueOf(name.toUpperCase()); - } catch (IllegalArgumentException e) { - return ColorMode.YELLOW; - } - } -} diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/FireMode.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/FireMode.java deleted file mode 100644 index cf0fab31..00000000 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/FireMode.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.region.flags.flagvalues; - -import de.steamwar.bausystem.region.flags.Flag; -import lombok.AllArgsConstructor; -import lombok.Getter; - -@Getter -@AllArgsConstructor -public enum FireMode implements Flag.Value { - - ALLOW("FLAG_FIRE_ALLOW"), - DENY("FLAG_FIRE_DENY"); - - private static FireMode[] values; - private final String chatValue; - - @Override - public FireMode[] getValues() { - if (FireMode.values == null) { - FireMode.values = FireMode.values(); //NOSONAR - } - return FireMode.values; - } - - @Override - public FireMode getValue() { - return this; - } - - @Override - public FireMode getValueOf(final String name) { - try { - return FireMode.valueOf(name.toUpperCase()); - } catch (IllegalArgumentException e) { - if (name.equalsIgnoreCase("false")) { - return FireMode.DENY; - } - return FireMode.ALLOW; - } - } -} \ No newline at end of file diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/FreezeMode.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/FreezeMode.java deleted file mode 100644 index 1b1774c7..00000000 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/FreezeMode.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.region.flags.flagvalues; - - -import de.steamwar.bausystem.region.flags.Flag; -import lombok.AllArgsConstructor; -import lombok.Getter; - -@Getter -@AllArgsConstructor -public enum FreezeMode implements Flag.Value { - - ACTIVE("FLAG_FREEZE_ACTIVE"), - INACTIVE("FLAG_FREEZE_INACTIVE"); - - private static FreezeMode[] values; - private final String chatValue; - - @Override - public FreezeMode[] getValues() { - if (FreezeMode.values == null) { - FreezeMode.values = FreezeMode.values(); //NOSONAR - } - return FreezeMode.values; - } - - @Override - public FreezeMode getValue() { - return this; - } - - @Override - public FreezeMode getValueOf(final String name) { - try { - return FreezeMode.valueOf(name.toUpperCase()); - } catch (IllegalArgumentException e) { - if (name.equalsIgnoreCase("false")) { - return FreezeMode.INACTIVE; - } - return FreezeMode.INACTIVE; - } - } -} \ No newline at end of file diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/ItemMode.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/ItemMode.java deleted file mode 100644 index c0cefa38..00000000 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/ItemMode.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.region.flags.flagvalues; - -import de.steamwar.bausystem.region.flags.Flag; -import lombok.AllArgsConstructor; -import lombok.Getter; - -@Getter -@AllArgsConstructor -public enum ItemMode implements Flag.Value { - - ACTIVE("FLAG_ITEMS_ACTIVE"), - INACTIVE("FLAG_ITEMS_INACTIVE"); - - private static ItemMode[] values; - private final String chatValue; - - @Override - public ItemMode[] getValues() { - if (ItemMode.values == null) { - ItemMode.values = ItemMode.values(); //NOSONAR - } - return ItemMode.values; - } - - @Override - public ItemMode getValue() { - return this; - } - - @Override - public ItemMode getValueOf(final String name) { - try { - return ItemMode.valueOf(name.toUpperCase()); - } catch (IllegalArgumentException e) { - if (name.equalsIgnoreCase("false")) { - return ItemMode.INACTIVE; - } - return ItemMode.ACTIVE; - } - } -} diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/NoGravityMode.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/NoGravityMode.java deleted file mode 100644 index 33368a35..00000000 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/NoGravityMode.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.region.flags.flagvalues; - -import de.steamwar.bausystem.region.flags.Flag; -import lombok.AllArgsConstructor; -import lombok.Getter; - -@Getter -@AllArgsConstructor -public enum NoGravityMode implements Flag.Value { - - ACTIVE("FLAG_NO_GRAVITY_ACTIVE"), - INACTIVE("FLAG_NO_GRAVITY_INACTIVE"); - - private static NoGravityMode[] values; - private final String chatValue; - - @Override - public NoGravityMode[] getValues() { - if (NoGravityMode.values == null) { - NoGravityMode.values = NoGravityMode.values(); //NOSONAR - } - return NoGravityMode.values; - } - - @Override - public NoGravityMode getValue() { - return this; - } - - @Override - public NoGravityMode getValueOf(final String name) { - try { - return NoGravityMode.valueOf(name.toUpperCase()); - } catch (IllegalArgumentException e) { - if (name.equalsIgnoreCase("false")) { - return NoGravityMode.INACTIVE; - } - return NoGravityMode.ACTIVE; - } - } -} diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/ProtectMode.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/ProtectMode.java deleted file mode 100644 index 18ea897b..00000000 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/ProtectMode.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.region.flags.flagvalues; - -import de.steamwar.bausystem.region.flags.Flag; -import lombok.AllArgsConstructor; -import lombok.Getter; - -@Getter -@AllArgsConstructor -public enum ProtectMode implements Flag.Value { - - ACTIVE("FLAG_PROTECT_ACTIVE"), - INACTIVE("FLAG_PROTECT_INACTIVE"); - - private static ProtectMode[] values; - private final String chatValue; - - @Override - public ProtectMode[] getValues() { - if (ProtectMode.values == null) { - ProtectMode.values = ProtectMode.values(); //NOSONAR - } - return ProtectMode.values; - } - - @Override - public ProtectMode getValue() { - return this; - } - - @Override - public ProtectMode getValueOf(final String name) { - try { - return ProtectMode.valueOf(name.toUpperCase()); - } catch (IllegalArgumentException e) { - if (name.equalsIgnoreCase("false")) { - return ProtectMode.INACTIVE; - } - return ProtectMode.ACTIVE; - } - } -} diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/TNTMode.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/TNTMode.java deleted file mode 100644 index 9b05d6b5..00000000 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/TNTMode.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.region.flags.flagvalues; - -import de.steamwar.bausystem.region.flags.Flag; -import lombok.AllArgsConstructor; -import lombok.Getter; - -@Getter -@AllArgsConstructor -public enum TNTMode implements Flag.Value { - - ALLOW("FLAG_TNT_ALLOW"), - DENY("FLAG_TNT_DENY"), - ONLY_TB("FLAG_TNT_ONLY_TB"), - ONLY_BUILD("FLAG_TNT_ONLY_BUILD"); - - private static TNTMode[] values; - private final String chatValue; - - @Override - public TNTMode[] getValues() { - if (TNTMode.values == null) { - TNTMode.values = TNTMode.values(); //NOSONAR - } - return TNTMode.values; - } - - @Override - public TNTMode getValue() { - return this; - } - - @Override - public TNTMode getValueOf(final String name) { - try { - return TNTMode.valueOf(name.toUpperCase()); - } catch (IllegalArgumentException e) { - return TNTMode.ALLOW; - } - } -} \ No newline at end of file diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/tags/Tag.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/tags/Tag.java deleted file mode 100644 index e37751d9..00000000 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/tags/Tag.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.region.tags; - -public enum Tag { - CHANGED, -} diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/utils/RegionExtensionType.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/utils/RegionExtensionType.java deleted file mode 100644 index 446e0d97..00000000 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/utils/RegionExtensionType.java +++ /dev/null @@ -1,25 +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.region.utils; - -public enum RegionExtensionType { - NORMAL, - EXTENSION -} diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/utils/RegionSelectionType.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/utils/RegionSelectionType.java index aeac38eb..00d54bb2 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/utils/RegionSelectionType.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/utils/RegionSelectionType.java @@ -2,5 +2,6 @@ package de.steamwar.bausystem.region.utils; public enum RegionSelectionType { LOCAL, - GLOBAL + GLOBAL, + ; } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/utils/RegionType.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/utils/RegionType.java deleted file mode 100644 index a618c644..00000000 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/utils/RegionType.java +++ /dev/null @@ -1,34 +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.region.utils; - -import de.steamwar.bausystem.shared.EnumDisplay; -import lombok.AllArgsConstructor; -import lombok.Getter; - -@AllArgsConstructor -public enum RegionType implements EnumDisplay { - NORMAL("REGION_TYPE_NORMAL"), - BUILD("REGION_TYPE_BUILD"), - TESTBLOCK("REGION_TYPE_ONLY_TB"); - - @Getter - private String chatValue; -} diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/FlagStorage.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/FlagStorage.java deleted file mode 100644 index 57a9523c..00000000 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/FlagStorage.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2024 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.regionnew; - -import de.steamwar.bausystem.regionnew.flags.Flag; - -public interface FlagStorage { - - & Flag.Value> boolean set(Flag flag, Flag.Value value); - - & Flag.Value> Flag.Value get(Flag flag); -} diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/Region.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/Region.java deleted file mode 100644 index 1bdab641..00000000 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/Region.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2024 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.regionnew; - -import com.sk89q.worldedit.EditSession; -import de.steamwar.bausystem.regionnew.flags.Flag; -import de.steamwar.sql.SchematicNode; -import lombok.NonNull; -import org.bukkit.Location; - -import javax.annotation.Nullable; -import java.io.File; -import java.util.Optional; - -public interface Region { - - static Region getRegion(Location location) { - return RegionSystem.REGION_SYSTEM.get(location); - } - - RegionType getType(); - - & Flag.Value> RegionFlagPolicy hasFlag(@NonNull Flag flag); - - & Flag.Value> boolean setFlag(@NonNull Flag flag, Flag.Value value); - - & Flag.Value> Optional> getFlag(@NonNull Flag flag); - - Point getMinPoint(); - - Point getMaxPoint(); - - boolean inRegion(Location location); - - Optional getBuildMinPoint(boolean extension); - - Optional getBuildMaxPoint(boolean extension); - - boolean inBuildRegion(Location location, boolean extension); - - Optional getTestblockMinPoint(boolean extension); - - Optional getTestblockMaxPoint(boolean extension); - - boolean inTestblockRegion(Location location, boolean extension); - - // TODO: Add forEachChunk and getChunkOutsidePredicate - - Optional getGameModeConfig(); - - Optional copy(); - - Optional copyBuild(); - - Optional copyTestblock(); - - void reset(); - - void resetBuild(@Nullable SchematicNode schematicNode, boolean extension); - - void resetTestblock(@Nullable SchematicNode schematicNode, boolean extension); - - void remember(EditSession editSession); - - boolean undo(); - - boolean redo(); -} diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/RegionSide.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/RegionSide.java deleted file mode 100644 index 6834e300..00000000 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/RegionSide.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2024 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.regionnew; - -public enum RegionSide { - NORTH, - SOUTH -} diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/flags/Flag.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/flags/Flag.java deleted file mode 100644 index d915c216..00000000 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionnew/flags/Flag.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2024 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.regionnew.flags; - -import de.steamwar.bausystem.shared.EnumDisplay; -import lombok.Getter; - -import java.util.HashSet; -import java.util.Set; -import java.util.concurrent.atomic.AtomicInteger; - -public class Flag & Flag.Value> implements EnumDisplay { - - public static final Flag COLOR = new Flag<>("COLOR", "FLAG_COLOR", ColorMode.class, ColorMode.YELLOW); - public static final Flag TNT = new Flag<>("TNT", "FLAG_TNT", TNTMode.class, TNTMode.ONLY_TB); - public static final Flag FIRE = new Flag<>("FIRE", "FLAG_FIRE", FireMode.class, FireMode.ALLOW); - public static final Flag FREEZE = new Flag<>("FREEZE", "FLAG_FREEZE", FreezeMode.class, FreezeMode.INACTIVE); - public static final Flag PROTECT = new Flag<>("PROTECT", "FLAG_PROTECT", ProtectMode.class, ProtectMode.ACTIVE); - public static final Flag ITEMS = new Flag<>("ITEMS", "FLAG_ITEMS", ItemMode.class, ItemMode.INACTIVE); - public static final Flag NO_GRAVITY = new Flag<>("NO_GRAVITY", "FLAG_NO_GRAVITY", NoGravityMode.class, NoGravityMode.INACTIVE); - public static final Flag TESTBLOCK = new Flag<>("TESTBLOCK", "FLAG_TESTBLOCK", TestblockMode.class, TestblockMode.NO_VALUE); - public static final Flag CHANGED = new Flag<>("CHANGED", "FLAG_CHANGED", ChangedMode.class, ChangedMode.NO_CHANGE); - - @Getter - private static final Set flags = new HashSet<>(); - - private static AtomicInteger counter = new AtomicInteger(0); - - private String name; - private int ordinal; - - @Getter - private String chatValue; - - @Getter - private final Class> valueType; - - @Getter - private final Flag.Value defaultValue; - - @Getter - private final Flag.Value[] values; - - private Flag(String name, String chatValue, Class> valueType, Value defaultValue) { - flags.add(this); - - this.name = name; - this.ordinal = counter.getAndIncrement(); - this.chatValue = chatValue; - - this.valueType = valueType; - this.defaultValue = defaultValue; - this.values = defaultValue.getValues(); - } - - public String name() { - return name; - } - - public int ordinal() { - return ordinal; - } - - public boolean oneOff(Flag... flags) { - for (Flag flag : flags) { - if (flag == this) { - return true; - } - } - return false; - } - - public interface Value & Flag.Value> extends EnumDisplay { - - T getValue(); - - T getValueOf(final String name); - - T[] getValues(); - - default String getName() { - return this.getValue().name().toLowerCase(); - } - } -} diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Prototype.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionold/Prototype.java.txt similarity index 100% rename from BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Prototype.java rename to BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionold/Prototype.java.txt diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionold/Region.java.txt b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionold/Region.java.txt new file mode 100644 index 00000000..c6f8b5c7 --- /dev/null +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionold/Region.java.txt @@ -0,0 +1,584 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2021 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.region; + +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.bukkit.BukkitWorld; +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.region.flags.Flag; +import de.steamwar.bausystem.region.flags.flagvalues.TNTMode; +import de.steamwar.bausystem.region.tags.Tag; +import de.steamwar.bausystem.region.utils.RegionExtensionType; +import de.steamwar.bausystem.region.utils.RegionType; +import de.steamwar.bausystem.shared.SizedStack; +import de.steamwar.bausystem.utils.FlatteningWrapper; +import de.steamwar.bausystem.utils.PasteBuilder; +import de.steamwar.core.Core; +import de.steamwar.sql.SchematicType; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NonNull; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import yapion.hierarchy.types.YAPIONObject; +import yapion.hierarchy.types.YAPIONType; +import yapion.hierarchy.types.YAPIONValue; + +import java.io.File; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.*; +import java.util.function.ObjIntConsumer; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +@Getter +public class Region { + + @Getter + private static final Map REGION_MAP = new HashMap<>(); + private static final File backupFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "backup"); + private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy.MM.dd' 'HH:mm:ss"); + + public static Region getRegion(Location location) { + return REGION_MAP.values().stream() + .filter(r -> r.inRegion(location, r.minPoint, r.maxPoint)) + .findFirst() + .orElse(GlobalRegion.instance); + } + + public static Set getRegion(Prototype prototype) { + return REGION_MAP.values().stream() + .filter(r -> r.getPrototype() == prototype) + .collect(Collectors.toSet()); + } + + public static void setGlobal(Flag flagType, Flag.Value value) { + REGION_MAP.values().forEach(region -> region.set(flagType, value)); + } + + YAPIONObject regionData; + + private String name; + private Prototype prototype; + private Set prototypes; + private String skin; + + private Point minPoint; + private Point maxPoint; + + private Point minPointTestblock; + private Point maxPointTestblock; + + private Point minPointTestblockExtension; + private Point maxPointTestblockExtension; + + private Point minPointBuild; + private Point maxPointBuild; + + private Point minPointBuildExtension; + private Point maxPointBuildExtension; + + private int floorLevel; + private int waterLevel; + + private Point copyPoint; // Nullable + private Point testBlockPoint; // Nullable + + private String linkedRegionName = null; // Nullable + private Region linkedRegion = null; // Nullable + + private FlagStorage flagStorage; + + @Getter(AccessLevel.PRIVATE) + private SizedStack undoSessions; + + @Getter(AccessLevel.PRIVATE) + private SizedStack redoSessions; + + public Region(String name, Prototype prototype, YAPIONObject regionConfig, FlagStorage flagStorage, YAPIONObject regionData) { + this.name = name; + this.regionData = regionData; + if (prototype != null) { + REGION_MAP.put(name, this); + } + + linkedRegionName = regionConfig.getPlainValueOrDefault("optionsLinkedWith", null); + + prototypes = new HashSet<>(); + if (regionConfig.containsKey("prototypes", YAPIONType.ARRAY)) { + regionConfig.getArray("prototypes").forEach(yapionAnyType -> { + if (yapionAnyType instanceof YAPIONValue) { + prototypes.add(((YAPIONValue) yapionAnyType).get()); + } + }); + } + if (regionConfig.containsKey("prototype")) { + prototypes.add(regionConfig.getPlainValue("prototype")); + } + + this.flagStorage = flagStorage; + Point point = null; + if (regionConfig.containsKey("minX", Integer.class) && regionConfig.containsKey("minY", Integer.class) && regionConfig.containsKey("minZ", Integer.class)) { + point = new Point(regionConfig.getPlainValue("minX"), regionConfig.getPlainValue("minY"), regionConfig.getPlainValue("minZ")); + } + if (prototype != null && prototypes.contains(prototype.getName())) { + generatePrototypeData(prototype, point); + } else if (regionConfig.containsKey("prototype")) { + generatePrototypeData(Prototype.getByName(regionConfig.getPlainValue("prototype")), point); + } + if (prototype != null) { + skin = regionData.getPlainValueOrDefault("skin", prototype.getDefaultSkin()); + if (!prototype.getSkinMap().containsKey(skin)) { + skin = prototype.getDefaultSkin(); + } + } + regionData.add("skin", skin); + + if (!hasType(RegionType.BUILD) || !hasType(RegionType.TESTBLOCK)) { + flagStorage.set(Flag.TNT, TNTMode.DENY); + } + } + + private void generatePrototypeData(Prototype prototype, Point point) { + if (prototype == null) { + return; + } + + this.prototype = prototype; + this.skin = prototype.getDefaultSkin(); + + this.minPoint = point; + this.maxPoint = point.add(prototype.getSizeX() - 1, prototype.getSizeY() - 1, prototype.getSizeZ() - 1); + + if (prototype.getTestblock() != null) { + this.minPointTestblock = point.add(prototype.getTestblock().getOffsetX(), prototype.getTestblock().getOffsetY(), prototype.getTestblock().getOffsetZ()); + this.maxPointTestblock = this.minPointTestblock.add(prototype.getTestblock().getSizeX() - 1, prototype.getTestblock().getSizeY() - 1, prototype.getTestblock().getSizeZ() - 1); + + this.minPointTestblockExtension = this.minPointTestblock.subtract(prototype.getTestblock().getExtensionNegativeX(), prototype.getTestblock().getExtensionNegativeY(), prototype.getTestblock().getExtensionNegativeZ()); + this.maxPointTestblockExtension = this.maxPointTestblock.add(prototype.getTestblock().getExtensionPositiveX(), prototype.getTestblock().getExtensionPositiveY(), prototype.getTestblock().getExtensionPositiveZ()); + + if (prototype.getTestblock().getCopyOffsetX() != 0 || prototype.getTestblock().getCopyOffsetY() != 0 || prototype.getTestblock().getCopyOffsetZ() != 0) { + this.testBlockPoint = this.minPointTestblock.add(prototype.getTestblock().getCopyOffsetX(), prototype.getTestblock().getCopyOffsetY(), prototype.getTestblock().getCopyOffsetZ()); + } else { + this.testBlockPoint = this.minPointTestblock.add(prototype.getTestblock().getSizeX() / 2, 0, -1); + } + } + + if (prototype.getBuild() != null) { + this.minPointBuild = point.add(prototype.getBuild().getOffsetX(), prototype.getBuild().getOffsetY(), prototype.getBuild().getOffsetZ()); + this.maxPointBuild = this.minPointBuild.add(prototype.getBuild().getSizeX() - 1, prototype.getBuild().getSizeY() - 1, prototype.getBuild().getSizeZ() - 1); + + this.minPointBuildExtension = this.minPointBuild.subtract(prototype.getBuild().getExtensionNegativeX(), prototype.getBuild().getExtensionNegativeY(), prototype.getBuild().getExtensionNegativeZ()); + this.maxPointBuildExtension = this.maxPointBuild.add(prototype.getBuild().getExtensionPositiveX(), prototype.getBuild().getExtensionPositiveY(), prototype.getBuild().getExtensionPositiveZ()); + + if (!prototype.getBuild().isHasCopyPoint() && (prototype.getCopyPointOffsetX() != 0 || prototype.getCopyPointOffsetY() != 0 || prototype.getCopyPointOffsetZ() != 0)) { + this.copyPoint = minPoint.add(prototype.getCopyPointOffsetX(), prototype.getCopyPointOffsetY(), prototype.getCopyPointOffsetZ()); + } else if (prototype.getBuild().getCopyOffsetX() != 0 || prototype.getBuild().getCopyOffsetY() != 0 || prototype.getBuild().getCopyOffsetZ() != 0) { + this.copyPoint = this.minPointBuild.add(prototype.getBuild().getCopyOffsetX(), prototype.getBuild().getCopyOffsetY(), prototype.getBuild().getCopyOffsetZ()); + } else { + this.copyPoint = this.minPointBuild.add(prototype.getBuild().getSizeX() / 2, 0, prototype.getBuild().getSizeZ()); + } + } else if (prototype.getCopyPointOffsetX() != 0 || prototype.getCopyPointOffsetY() != 0 || prototype.getCopyPointOffsetZ() != 0) { + this.copyPoint = minPoint.add(prototype.getCopyPointOffsetX(), prototype.getCopyPointOffsetY(), prototype.getCopyPointOffsetZ()); + } + + if (prototype.getFloorOffset() != 0) { + floorLevel = minPoint.getY() + prototype.getFloorOffset(); + } else { + floorLevel = 0; + } + + if (prototype.getWaterOffset() != 0) { + waterLevel = minPoint.getY() + prototype.getWaterOffset(); + } else { + waterLevel = 0; + } + } + + public boolean inRegion(Location location, RegionType regionType, RegionExtensionType regionExtensionType) { + if (!hasType(regionType)) { + return false; + } + switch (regionType) { + case BUILD: + Point minBPoint = regionExtensionType == RegionExtensionType.EXTENSION ? minPointBuildExtension : minPointBuild; + Point maxBPoint = regionExtensionType == RegionExtensionType.EXTENSION ? maxPointBuildExtension : maxPointBuild; + return inRegion(location, minBPoint, maxBPoint); + case TESTBLOCK: + Point minTBPoint = regionExtensionType == RegionExtensionType.EXTENSION ? minPointTestblockExtension : minPointTestblock; + Point maxTBPoint = regionExtensionType == RegionExtensionType.EXTENSION ? maxPointTestblockExtension : maxPointTestblock; + return inRegion(location, minTBPoint, maxTBPoint); + default: + case NORMAL: + return inRegion(location, minPoint, maxPoint); + } + } + + private boolean inRegion(Location location, Point minPoint, Point maxPoint) { + int blockX = location.getBlockX(); + int blockY = location.getBlockY(); + int blockZ = location.getBlockZ(); + return blockX >= minPoint.getX() && blockX <= maxPoint.getX() && + blockY >= minPoint.getY() && blockY <= maxPoint.getY() && + blockZ >= minPoint.getZ() && blockZ <= maxPoint.getZ(); + } + + public boolean hasType(RegionType regionType) { + if (prototype == null) { + return false; + } + if (regionType == null) { + return false; + } + switch (regionType) { + case BUILD: + return prototype.getBuild() != null; + case TESTBLOCK: + return prototype.getTestblock() != null; + default: + case NORMAL: + return true; + } + } + + public boolean hasExtensionType(RegionType regionType) { + if (!hasType(regionType)) { + return false; + } + switch (regionType) { + case BUILD: + return prototype.getBuild().isExtensionRegistered(); + case TESTBLOCK: + return prototype.getTestblock().isExtensionRegistered(); + default: + case NORMAL: + return false; + } + } + + public String getDisplayName() { + return prototype != null ? prototype.getSkinMap().get(skin).getName() : ""; + } + + private void setLinkedRegion(Predicate regionConsumer) { + if (linkedRegionName == null) { + return; + } + if (linkedRegion != null) { + if (regionConsumer.test(linkedRegion)) { + RegionUtils.save(linkedRegion); + } + return; + } + for (Region region : REGION_MAP.values()) { + if (region.name.equals(linkedRegionName)) { + linkedRegion = region; + if (regionConsumer.test(linkedRegion)) { + RegionUtils.save(linkedRegion); + } + return; + } + } + } + + public Region getLinkedRegion() { + if (linkedRegion == null && linkedRegionName != null) { + setLinkedRegion(region -> false); + } + return linkedRegion; + } + + public boolean setPrototype(@NonNull Prototype prototype) { + if (!prototypes.contains(prototype.getName())) { + return false; + } + return _setPrototype(prototype); + } + + boolean _setPrototype(@NonNull Prototype prototype) { + generatePrototypeData(prototype, minPoint); + RegionUtils.save(this); + return true; + } + + public boolean setSkin(@NonNull String skinName) { + if (!prototype.getSkinMap().containsKey(skinName)) { + return false; + } + this.skin = skinName; + setLinkedRegion(region -> { + region.skin = skinName; + return true; + }); + regionData.add("skin", skin); + return true; + } + + public void set(Flag flagType, Flag.Value value) { + if (flagStorage.set(flagType, value)) { + RegionUtils.save(this); + } + setLinkedRegion(region -> region.flagStorage.set(flagType, value)); + } + + public void set(Tag tag) { + if (flagStorage.set(tag)) { + RegionUtils.save(this); + } + setLinkedRegion(region -> region.flagStorage.set(tag)); + } + + public void remove(Tag tag) { + if (flagStorage.remove(tag)) { + RegionUtils.save(this); + } + } + + public Flag.Value get(Flag flagType) { + return flagStorage.get(flagType); + } + + public boolean get(Tag tagType) { + return flagStorage.is(tagType); + } + + public & Flag.Value> T getPlain(Flag flagType) { + return (T) flagStorage.get(flagType).getValue(); + } + + public & Flag.Value> T getPlain(Flag flagType, Class type) { + return (T) flagStorage.get(flagType).getValue(); + } + + public Point getMinPoint(RegionType regionType, RegionExtensionType regionExtensionType) { + switch (regionType) { + case TESTBLOCK: + return (regionExtensionType == null || regionExtensionType == RegionExtensionType.NORMAL) ? minPointTestblock : minPointTestblockExtension; + case BUILD: + return (regionExtensionType == null || regionExtensionType == RegionExtensionType.NORMAL) ? minPointBuild : minPointBuildExtension; + default: + case NORMAL: + return minPoint; + } + } + + public Point getMaxPoint(RegionType regionType, RegionExtensionType regionExtensionType) { + switch (regionType) { + case TESTBLOCK: + return (regionExtensionType == null || regionExtensionType == RegionExtensionType.NORMAL) ? maxPointTestblock : maxPointTestblockExtension; + case BUILD: + return (regionExtensionType == null || regionExtensionType == RegionExtensionType.NORMAL) ? maxPointBuild : maxPointBuildExtension; + default: + case NORMAL: + return maxPoint; + } + } + + boolean hasReset(RegionType regionType) { + if (!hasType(regionType)) { + return false; + } + switch (regionType) { + case TESTBLOCK: + return prototype.getSkinMap().get(skin).getTestblockSchematicFile() != null; + case BUILD: + return prototype.getSkinMap().get(skin).getBuildSchematicFile() != null; + default: + case NORMAL: + return prototype.getSkinMap().get(skin).getSchematicFile() != null; + } + } + + public File getResetFile(RegionType regionType) { + if (!hasReset(regionType)) { + return null; + } + switch (regionType) { + case TESTBLOCK: + return prototype.getSkinMap().get(skin).getTestblockSchematicFile(); + case BUILD: + return prototype.getSkinMap().get(skin).getBuildSchematicFile(); + default: + case NORMAL: + return prototype.getSkinMap().get(skin).getSchematicFile(); + } + } + + public void reset(PasteBuilder pasteBuilder, RegionType regionType, RegionExtensionType regionExtensionType) { + if (!hasReset(regionType)) { + return; + } + if (regionExtensionType == RegionExtensionType.EXTENSION && !hasExtensionType(regionType)) { + regionExtensionType = RegionExtensionType.NORMAL; + } + + pasteBuilder.reset(regionExtensionType == RegionExtensionType.EXTENSION) + .minPoint(getMinPoint(regionType, regionExtensionType)) + .maxPoint(getMaxPoint(regionType, regionExtensionType)) + .waterLevel(waterLevel); + if (pasteBuilder.getClipboardProvider().is(PasteBuilder.SchematicProvider.class)) { + SchematicType schematicType = pasteBuilder.getClipboardProvider().as(PasteBuilder.SchematicProvider.class).getSchematic().getSchemtype(); + pasteBuilder.rotate(schematicType.fightType() || schematicType.check()); + } + + switch (regionType) { + case BUILD: + pasteBuilder.pastePoint(minPointBuild.add(prototype.getBuild().getSizeX() / 2, 0, prototype.getBuild().getSizeZ() / 2)); + break; + case TESTBLOCK: + Point pastePoint = minPointTestblock.add(prototype.getTestblock().getSizeX() / 2, 0, prototype.getTestblock().getSizeZ() / 2); + if (pasteBuilder.getClipboardProvider().is(PasteBuilder.SchematicProvider.class)) { + SchematicType schematicType = pasteBuilder.getClipboardProvider().as(PasteBuilder.SchematicProvider.class).getSchematic().getSchemtype(); + if (schematicType.getKuerzel().equalsIgnoreCase("wg")) { + pastePoint = pastePoint.add(0, 0, 1); + } + if (schematicType.getKuerzel().equalsIgnoreCase("ws")) { + pastePoint = pastePoint.add(-1, 0, 1); + } + if (schematicType.getKuerzel().equalsIgnoreCase("as")) { + pastePoint = pastePoint.add(-1, 0, 1); + } + } + pasteBuilder.pastePoint(pastePoint); + break; + default: + case NORMAL: + pasteBuilder.pastePoint(minPoint.add(prototype.getSizeX() / 2, 0, prototype.getSizeZ() / 2)); + break; + } + + initSessions(); + undoSessions.push(pasteBuilder.run()); + } + + public void remember(EditSession editSession) { + initSessions(); + undoSessions.push(editSession); + } + + public boolean isGlobal() { + return this == GlobalRegion.getInstance(); + } + + private void initSessions() { + if (undoSessions == null) { + undoSessions = new SizedStack<>(20); + redoSessions = new SizedStack<>(20); + } + } + + public boolean undo() { + initSessions(); + EditSession session = undoSessions.pop(); + if (session == null) + return false; + + try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) { + session.undo(e); + redoSessions.push(e); + } + return true; + } + + public boolean redo() { + initSessions(); + EditSession session = redoSessions.pop(); + if (session == null) + return false; + + try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) { + session.redo(e); + undoSessions.push(e); + } + return true; + } + + public boolean backup() { + final File definedBackupFolder = new File(new File(backupFolder, prototype.getName()), name); + //noinspection ResultOfMethodCallIgnored + definedBackupFolder.mkdirs(); + + File[] currentBackups = definedBackupFolder.listFiles(); + if (currentBackups != null && currentBackups.length >= 20) { + List files = new ArrayList<>(Arrays.asList(currentBackups)); + files.sort(Comparator.comparingLong(File::lastModified)); + while (files.size() >= 20) files.remove(0).delete(); + } + + final File backupFile = new File(definedBackupFolder, LocalDateTime.now().format(formatter) + ".schem"); + return FlatteningWrapper.impl.backup(minPoint, maxPoint, backupFile); + } + + public static boolean copy(Point minPoint, Point maxPoint, File file) { + return FlatteningWrapper.impl.backup(minPoint, maxPoint, file); + } + + public List listBackup() { + final File definedBackupFolder = new File(new File(backupFolder, prototype.getName()), name); + //noinspection ResultOfMethodCallIgnored + definedBackupFolder.mkdirs(); + + File[] currentBackups = definedBackupFolder.listFiles(); + List files = new ArrayList<>(Arrays.asList(currentBackups)); + files.sort(Comparator.comparingLong(File::lastModified)); + return files.stream().map(File::getName).collect(Collectors.toList()); + } + + public File getBackupFile(String backupName) { + final File definedBackupFolder = new File(new File(backupFolder, prototype.getName()), name); + //noinspection ResultOfMethodCallIgnored + definedBackupFolder.mkdirs(); + File[] files = definedBackupFolder.listFiles((dir, name) -> name.equals(backupName + ".schem")); + if (files == null || files.length == 0) return null; + return files[0]; + } + + public void forEachChunk(ObjIntConsumer executor) { + for (int x = (int) Math.floor(minPoint.getX() / 16.0); x <= (int) Math.ceil(maxPoint.getX() / 16.0); x++) { + for (int z = (int) Math.floor(minPoint.getZ() / 16.0); z <= (int) Math.ceil(maxPoint.getZ() / 16.0); z++) { + executor.accept(x, z); + } + } + } + + public boolean buildChunkOutside(int chunkX, int chunkY) { + if (!hasType(RegionType.BUILD)) { + return Math.floor(minPoint.getX() / 16.0) > chunkX || chunkX >= Math.ceil(maxPoint.getX() / 16.0) || + Math.floor(minPoint.getZ() / 16.0) > chunkY || chunkY >= Math.ceil(maxPoint.getZ() / 16.0); + } + if (!hasExtensionType(RegionType.BUILD)) { + return Math.floor(minPointBuild.getX() / 16.0) > chunkX || chunkX >= Math.ceil(maxPointBuild.getX() / 16.0) || + Math.floor(minPointBuild.getZ() / 16.0) > chunkY || chunkY >= Math.ceil(maxPointBuild.getZ() / 16.0); + } + return Math.floor(minPointBuildExtension.getX() / 16.0) > chunkX || chunkX >= Math.ceil(maxPointBuildExtension.getX() / 16.0) || + Math.floor(minPointBuildExtension.getZ() / 16.0) > chunkY || chunkY >= Math.ceil(maxPointBuildExtension.getZ() / 16.0); + } + + public File gameModeConfig() { + File baseFile = new File(BauSystem.getInstance().getDataFolder().getParentFile(), "FightSystem"); + for (int version = Core.getVersion(); version >= 15; version--) { + File specific = new File(baseFile, prototype.getDisplayName() + version + ".yml"); + if (specific.exists()) return specific; + } + return null; + } +} \ No newline at end of file diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/loader/PrototypeLoader.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionold/loader/PrototypeLoader.java.txt similarity index 100% rename from BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/loader/PrototypeLoader.java rename to BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionold/loader/PrototypeLoader.java.txt diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/loader/RegionLoader.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionold/loader/RegionLoader.java.txt similarity index 100% rename from BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/loader/RegionLoader.java rename to BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionold/loader/RegionLoader.java.txt diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/loader/Updater.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionold/loader/Updater.java.txt similarity index 100% rename from BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/loader/Updater.java rename to BauSystem/BauSystem_Main/src/de/steamwar/bausystem/regionold/loader/Updater.java.txt diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/FlatteningWrapper.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/FlatteningWrapper.java index 12b7a78a..3cd96295 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/FlatteningWrapper.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/FlatteningWrapper.java @@ -22,7 +22,7 @@ package de.steamwar.bausystem.utils; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.extent.clipboard.Clipboard; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.regionnew.Point; +import de.steamwar.bausystem.region.Point; import de.steamwar.core.VersionDependent; import org.bukkit.Material; import org.bukkit.World; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PasteBuilder.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PasteBuilder.java index 8c3813ac..a4a74e17 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PasteBuilder.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PasteBuilder.java @@ -26,8 +26,8 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; -import de.steamwar.bausystem.regionnew.Color; -import de.steamwar.bausystem.regionnew.Point; +import de.steamwar.bausystem.region.Color; +import de.steamwar.bausystem.region.Point; import de.steamwar.sql.SchematicData; import de.steamwar.sql.SchematicNode; import lombok.Getter; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/GlobalBossbar.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/GlobalBossbar.java index a5aaf9fe..47f57907 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/GlobalBossbar.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/GlobalBossbar.java @@ -19,8 +19,8 @@ package de.steamwar.bausystem.utils.bossbar; -import de.steamwar.bausystem.region.GlobalRegion; import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.RegionSystem; import org.bukkit.boss.BarColor; import org.bukkit.boss.BarFlag; import org.bukkit.boss.BarStyle; @@ -101,7 +101,7 @@ public class GlobalBossbar implements BauSystemBossbar { @Override public Region getRegion() { - return GlobalRegion.getInstance(); + return RegionSystem.INSTANCE.getGlobalRegion(); } @Override diff --git a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/regionnew/FixedFlagStorage.java b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedFlagStorage.java similarity index 86% rename from BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/regionnew/FixedFlagStorage.java rename to BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedFlagStorage.java index 1af55086..af44866a 100644 --- a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/regionnew/FixedFlagStorage.java +++ b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedFlagStorage.java @@ -17,9 +17,9 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.regionnew; +package de.steamwar.bausystem.region; -import de.steamwar.bausystem.regionnew.flags.Flag; +import de.steamwar.bausystem.region.flags.Flag; import java.io.File; import java.util.HashMap; @@ -44,12 +44,12 @@ public class FixedFlagStorage implements FlagStorage { } @Override - public & Flag.Value> boolean set(Flag flag, Flag.Value value) { + public & Flag.Value> boolean set(Flag flag, T value) { return flagMap.put(flag, value) != value; } @Override - public & Flag.Value> Flag.Value get(Flag flag) { - return (Flag.Value) flagMap.get(flag); + public & Flag.Value> T get(Flag flag) { + return (T) flagMap.get(flag); } } diff --git a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/regionnew/FixedGlobalRegion.java b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedGlobalRegion.java similarity index 65% rename from BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/regionnew/FixedGlobalRegion.java rename to BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedGlobalRegion.java index 81b39197..b36ddecb 100644 --- a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/regionnew/FixedGlobalRegion.java +++ b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedGlobalRegion.java @@ -17,15 +17,13 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.regionnew; +package de.steamwar.bausystem.region; import com.sk89q.worldedit.EditSession; -import de.steamwar.bausystem.regionnew.flags.Flag; -import de.steamwar.sql.SchematicNode; +import de.steamwar.bausystem.region.flags.Flag; import lombok.NonNull; import org.bukkit.Location; -import javax.annotation.Nullable; import java.io.File; import java.util.Optional; @@ -35,6 +33,7 @@ public final class FixedGlobalRegion implements Region { private static final Point MIN_POINT = new Point(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE); private static final Point MAX_POINT = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE); + private final FlagStorage FLAG_STORAGE = FixedFlagStorage.createFromRegion(this); // TODO: Update to either File or Region creation! private FixedGlobalRegion() { @@ -47,21 +46,21 @@ public final class FixedGlobalRegion implements Region { @Override public & Flag.Value> RegionFlagPolicy hasFlag(@NonNull Flag flag) { - if (flag.oneOff(Flag.TNT, Flag.FIRE, Flag.FREEZE, Flag.ITEMS)) { + if (flag.oneOf(Flag.TNT, Flag.FIRE, Flag.FREEZE, Flag.ITEMS, Flag.NO_GRAVITY)) { return RegionFlagPolicy.WRITABLE; } return RegionFlagPolicy.NOT_APPLICABLE; } @Override - public & Flag.Value> boolean setFlag(@NonNull Flag flag, Flag.Value value) { + public & Flag.Value> boolean setFlag(@NonNull Flag flag, T value) { return hasFlag(flag).isWritable() && FLAG_STORAGE.set(flag, value); } @Override - public & Flag.Value> Optional> getFlag(@NonNull Flag flag) { + public & Flag.Value> Optional getFlag(@NonNull Flag flag) { if (hasFlag(flag).isReadable()) { - return Optional.of(FLAG_STORAGE.get(flag)); + return Optional.ofNullable(FLAG_STORAGE.get(flag)); } else { return Optional.empty(); } @@ -83,33 +82,13 @@ public final class FixedGlobalRegion implements Region { } @Override - public Optional getBuildMinPoint(boolean extension) { - return Optional.empty(); + public Inner getBuildArea() { + return Inner.EMPTY; } @Override - public Optional getBuildMaxPoint(boolean extension) { - return Optional.empty(); - } - - @Override - public boolean inBuildRegion(Location location, boolean extension) { - return false; - } - - @Override - public Optional getTestblockMinPoint(boolean extension) { - return Optional.empty(); - } - - @Override - public Optional getTestblockMaxPoint(boolean extension) { - return Optional.empty(); - } - - @Override - public boolean inTestblockRegion(Location location, boolean extension) { - return false; + public Inner getTestblockArea() { + return Inner.EMPTY; } @Override @@ -123,13 +102,8 @@ public final class FixedGlobalRegion implements Region { } @Override - public Optional copyBuild() { - return Optional.empty(); - } - - @Override - public Optional copyTestblock() { - return Optional.empty(); + public boolean backup(boolean automatic) { + return false; } @Override @@ -137,16 +111,6 @@ public final class FixedGlobalRegion implements Region { } - @Override - public void resetBuild(@Nullable SchematicNode schematicNode, boolean extension) { - - } - - @Override - public void resetTestblock(@Nullable SchematicNode schematicNode, boolean extension) { - - } - @Override public void remember(EditSession editSession) { diff --git a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/regionnew/FixedRegion.java b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedRegion.java similarity index 61% rename from BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/regionnew/FixedRegion.java rename to BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedRegion.java index c89cdf61..0023060d 100644 --- a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/regionnew/FixedRegion.java +++ b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedRegion.java @@ -17,15 +17,13 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.regionnew; +package de.steamwar.bausystem.region; import com.sk89q.worldedit.EditSession; -import de.steamwar.bausystem.regionnew.flags.Flag; -import de.steamwar.sql.SchematicNode; +import de.steamwar.bausystem.region.flags.Flag; import lombok.NonNull; import org.bukkit.Location; -import javax.annotation.Nullable; import java.io.File; import java.util.Optional; @@ -42,12 +40,12 @@ public class FixedRegion implements Region { // TODO: Implement! } @Override - public & Flag.Value> boolean setFlag(@NonNull Flag flag, Flag.Value value) { + public & Flag.Value> boolean setFlag(@NonNull Flag flag, T value) { return false; } @Override - public & Flag.Value> Optional> getFlag(@NonNull Flag flag) { + public & Flag.Value> Optional getFlag(@NonNull Flag flag) { return Optional.empty(); } @@ -67,33 +65,13 @@ public class FixedRegion implements Region { // TODO: Implement! } @Override - public Optional getBuildMinPoint(boolean extension) { - return Optional.empty(); + public Inner getBuildArea() { + return Inner.EMPTY; } @Override - public Optional getBuildMaxPoint(boolean extension) { - return Optional.empty(); - } - - @Override - public boolean inBuildRegion(Location location, boolean extension) { - return false; - } - - @Override - public Optional getTestblockMinPoint(boolean extension) { - return Optional.empty(); - } - - @Override - public Optional getTestblockMaxPoint(boolean extension) { - return Optional.empty(); - } - - @Override - public boolean inTestblockRegion(Location location, boolean extension) { - return false; + public Inner getTestblockArea() { + return Inner.EMPTY; } @Override @@ -101,36 +79,21 @@ public class FixedRegion implements Region { // TODO: Implement! return Optional.empty(); } + @Override + public boolean backup(boolean automatic) { + return false; + } + @Override public Optional copy() { return Optional.empty(); } - @Override - public Optional copyBuild() { - return Optional.empty(); - } - - @Override - public Optional copyTestblock() { - return Optional.empty(); - } - @Override public void reset() { } - @Override - public void resetBuild(@Nullable SchematicNode schematicNode, boolean extension) { - - } - - @Override - public void resetTestblock(@Nullable SchematicNode schematicNode, boolean extension) { - - } - @Override public void remember(EditSession editSession) { diff --git a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/regionnew/FixedRegionSystem.java b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedRegionSystem.java similarity index 97% rename from BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/regionnew/FixedRegionSystem.java rename to BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedRegionSystem.java index f29b1ebc..dfdaf3f3 100644 --- a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/regionnew/FixedRegionSystem.java +++ b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedRegionSystem.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.regionnew; +package de.steamwar.bausystem.region; import org.bukkit.Location;