From e75da0d8f4b9221c740a69f7ea69fae9d453e45b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 3 Apr 2021 19:35:37 +0200 Subject: [PATCH] Add Region.RegionExtensionType Add Region.RegionType --- .../bausystem/commands/CommandTNT.java | 4 +- .../bausystem/commands/RegionUtils.java | 2 +- .../de/steamwar/bausystem/world/Region.java | 163 ++++++++++-------- 3 files changed, 95 insertions(+), 74 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index c839afe..18553db 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -157,11 +157,11 @@ public class CommandTNT extends SWCommand implements Listener { event.blockList().removeIf(block -> { Region region = Region.getRegion(block.getLocation()); if (region.getTntMode() == TNTMode.ON) return false; - if (region.hasBuildRegion() && region.inBuildRegion(block.getLocation())) { + if (region.hasBuildRegion() && region.inBuildRegion(block.getLocation(), Region.RegionExtensionType.NORMAL)) { RegionUtils.actionBar(region, "§cEine Explosion hätte Blöcke im Baubereich zerstört"); return true; } - if (region.hasBuildRegion() && region.inBuildRegionExtension(block.getLocation())) { + if (region.hasBuildRegion() && region.inBuildRegion(block.getLocation(), Region.RegionExtensionType.EXTENSION)) { RegionUtils.actionBar(region, "§cEine Explosion hätte Blöcke im Ausfahrbereich zerstört"); return true; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionUtils.java index 24dcedd..49901e0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionUtils.java @@ -30,7 +30,7 @@ public class RegionUtils { if (Region.GlobalRegion.isGlobalRegion(region)) { Bukkit.getOnlinePlayers().stream().filter(player -> Region.getRegion(player.getLocation()) == null).forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s))); } else { - Bukkit.getOnlinePlayers().stream().filter(player -> region.inRegion(player.getLocation())).forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s))); + Bukkit.getOnlinePlayers().stream().filter(player -> region.inRegion(player.getLocation(), Region.RegionExtensionType.NORMAL)).forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s))); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index c9d746a..53bb16a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -26,9 +26,6 @@ import de.steamwar.bausystem.commands.CommandTNT.TNTMode; import de.steamwar.core.VersionedCallable; import de.steamwar.sql.NoClipboardException; import de.steamwar.sql.Schematic; -import java.awt.*; -import java.util.List; - import lombok.AllArgsConstructor; import lombok.Getter; import org.bukkit.Bukkit; @@ -80,7 +77,7 @@ public class Region { public static Region getRegion(Location location) { for (Region region : regions) { - if (region.inRegion(location)) return region; + if (region.inRegion(location, RegionExtensionType.NORMAL)) return region; } return GlobalRegion.getInstance(); } @@ -158,44 +155,52 @@ public class Region { setLinkedRegion(region -> region.fire = fire); } - public Point getMinPoint() { - return prototype.getMinPoint(this); + public Point getMinPoint(RegionType regionType, RegionExtensionType regionExtensionType) { + switch (regionType) { + case BUILD_AREA: + return prototype.buildArea.getMinPoint(this, regionExtensionType); + case TESTBLOCK: + return prototype.testblock.getMinPoint(this, regionExtensionType); + default: + case NORMAL: + return prototype.getMinPoint(this, regionExtensionType); + } } - public Point getMaxPoint() { - return prototype.getMaxPoint(this); + public Point getMaxPoint(RegionType regionType, RegionExtensionType regionExtensionType) { + switch (regionType) { + case BUILD_AREA: + return prototype.buildArea.getMaxPoint(this, regionExtensionType); + case TESTBLOCK: + return prototype.testblock.getMaxPoint(this, regionExtensionType); + default: + case NORMAL: + return prototype.getMaxPoint(this, regionExtensionType); + } } - public Point getMinPointExtension() { - return prototype.getMinPointExtension(this); + public boolean inRegion(Location l, RegionType regionType, RegionExtensionType regionExtensionType) { + switch (regionType) { + case BUILD_AREA: + return prototype.buildArea.inRegion(this, l, regionExtensionType); + case TESTBLOCK: + return prototype.testblock.inRegion(this, l, regionExtensionType); + default: + case NORMAL: + return prototype.inRegion(this, l, regionExtensionType); + } } - public Point getMaxPointExtension() { - return prototype.getMaxPointExtension(this); - } - - public Point getMinPointBuildArea() { - return prototype.buildArea.getMinPoint(this); - } - - public Point getMaxPointBuildArea() { - return prototype.buildArea.getMaxPoint(this); - } - - public boolean inRegion(Location l) { - return prototype.inRegion(this, l); + public boolean inRegion(Location l, RegionExtensionType regionExtensionType) { + return prototype.inRegion(this, l, regionExtensionType); } public boolean hasBuildRegion() { return prototype.buildArea != null; } - public boolean inBuildRegion(Location l) { - return prototype.buildArea.inRegion(this, l); - } - - public boolean inBuildRegionExtension(Location l) { - return prototype.buildArea.inRegionExtension(this, l); + public boolean inBuildRegion(Location l, RegionExtensionType regionExtensionType) { + return prototype.buildArea.inRegion(this, l, regionExtensionType); } public void reset() throws IOException { @@ -292,7 +297,7 @@ public class Region { } @Override - public boolean inRegion(Location l) { + public boolean inRegion(Location l, RegionExtensionType regionExtensionType) { return true; } @@ -382,50 +387,55 @@ public class Region { if (!config.getName().equals("testblock") && !config.getName().equals("buildArea")) prototypes.put(config.getName(), this); } - - public Point getMinPoint(Region region) { - return new Point( - region.minPoint.getX() + offsetX, - region.minPoint.getY() + offsetY, - region.minPoint.getZ() + offsetZ - ); + + public Point getMinPoint(Region region, RegionExtensionType regionExtensionType) { + switch (regionExtensionType) { + case EXTENSION: + return new Point( + region.minPoint.getX() + offsetX - extensionAxisX, + region.minPoint.getY() + offsetY, + region.minPoint.getZ() + offsetZ - extensionNegativeZ + ); + default: + case NORMAL: + return new Point( + region.minPoint.getX() + offsetX, + region.minPoint.getY() + offsetY, + region.minPoint.getZ() + offsetZ + ); + } } - public Point getMaxPoint(Region region) { - return new Point( - region.minPoint.getX() + offsetX + sizeX, - region.minPoint.getY() + offsetY + sizeY, - region.minPoint.getZ() + offsetZ + sizeZ - ); + public Point getMaxPoint(Region region, RegionExtensionType regionExtensionType) { + switch (regionExtensionType) { + case EXTENSION: + return new Point( + region.minPoint.getX() + offsetX - extensionAxisX + (sizeX + extensionAxisX * 2), + region.minPoint.getY() + offsetY + sizeY + extensionPositiveY, + region.minPoint.getZ() + offsetZ - extensionNegativeZ + (sizeZ + extensionNegativeZ + extensionPositiveZ) + ); + default: + case NORMAL: + return new Point( + region.minPoint.getX() + offsetX + sizeX, + region.minPoint.getY() + offsetY + sizeY, + region.minPoint.getZ() + offsetZ + sizeZ + ); + } } - - public Point getMinPointExtension(Region region) { - return new Point( - region.minPoint.getX() + offsetX - extensionAxisX, - region.minPoint.getY() + offsetY, - region.minPoint.getZ() + offsetZ - extensionNegativeZ - ); - } - - public Point getMaxPointExtension(Region region) { - return new Point( - region.minPoint.getX() + offsetX - extensionAxisX + (sizeX + extensionAxisX * 2), - region.minPoint.getY() + offsetY + sizeY + extensionPositiveY, - region.minPoint.getZ() + offsetZ - extensionNegativeZ + (sizeZ + extensionNegativeZ + extensionPositiveZ) - ); - } - - public boolean inRegion(Region region, Location l) { - return inRange(l.getX(), region.minPoint.getX() + offsetX, sizeX) && - inRange(l.getY(), region.minPoint.getY() + offsetY, sizeY) && - inRange(l.getZ(), region.minPoint.getZ() + offsetZ, sizeZ); - } - - public boolean inRegionExtension(Region region, Location l) { - return inRange(l.getX(), region.minPoint.getX() + offsetX - extensionAxisX, sizeX + extensionAxisX * 2) && - inRange(l.getY(), region.minPoint.getY() + offsetY, sizeY + extensionPositiveY) && - inRange(l.getZ(), region.minPoint.getZ() + offsetZ - extensionNegativeZ, sizeZ + extensionNegativeZ + extensionPositiveZ); + public boolean inRegion(Region region, Location l, RegionExtensionType regionExtensionType) { + switch (regionExtensionType) { + case EXTENSION: + return inRange(l.getX(), region.minPoint.getX() + offsetX - extensionAxisX, sizeX + extensionAxisX * 2) && + inRange(l.getY(), region.minPoint.getY() + offsetY, sizeY + extensionPositiveY) && + inRange(l.getZ(), region.minPoint.getZ() + offsetZ - extensionNegativeZ, sizeZ + extensionNegativeZ + extensionPositiveZ); + default: + case NORMAL: + return inRange(l.getX(), region.minPoint.getX() + offsetX, sizeX) && + inRange(l.getY(), region.minPoint.getY() + offsetY, sizeY) && + inRange(l.getZ(), region.minPoint.getZ() + offsetZ, sizeZ); + } } public EditSession reset(Region region, Schematic schem) throws IOException, NoClipboardException { @@ -475,6 +485,17 @@ public class Region { } } + public enum RegionType { + NORMAL, + BUILD_AREA, + TESTBLOCK + } + + public enum RegionExtensionType { + NORMAL, + EXTENSION + } + @Getter @AllArgsConstructor public static class Point {