From e3c030602e6397394ecc267eb0eaa9c2e4be963d Mon Sep 17 00:00:00 2001 From: Eric Date: Fri, 31 May 2019 12:18:58 +0200 Subject: [PATCH] Added addRegion for a given selection --- .../IWorldGuardImplementation.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/api/src/main/java/org/codemc/worldguardwrapper/implementation/IWorldGuardImplementation.java b/api/src/main/java/org/codemc/worldguardwrapper/implementation/IWorldGuardImplementation.java index 3c5fe52..cd1b3fe 100644 --- a/api/src/main/java/org/codemc/worldguardwrapper/implementation/IWorldGuardImplementation.java +++ b/api/src/main/java/org/codemc/worldguardwrapper/implementation/IWorldGuardImplementation.java @@ -7,6 +7,9 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import org.codemc.worldguardwrapper.flag.IWrappedFlag; import org.codemc.worldguardwrapper.region.IWrappedRegion; +import org.codemc.worldguardwrapper.selection.ICuboidSelection; +import org.codemc.worldguardwrapper.selection.IPolygonalSelection; +import org.codemc.worldguardwrapper.selection.ISelection; import java.util.*; @@ -128,6 +131,24 @@ public interface IWorldGuardImplementation { return addRegion(id, Arrays.asList(point1, point2), 0, 0); } + /** + * Add a region for the given selection. + * + * @param id The region ID + * @param selection The selection for the region's volume + * @return The added region + */ + default Optional addRegion(@NonNull String id, @NonNull ISelection selection) { + if (selection instanceof ICuboidSelection) { + ICuboidSelection sel = (ICuboidSelection) selection; + return addCuboidRegion(id, sel.getMinimumPoint(), sel.getMaximumPoint()); + } else if (selection instanceof IPolygonalSelection) { + IPolygonalSelection sel = (IPolygonalSelection) selection; + return addRegion(id, new ArrayList<>(sel.getPoints()), sel.getMinimumY(), sel.getMaximumY()); + } + return Optional.empty(); + } + /** * Remove a region, including inheriting children. *