7
7
import com .sk89q .worldguard .WorldGuard ;
8
8
import com .sk89q .worldguard .bukkit .WorldGuardPlugin ;
9
9
import 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 ;
10
13
import com .sk89q .worldguard .protection .managers .RegionManager ;
11
14
import com .sk89q .worldguard .protection .regions .ProtectedCuboidRegion ;
12
15
import com .sk89q .worldguard .protection .regions .ProtectedPolygonalRegion ;
17
20
import org .bukkit .block .Block ;
18
21
import org .bukkit .entity .Player ;
19
22
import org .bukkit .util .Vector ;
23
+ import org .jetbrains .annotations .NotNull ;
20
24
import org .jetbrains .annotations .Nullable ;
21
25
22
26
import java .util .ArrayList ;
27
+ import java .util .Arrays ;
23
28
import java .util .Collection ;
24
29
import java .util .List ;
30
+ import java .util .stream .Collectors ;
25
31
26
32
public class RegionUtils {
27
33
@@ -70,7 +76,13 @@ public static Collection<WorldGuardRegion> getRegionsAt(Location location) {
70
76
return regions ;
71
77
}
72
78
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 ) {
74
86
World world = location .getWorld ();
75
87
if (world == null ) {
76
88
return false ;
@@ -82,6 +94,22 @@ public static boolean canBuild(Player player, Location location) {
82
94
return getRegionContainer ().createQuery ().testBuild (BukkitAdapter .adapt (location ), WorldGuardPlugin .inst ().wrapPlayer (player ));
83
95
}
84
96
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
+
85
113
public static List <Block > getBlocksInRegion (WorldGuardRegion region ) {
86
114
ProtectedRegion protectedRegion = region .getRegion ();
87
115
List <Block > blocks = new ArrayList <>();
0 commit comments