From 2353fb17e74a3cdb2a10a8f9084dd409bf6aa7c4 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 9 Apr 2021 16:24:47 +0200 Subject: [PATCH 1/9] Add initial Region.protect --- .../bausystem/world/regions/Region.java | 54 ++++++++++++------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Region.java index a02edfb..723587d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Region.java @@ -29,6 +29,7 @@ import de.steamwar.bausystem.world.Color; import de.steamwar.bausystem.world.SizedStack; import de.steamwar.sql.NoClipboardException; import de.steamwar.sql.Schematic; +import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.configuration.ConfigurationSection; @@ -133,10 +134,19 @@ public class Region { private JsonObject regionOptions = new JsonObject(); + @Getter private TNTMode tntMode = Region.buildAreaEnabled() ? TNTMode.ONLY_TB : TNTMode.OFF; + + @Getter private boolean freeze = false; + + @Getter private boolean fire = false; + @Getter + private boolean protect = false; + + @Getter private Color color = Color.YELLOW; private Region(ConfigurationSection config) { @@ -178,6 +188,10 @@ public class Region { freeze = regionOptions.getAsJsonPrimitive("freeze").getAsBoolean(); } + if (regionOptions.has("protect")) { + protect = regionOptions.getAsJsonPrimitive("protect").getAsBoolean(); + } + if (regionOptions.has("color")) { String colorName = regionOptions.getAsJsonPrimitive("color").getAsString(); try { @@ -191,10 +205,6 @@ public class Region { } } - public Color getColor() { - return color; - } - public void setColor(Color color) { this.color = color; regionOptions.add("color", new JsonPrimitive(color.name())); @@ -217,36 +227,42 @@ public class Region { } } - public TNTMode getTntMode() { - return tntMode; - } - public void setTntMode(TNTMode tntMode) { this.tntMode = tntMode; - setLinkedRegion(region -> region.tntMode = tntMode); + setLinkedRegion(region -> { + region.tntMode = tntMode; + region.regionOptions.add("tnt", new JsonPrimitive(tntMode.name())); + }); regionOptions.add("tnt", new JsonPrimitive(tntMode.name())); } - public boolean isFreeze() { - return freeze; - } - public void setFreeze(boolean freeze) { this.freeze = freeze; - setLinkedRegion(region -> region.freeze = freeze); + setLinkedRegion(region -> { + region.freeze = freeze; + region.regionOptions.add("freeze", new JsonPrimitive(freeze)); + }); regionOptions.add("freeze", new JsonPrimitive(freeze)); } - public boolean isFire() { - return fire; - } - public void setFire(boolean fire) { this.fire = fire; - setLinkedRegion(region -> region.fire = fire); + setLinkedRegion(region -> { + region.fire = fire; + region.regionOptions.add("fire", new JsonPrimitive(fire)); + }); regionOptions.add("fire", new JsonPrimitive(fire)); } + public void setProtect(boolean protect) { + this.protect = protect; + setLinkedRegion(region -> { + region.protect = protect; + region.regionOptions.add("protect", new JsonPrimitive(protect)); + }); + regionOptions.add("protect", new JsonPrimitive(protect)); + } + public Point getMinPoint(RegionType regionType, RegionExtensionType regionExtensionType) { switch (regionType) { case BUILD: From 010bac9741013d2b10a37a12f6378055a4892982 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 9 Apr 2021 16:51:52 +0200 Subject: [PATCH 2/9] Add initial CommandProtect usability --- .../steamwar/bausystem/commands/CommandProtect.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java index 5917041..259fe14 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java @@ -48,6 +48,15 @@ public class CommandProtect extends SWCommand { if (!permissionCheck(p)) return; Region region = regionCheck(p); if (region == null) return; + if (Region.buildAreaEnabled()) { + region.setProtect(!region.isProtect()); + if (region.isProtect()) { + p.sendMessage(BauSystem.PREFIX + "§7Boden geschützt"); + } else { + p.sendMessage(BauSystem.PREFIX + "§7Boden Schutz aufgehoben"); + } + return; + } try { region.protect(null); p.sendMessage(BauSystem.PREFIX + "§7Boden geschützt"); @@ -60,6 +69,10 @@ public class CommandProtect extends SWCommand { @Register public void schematicProtectCommand(Player p, String s) { if (!permissionCheck(p)) return; + if (Region.buildAreaEnabled()) { + genericHelp(p); + return; + } Region region = regionCheck(p); if (region == null) return; Schematic schem = Schematic.getSchemFromDB(s, p.getUniqueId()); From 4098d70a2395147f7fd3d32b1328e3d86531b0e4 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 9 Apr 2021 18:11:17 +0200 Subject: [PATCH 3/9] Add CommandProtect capabilities Add Region.getProtectYLevel --- .../bausystem/commands/CommandProtect.java | 24 ++++++++++++++++++- .../bausystem/world/regions/Region.java | 4 ++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java index 259fe14..117e8d7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java @@ -23,18 +23,26 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.world.Welt; import de.steamwar.bausystem.world.regions.Region; +import de.steamwar.bausystem.world.regions.RegionExtensionType; +import de.steamwar.bausystem.world.regions.RegionType; import de.steamwar.command.SWCommand; import de.steamwar.sql.Schematic; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityExplodeEvent; import java.io.IOException; import java.util.logging.Level; -public class CommandProtect extends SWCommand { +public class CommandProtect extends SWCommand implements Listener { public CommandProtect() { super("protect"); + if (Region.buildAreaEnabled()) { + Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin()); + } } @Register(help = true) @@ -105,4 +113,18 @@ public class CommandProtect extends SWCommand { } return region; } + + @EventHandler + public void onExplode(EntityExplodeEvent event) { + event.blockList().removeIf(block -> { + Region region = Region.getRegion(block.getLocation()); + if (!region.isProtect()) { + return false; + } + if (!region.hasProtection()) { + return false; + } + return block.getY() < region.getProtectYLevel(); + }); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Region.java index 723587d..065f020 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Region.java @@ -326,6 +326,10 @@ public class Region { undosessions.push(prototype.protect(this, schem)); } + public int getProtectYLevel() { + return getMinPoint(RegionType.TESTBLOCK, RegionExtensionType.NORMAL).getY(); + } + public boolean hasExtensionArea(RegionType regionType) { switch (regionType) { case BUILD: From bcc972ab6b2cf8f32d43e15f2e0b31e6193b4a0b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 9 Apr 2021 18:16:19 +0200 Subject: [PATCH 4/9] Add BauScoreboard Protect section --- .../src/de/steamwar/bausystem/world/BauScoreboard.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java index 5ba1eb3..f01e67c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -66,6 +66,9 @@ public class BauScoreboard implements Listener { strings.add("§eFire§8: " + (region.isFire() ? "§aaus" : "§can")); strings.add("§eTrace§8: " + RecordStateMachine.getRecordStatus().getName()); strings.add("§eLoader§8: " + (AutoLoader.hasLoader(p) ? "§aan" : "§caus")); + if (region.hasProtection()) { + strings.add("§eProtect§8: " + (region.isProtect() ? "§aan" : "§caus")); + } if (RecordStateMachine.getRecordStatus().isTracing()) { strings.add("§3"); From f95fb01eb12cdaa4c671f107b67585ebb79259ff Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 9 Apr 2021 18:43:53 +0200 Subject: [PATCH 5/9] Update CommandProtect message sending Add CommandInfo protect status --- .../de/steamwar/bausystem/commands/CommandInfo.java | 12 +++++++++--- .../steamwar/bausystem/commands/CommandProtect.java | 6 ++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java index c6b245d..f3c9b31 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java @@ -20,8 +20,8 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.world.regions.Region; import de.steamwar.bausystem.world.TPSUtils; +import de.steamwar.bausystem.world.regions.Region; import de.steamwar.command.SWCommand; import de.steamwar.core.TPSWatcher; import de.steamwar.sql.BauweltMember; @@ -52,11 +52,15 @@ public class CommandInfo extends SWCommand { p.sendMessage(BauSystem.PREFIX + "Besitzer: §e" + SteamwarUser.get(BauSystem.getOwnerID()).getUserName()); Region region = Region.getRegion(p.getLocation()); p.sendMessage(BauSystem.PREFIX + "§eTNT§8: " + region.getTntMode().getName() + " §eFire§8: " + (region.isFire() ? "§aAUS" : "§cAN") + " §eFreeze§8: " + (region.isFreeze() ? "§aAN" : "§cAUS")); + if (region.hasProtection()) { + p.sendMessage(BauSystem.PREFIX + "§eProtect§8: " + (region.isProtect() ? "§aAN" : "§cAUS")); + } List members = BauweltMember.getMembers(BauSystem.getOwnerID()); StringBuilder membermessage = new StringBuilder().append(BauSystem.PREFIX).append("Mitglieder: "); - for (BauweltMember member : members) { + for ( + BauweltMember member : members) { membermessage.append("§e").append(SteamwarUser.get(member.getMemberID()).getUserName()).append("§8["); membermessage.append(member.isWorldEdit() ? "§a" : "§c").append("WE").append("§8,"); membermessage.append(member.isWorld() ? "§a" : "§c").append("W").append("§8]").append(" "); @@ -64,7 +68,9 @@ public class CommandInfo extends SWCommand { p.sendMessage(membermessage.toString()); StringBuilder tpsMessage = new StringBuilder(); - tpsMessage.append(BauSystem.PREFIX).append("TPS:§e"); + tpsMessage.append(BauSystem.PREFIX). + + append("TPS:§e"); tpsMessage.append(" ").append(getTps(TPSWatcher.TPSType.ONE_SECOND)); tpsMessage.append(" ").append(getTps(TPSWatcher.TPSType.TEN_SECONDS)); if (!TPSUtils.isWarping()) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java index 117e8d7..249d512 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java @@ -23,8 +23,6 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.world.Welt; import de.steamwar.bausystem.world.regions.Region; -import de.steamwar.bausystem.world.regions.RegionExtensionType; -import de.steamwar.bausystem.world.regions.RegionType; import de.steamwar.command.SWCommand; import de.steamwar.sql.Schematic; import org.bukkit.Bukkit; @@ -59,9 +57,9 @@ public class CommandProtect extends SWCommand implements Listener { if (Region.buildAreaEnabled()) { region.setProtect(!region.isProtect()); if (region.isProtect()) { - p.sendMessage(BauSystem.PREFIX + "§7Boden geschützt"); + RegionUtils.actionBar(region, "§aBoden geschützt"); } else { - p.sendMessage(BauSystem.PREFIX + "§7Boden Schutz aufgehoben"); + RegionUtils.actionBar(region, "§cBoden Schutz aufgehoben"); } return; } From f3f3fb36258767659cdbd071e2fc3c2708f6527a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 9 Apr 2021 20:36:19 +0200 Subject: [PATCH 6/9] Update CommandProtect message sending Add CommandInfo protect status --- .../src/de/steamwar/bausystem/commands/CommandInfo.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java index f3c9b31..c8de3ad 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java @@ -68,9 +68,7 @@ public class CommandInfo extends SWCommand { p.sendMessage(membermessage.toString()); StringBuilder tpsMessage = new StringBuilder(); - tpsMessage.append(BauSystem.PREFIX). - - append("TPS:§e"); + tpsMessage.append(BauSystem.PREFIX).append("TPS:§e"); tpsMessage.append(" ").append(getTps(TPSWatcher.TPSType.ONE_SECOND)); tpsMessage.append(" ").append(getTps(TPSWatcher.TPSType.TEN_SECONDS)); if (!TPSUtils.isWarping()) { From 364267ae3c2997f2412cc9c6d33abb879fa73189 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 9 Apr 2021 20:36:34 +0200 Subject: [PATCH 7/9] Update CommandProtect message sending Add CommandInfo protect status --- .../src/de/steamwar/bausystem/commands/CommandInfo.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java index c8de3ad..b183140 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java @@ -59,8 +59,7 @@ public class CommandInfo extends SWCommand { List members = BauweltMember.getMembers(BauSystem.getOwnerID()); StringBuilder membermessage = new StringBuilder().append(BauSystem.PREFIX).append("Mitglieder: "); - for ( - BauweltMember member : members) { + for (BauweltMember member : members) { membermessage.append("§e").append(SteamwarUser.get(member.getMemberID()).getUserName()).append("§8["); membermessage.append(member.isWorldEdit() ? "§a" : "§c").append("WE").append("§8,"); membermessage.append(member.isWorld() ? "§a" : "§c").append("W").append("§8]").append(" "); From 9e899fe19543576573dede20ae743727892b5ec6 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 9 Apr 2021 22:30:25 +0200 Subject: [PATCH 8/9] Add /tb extension or /tb normal to reset extension area as well --- .../bausystem/commands/CommandSelect_12.java | 8 +- .../world/regions/RegionUtils_12.java | 32 +++++++ .../bausystem/world/regions/Region_12.java | 18 +++- .../bausystem/commands/CommandSelect_15.java | 8 +- .../world/regions/RegionUtils_15.java | 32 +++++++ .../bausystem/world/regions/Region_15.java | 23 +++-- .../bausystem/world/regions/PasteOptions.java | 94 +++++++++++++++++++ .../bausystem/commands/CommandTestblock.java | 21 ++++- .../bausystem/world/regions/Prototype.java | 38 +++++--- .../bausystem/world/regions/Region.java | 4 +- 10 files changed, 232 insertions(+), 46 deletions(-) create mode 100644 BauSystem_12/src/de/steamwar/bausystem/world/regions/RegionUtils_12.java create mode 100644 BauSystem_15/src/de/steamwar/bausystem/world/regions/RegionUtils_15.java create mode 100644 BauSystem_API/src/de/steamwar/bausystem/world/regions/PasteOptions.java diff --git a/BauSystem_12/src/de/steamwar/bausystem/commands/CommandSelect_12.java b/BauSystem_12/src/de/steamwar/bausystem/commands/CommandSelect_12.java index 144714e..3237e0b 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/commands/CommandSelect_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/commands/CommandSelect_12.java @@ -19,12 +19,12 @@ package de.steamwar.bausystem.commands; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.bukkit.BukkitWorld; import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.regions.selector.CuboidRegionSelector; import com.sk89q.worldedit.world.World; import de.steamwar.bausystem.world.regions.Point; +import de.steamwar.bausystem.world.regions.RegionUtils_12; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -34,11 +34,7 @@ class CommandSelect_12 { static final World BUKKITWORLD = new BukkitWorld(Bukkit.getWorlds().get(0)); static void setSelection(Player p, Point minPoint, Point maxPoint) { - WORLDEDIT_PLUGIN.getSession(p).setRegionSelector(BUKKITWORLD, new CuboidRegionSelector(BUKKITWORLD, toVector(minPoint), toVector(maxPoint))); - } - - private static Vector toVector(Point point) { - return Vector.toBlockPoint(point.getX(), point.getY(), point.getZ()); + WORLDEDIT_PLUGIN.getSession(p).setRegionSelector(BUKKITWORLD, new CuboidRegionSelector(BUKKITWORLD, RegionUtils_12.toVector(minPoint), RegionUtils_12.toVector(maxPoint))); } } diff --git a/BauSystem_12/src/de/steamwar/bausystem/world/regions/RegionUtils_12.java b/BauSystem_12/src/de/steamwar/bausystem/world/regions/RegionUtils_12.java new file mode 100644 index 0000000..f88b463 --- /dev/null +++ b/BauSystem_12/src/de/steamwar/bausystem/world/regions/RegionUtils_12.java @@ -0,0 +1,32 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.world.regions; + +import com.sk89q.worldedit.Vector; +import lombok.experimental.UtilityClass; + +@UtilityClass +public class RegionUtils_12 { + + public Vector toVector(Point point) { + return Vector.toBlockPoint(point.getX(), point.getY(), point.getZ()); + } + +} diff --git a/BauSystem_12/src/de/steamwar/bausystem/world/regions/Region_12.java b/BauSystem_12/src/de/steamwar/bausystem/world/regions/Region_12.java index d743f3b..dc49d8c 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/world/regions/Region_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/world/regions/Region_12.java @@ -20,13 +20,17 @@ package de.steamwar.bausystem.world.regions; import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.blocks.BlockID; import com.sk89q.worldedit.bukkit.BukkitWorld; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.math.transform.AffineTransform; +import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.world.World; import org.bukkit.Bukkit; @@ -40,7 +44,7 @@ class Region_12 { private Region_12() { } - static EditSession paste(File file, int x, int y, int z, boolean rotate, boolean ignoreAir) { + static EditSession paste(File file, int x, int y, int z, PasteOptions pasteOptions) throws MaxChangedBlocksException { World w = new BukkitWorld(Bukkit.getWorlds().get(0)); Clipboard clipboard; try { @@ -49,17 +53,17 @@ class Region_12 { throw new SecurityException("Bausystem schematic not found", e); } - return paste(clipboard, x, y, z, rotate, ignoreAir); + return paste(clipboard, x, y, z, pasteOptions); } - static EditSession paste(Clipboard clipboard, int x, int y, int z, boolean rotate, boolean ignoreAir) { + static EditSession paste(Clipboard clipboard, int x, int y, int z, PasteOptions pasteOptions) throws MaxChangedBlocksException { World w = new BukkitWorld(Bukkit.getWorlds().get(0)); Vector dimensions = clipboard.getDimensions(); Vector v = new Vector(x, y, z); Vector offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()); AffineTransform aT = new AffineTransform(); - if (rotate) { + if (pasteOptions.isRotate()) { aT = aT.rotateY(180); v = v.add(dimensions.getX() / 2 + dimensions.getX() % 2, 0, dimensions.getZ() / 2 + dimensions.getZ() % 2).subtract(offset.multiply(-1, 1, -1)).subtract(1, 0, 1); } else { @@ -69,7 +73,11 @@ class Region_12 { EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(w, -1); ClipboardHolder ch = new ClipboardHolder(clipboard, w.getWorldData()); ch.setTransform(aT); - Operations.completeBlindly(ch.createPaste(e, w.getWorldData()).to(v).ignoreAirBlocks(ignoreAir).build()); + + if (pasteOptions.isReset()) { + e.setBlocks(new CuboidRegion(RegionUtils_12.toVector(pasteOptions.getMinPoint()), RegionUtils_12.toVector(pasteOptions.getMaxPoint())), new BaseBlock(BlockID.AIR)); + } + Operations.completeBlindly(ch.createPaste(e, w.getWorldData()).to(v).ignoreAirBlocks(pasteOptions.isIgnoreAir()).build()); return e; } } diff --git a/BauSystem_15/src/de/steamwar/bausystem/commands/CommandSelect_15.java b/BauSystem_15/src/de/steamwar/bausystem/commands/CommandSelect_15.java index f69008a..8b4a280 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/commands/CommandSelect_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/commands/CommandSelect_15.java @@ -21,10 +21,10 @@ package de.steamwar.bausystem.commands; import com.sk89q.worldedit.bukkit.BukkitWorld; import com.sk89q.worldedit.bukkit.WorldEditPlugin; -import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.selector.CuboidRegionSelector; import com.sk89q.worldedit.world.World; import de.steamwar.bausystem.world.regions.Point; +import de.steamwar.bausystem.world.regions.RegionUtils_15; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -34,11 +34,7 @@ class CommandSelect_15 { static final World BUKKITWORLD = new BukkitWorld(Bukkit.getWorlds().get(0)); static void setSelection(Player p, Point minPoint, Point maxPoint) { - WORLDEDIT_PLUGIN.getSession(p).setRegionSelector(BUKKITWORLD, new CuboidRegionSelector(BUKKITWORLD, toBlockVector3(minPoint), toBlockVector3(maxPoint))); - } - - private static BlockVector3 toBlockVector3(Point point) { - return BlockVector3.at(point.getX(), point.getY(), point.getZ()); + WORLDEDIT_PLUGIN.getSession(p).setRegionSelector(BUKKITWORLD, new CuboidRegionSelector(BUKKITWORLD, RegionUtils_15.toBlockVector3(minPoint), RegionUtils_15.toBlockVector3(maxPoint))); } } diff --git a/BauSystem_15/src/de/steamwar/bausystem/world/regions/RegionUtils_15.java b/BauSystem_15/src/de/steamwar/bausystem/world/regions/RegionUtils_15.java new file mode 100644 index 0000000..2cc1d64 --- /dev/null +++ b/BauSystem_15/src/de/steamwar/bausystem/world/regions/RegionUtils_15.java @@ -0,0 +1,32 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.world.regions; + +import com.sk89q.worldedit.math.BlockVector3; +import lombok.experimental.UtilityClass; + +@UtilityClass +public class RegionUtils_15 { + + public BlockVector3 toBlockVector3(Point point) { + return BlockVector3.at(point.getX(), point.getY(), point.getZ()); + } + +} diff --git a/BauSystem_15/src/de/steamwar/bausystem/world/regions/Region_15.java b/BauSystem_15/src/de/steamwar/bausystem/world/regions/Region_15.java index 20177e8..1c622f8 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/world/regions/Region_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/world/regions/Region_15.java @@ -29,25 +29,25 @@ import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.transform.AffineTransform; +import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.session.ClipboardHolder; 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.world.Color; +import org.bukkit.Bukkit; + import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.Objects; -import de.steamwar.bausystem.world.Color; -import org.bukkit.Bukkit; - - class Region_15 { private Region_15() { } - static EditSession paste(File file, int x, int y, int z, boolean rotate, boolean ignoreAir, Color color) { + static EditSession paste(File file, int x, int y, int z, PasteOptions pasteOptions) { Clipboard clipboard; try (ClipboardReader reader = Objects.requireNonNull(ClipboardFormats.findByFile(file)).getReader(new FileInputStream(file))) { clipboard = reader.read(); @@ -55,25 +55,28 @@ class Region_15 { throw new SecurityException("Bausystem schematic not found", e); } - return paste(clipboard, x, y, z, rotate, ignoreAir, color); + return paste(clipboard, x, y, z, pasteOptions); } - static EditSession paste(Clipboard clipboard, int x, int y, int z, boolean rotate, boolean ignoreAir, Color color) { + static EditSession paste(Clipboard clipboard, int x, int y, int z, PasteOptions pasteOptions) { try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) { - changeColor(clipboard, color); + changeColor(clipboard, pasteOptions.getColor()); ClipboardHolder ch = new ClipboardHolder(clipboard); BlockVector3 dimensions = clipboard.getDimensions(); BlockVector3 v = BlockVector3.at(x, y, z); BlockVector3 offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()); - if (rotate) { + if (pasteOptions.isRotate()) { ch.setTransform(new AffineTransform().rotateY(180)); v = v.add(dimensions.getX() / 2, 0, dimensions.getZ() / 2).subtract(offset.multiply(-1, 1, -1)).subtract(1, 0, 1); } else { v = v.subtract(dimensions.getX() / 2, 0, dimensions.getZ() / 2).subtract(offset); } - Operations.completeBlindly(ch.createPaste(e).to(v).ignoreAirBlocks(ignoreAir).build()); + if (pasteOptions.isReset()) { + e.setBlocks(new CuboidRegion(RegionUtils_15.toBlockVector3(pasteOptions.getMinPoint()), RegionUtils_15.toBlockVector3(pasteOptions.getMaxPoint())), BlockTypes.AIR.getDefaultState().toBaseBlock()); + } + Operations.completeBlindly(ch.createPaste(e).to(v).ignoreAirBlocks(pasteOptions.isIgnoreAir()).build()); return e; } catch (WorldEditException e) { throw new SecurityException(e.getMessage(), e); diff --git a/BauSystem_API/src/de/steamwar/bausystem/world/regions/PasteOptions.java b/BauSystem_API/src/de/steamwar/bausystem/world/regions/PasteOptions.java new file mode 100644 index 0000000..52e58ff --- /dev/null +++ b/BauSystem_API/src/de/steamwar/bausystem/world/regions/PasteOptions.java @@ -0,0 +1,94 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.world.regions; + +import de.steamwar.bausystem.world.Color; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +@AllArgsConstructor +public class PasteOptions { + + /** + * Used in 1.12 and 1.15 + */ + private boolean rotate = false; + + /** + * Used in 1.12 and 1.15 + */ + private boolean ignoreAir = false; + + /** + * Used in 1.15 + */ + private Color color = Color.YELLOW; + + /** + * Used in 1.15 + */ + private boolean reset = false; + + /** + * Used in 1.15 + */ + private Point minPoint = null; + + /** + * Used in 1.15 + */ + private Point maxPoint = null; + + public PasteOptions(boolean rotate) { + this.rotate = rotate; + } + + public PasteOptions(boolean rotate, Color color) { + this.rotate = rotate; + this.color = color; + } + + public PasteOptions(boolean rotate, boolean ignoreAir) { + this.rotate = rotate; + this.ignoreAir = ignoreAir; + } + + public PasteOptions(boolean rotate, boolean ignoreAir, boolean reset) { + this.rotate = rotate; + this.ignoreAir = ignoreAir; + this.reset = reset; + } + + public PasteOptions(boolean rotate, Color color, boolean reset) { + this.rotate = rotate; + this.color = color; + this.reset = reset; + } + + public PasteOptions(boolean rotate, boolean ignoreAir, Color color) { + this.rotate = rotate; + this.ignoreAir = ignoreAir; + this.color = color; + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java index 45cc490..5ee1967 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java @@ -23,6 +23,7 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.world.regions.Region; import de.steamwar.bausystem.world.Welt; +import de.steamwar.bausystem.world.regions.RegionExtensionType; import de.steamwar.command.SWCommand; import de.steamwar.sql.Schematic; import org.bukkit.Bukkit; @@ -45,11 +46,16 @@ public class CommandTestblock extends SWCommand { @Register public void genericTestblockCommand(Player p) { + genericTestblockCommand(p, RegionExtensionType.NORMAL); + } + + @Register + public void genericTestblockCommand(Player p, RegionExtensionType regionExtensionType) { if (!permissionCheck(p)) return; Region region = regionCheck(p); if (region == null) return; try { - region.resetTestblock(null); + region.resetTestblock(null, regionExtensionType == RegionExtensionType.EXTENSION); p.sendMessage(BauSystem.PREFIX + "§7Testblock zurückgesetzt"); } catch (IOException e) { p.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen des Testblocks"); @@ -57,8 +63,19 @@ public class CommandTestblock extends SWCommand { } } + @Register public void schematicTestblockCommand(Player p, String s) { + schematicTestblockCommand(p, s, RegionExtensionType.NORMAL); + } + + @Register + public void schematicTestblockCommand(Player p, RegionExtensionType regionExtensionType, String s) { + schematicTestblockCommand(p, s, regionExtensionType); + } + + @Register + public void schematicTestblockCommand(Player p, String s, RegionExtensionType regionExtensionType) { if (!permissionCheck(p)) return; Region region = regionCheck(p); if (region == null) return; @@ -68,7 +85,7 @@ public class CommandTestblock extends SWCommand { return; } try { - region.resetTestblock(schem); + region.resetTestblock(schem, regionExtensionType == RegionExtensionType.EXTENSION); p.sendMessage(BauSystem.PREFIX + "§7Testblock zurückgesetzt"); } catch (IOException e) { p.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen des Testblocks"); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Prototype.java b/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Prototype.java index 9d91052..481e024 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Prototype.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Prototype.java @@ -145,16 +145,24 @@ public class Prototype { } public EditSession reset(Region region, Schematic schem, boolean ignoreAir, Color color) throws IOException, NoClipboardException { + return reset(region, schem, ignoreAir, color, false); + } + + public EditSession reset(Region region, Schematic schem, boolean ignoreAir, Color color, boolean reset) throws IOException, NoClipboardException { + PasteOptions pasteOptions; + if (reset) { + pasteOptions = new PasteOptions(rotate ^ (schem != null && (schem.getSchemType().fightType() || schem.getSchemType().check())), ignoreAir, color, true, getMinPoint(region, RegionExtensionType.EXTENSION), getMaxPoint(region, RegionExtensionType.EXTENSION)); + } else { + pasteOptions = new PasteOptions(rotate ^ (schem != null && (schem.getSchemType().fightType() || schem.getSchemType().check())), ignoreAir, color); + } + int x = region.minPoint.getX() + offsetX + sizeX / 2; int y = region.minPoint.getY() + offsetY; int z = region.minPoint.getZ() + offsetZ + sizeZ / 2; if (schem == null) { - return paste(new File(schematic), x, y, z, rotate, ignoreAir, color); + return paste(new File(schematic), x, y, z, pasteOptions); } else { - if (schem.getSchemType().fightType() || schem.getSchemType().check()) { - return paste(schem.load(), x, y, z, !rotate, ignoreAir, color); - } - return paste(schem.load(), x, y, z, rotate, ignoreAir, color); + return paste(schem.load(), x, y, z, pasteOptions); } } @@ -167,9 +175,9 @@ public class Prototype { int y = region.minPoint.getY() + testblock.offsetY - 1; int z = region.minPoint.getZ() + offsetZ + sizeZ / 2; if (schem == null) { - return paste(new File(protectSchematic), x, y, z, rotate, false, Color.YELLOW); + return paste(new File(protectSchematic), x, y, z, new PasteOptions(rotate, false, Color.YELLOW)); } else { - return paste(schem.load(), x, y, z, rotate, false, Color.YELLOW); + return paste(schem.load(), x, y, z, new PasteOptions(rotate, false, Color.YELLOW)); } } @@ -177,21 +185,21 @@ public class Prototype { return testblock != null; } - public EditSession resetTestblock(Region region, Schematic schem, Color color) throws IOException, NoClipboardException { - return testblock.reset(region, schem, false, color); + public EditSession resetTestblock(Region region, Schematic schem, Color color, boolean reset) throws IOException, NoClipboardException { + return testblock.reset(region, schem, false, color, reset); } private static boolean inRange(double l, int min, int size) { return min <= l && l < min + size; } - private static EditSession paste(File file, int x, int y, int z, boolean rotate, boolean ignoreAir, Color color) { //Type of protect - return (EditSession) VersionedCallable.call(new VersionedCallable(() -> Region_12.paste(file, x, y, z, rotate, ignoreAir), 8), - new VersionedCallable(() -> Region_15.paste(file, x, y, z, rotate, ignoreAir, color), 15)); + private static EditSession paste(File file, int x, int y, int z, PasteOptions pasteOptions) { //Type of protect + return (EditSession) VersionedCallable.call(new VersionedCallable(() -> Region_12.paste(file, x, y, z, pasteOptions), 8), + new VersionedCallable(() -> Region_15.paste(file, x, y, z, pasteOptions), 15)); } - private static EditSession paste(Clipboard clipboard, int x, int y, int z, boolean rotate, boolean ignoreAir, Color color) { - return (EditSession) VersionedCallable.call(new VersionedCallable(() -> Region_12.paste(clipboard, x, y, z, rotate, ignoreAir), 8), - new VersionedCallable(() -> Region_15.paste(clipboard, x, y, z, rotate, ignoreAir, color), 15)); + private static EditSession paste(Clipboard clipboard, int x, int y, int z, PasteOptions pasteOptions) { + return (EditSession) VersionedCallable.call(new VersionedCallable(() -> Region_12.paste(clipboard, x, y, z, pasteOptions), 8), + new VersionedCallable(() -> Region_15.paste(clipboard, x, y, z, pasteOptions), 15)); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Region.java index a02edfb..f762e02 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Region.java @@ -296,9 +296,9 @@ public class Region { return prototype.hasTestblock(); } - public void resetTestblock(Schematic schem) throws IOException, NoClipboardException { + public void resetTestblock(Schematic schem, boolean reset) throws IOException, NoClipboardException { initSessions(); - undosessions.push(prototype.resetTestblock(this, schem, color)); + undosessions.push(prototype.resetTestblock(this, schem, color, reset)); } public boolean hasProtection() { From a6e32e08cfd3ff3198875f205a0751273b97db5a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 10 Apr 2021 18:40:11 +0200 Subject: [PATCH 9/9] Simplify CommandProtect --- .../steamwar/bausystem/commands/CommandProtect.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java index 249d512..1ac7468 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java @@ -114,14 +114,11 @@ public class CommandProtect extends SWCommand implements Listener { @EventHandler public void onExplode(EntityExplodeEvent event) { + Region region = Region.getRegion(event.getLocation()); + if (!region.isProtect() && !region.hasProtection()) { + return; + } event.blockList().removeIf(block -> { - Region region = Region.getRegion(block.getLocation()); - if (!region.isProtect()) { - return false; - } - if (!region.hasProtection()) { - return false; - } return block.getY() < region.getProtectYLevel(); }); }