/
WorldGuardUtilities.java
80 lines (60 loc) · 2.25 KB
/
WorldGuardUtilities.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package net.aufdemrand.denizen.utilities.depends;
import java.util.ArrayList;
import java.util.List;
import net.aufdemrand.denizen.objects.dList;
import org.bukkit.Location;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
public class WorldGuardUtilities {
/**
* Get all the regions a location is in, as a dList.
*
* @param location The location to check
*
* @return A dList of the regions
*/
public static dList getRegions(Location location) {
if (Depends.worldGuard == null) return null;
List<String> regionList = new ArrayList<String>();
ApplicableRegionSet currentRegions = Depends.worldGuard.getRegionManager
(location.getWorld()).getApplicableRegions(location);
for(ProtectedRegion thisRegion: currentRegions) {
regionList.add(thisRegion.getId());
}
return new dList(regionList);
}
/**
* Determine if a location is inside any Worldguard
* region.
*
* @param location The location to check
*
* @return Returns a boolean value
*/
public static boolean inRegion(Location location) {
if (Depends.worldGuard == null) return false;
ApplicableRegionSet currentRegions = Depends.worldGuard.getRegionManager
(location.getWorld()).getApplicableRegions(location);
return (currentRegions.size() > 0);
}
/**
* Determine if a location is inside a specific WorldGuard
* region.
*
* @param location The location to check
* @param region The WorldGuard region to check
*
* @return Returns a boolean value
*/
public static boolean inRegion(Location location, String region) {
if (Depends.worldGuard == null) return false;
ApplicableRegionSet currentRegions = Depends.worldGuard.getRegionManager
(location.getWorld()).getApplicableRegions(location);
for(ProtectedRegion thisRegion: currentRegions) {
if (thisRegion.getId().equalsIgnoreCase(region)) {
return true;
}
}
return false;
}
}