77import com .sk89q .worldguard .WorldGuard ;
88import com .sk89q .worldguard .bukkit .WorldGuardPlugin ;
99import com .sk89q .worldguard .internal .platform .WorldGuardPlatform ;
10+ import com .sk89q .worldguard .protection .ApplicableRegionSet ;
11+ import com .sk89q .worldguard .protection .RegionResultSet ;
12+ import com .sk89q .worldguard .protection .flags .Flags ;
1013import com .sk89q .worldguard .protection .managers .RegionManager ;
1114import com .sk89q .worldguard .protection .regions .ProtectedCuboidRegion ;
1215import com .sk89q .worldguard .protection .regions .ProtectedPolygonalRegion ;
1720import org .bukkit .block .Block ;
1821import org .bukkit .entity .Player ;
1922import org .bukkit .util .Vector ;
23+ import org .jetbrains .annotations .NotNull ;
2024import org .jetbrains .annotations .Nullable ;
2125
2226import java .util .ArrayList ;
27+ import java .util .Arrays ;
2328import java .util .Collection ;
2429import java .util .List ;
30+ import java .util .stream .Collectors ;
2531
2632public class RegionUtils {
2733
@@ -70,7 +76,13 @@ public static Collection<WorldGuardRegion> getRegionsAt(Location location) {
7076 return regions ;
7177 }
7278
73- public static boolean canBuild (Player player , Location location ) {
79+ /**
80+ * Tests if a player can build at a given location.
81+ * @param player The player to test with
82+ * @param location The location to test at
83+ * @return Whether the given player can build at the location.
84+ */
85+ public static boolean canBuild (Player player , @ NotNull Location location ) {
7486 World world = location .getWorld ();
7587 if (world == null ) {
7688 return false ;
@@ -82,6 +94,22 @@ public static boolean canBuild(Player player, Location location) {
8294 return getRegionContainer ().createQuery ().testBuild (BukkitAdapter .adapt (location ), WorldGuardPlugin .inst ().wrapPlayer (player ));
8395 }
8496
97+ /**
98+ * Tests if a player can build in all the given regions.
99+ * @param player The player to test with
100+ * @param regions The regions to test against
101+ * @return Whether the given player can build in all the regions.
102+ */
103+ public static boolean canBuild (Player player , WorldGuardRegion ... regions ) {
104+ // create queryable set of regions
105+ ApplicableRegionSet regionSet = new RegionResultSet (
106+ (List <ProtectedRegion >) Arrays .stream (regions )
107+ .map (WorldGuardRegion ::getRegion )
108+ .collect (Collectors .toCollection (ArrayList ::new )), null );
109+ return regionSet .testState (WorldGuardPlugin .inst ().wrapPlayer (player ), Flags .BUILD );
110+ }
111+
112+
85113 public static List <Block > getBlocksInRegion (WorldGuardRegion region ) {
86114 ProtectedRegion protectedRegion = region .getRegion ();
87115 List <Block > blocks = new ArrayList <>();
0 commit comments