WorldGuard - Checking if a player is in a region

Discussion in 'Plugin Development' started by thehutch, Feb 9, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    thehutch

    Any ideas on how to check if a player is in a region? I have this so far but wasn't sure if there is a better less CPU intensive method?:

    Code:java
    1.  
    2. public boolean test1(Player p, World w) {
    3. WorldGuardPlugin wg = new WorldGuardPlugin();
    4. for(ProtectedRegion pr : wg.getRegionManager(w).getRegions().values()) {
    5. if (pr.contains(p.getLocation().getBlockX(), p.getLocation().getBlockY(), p.getLocation().getBlockZ())) {
    6. return true;
    7. }
    8. }
    9. return false;
    10. }
    11.  
     
  2. Offline

    nisovin

    Create a Vector (a WorldEdit Vector, not a Bukkit Vector), then use wg.getRegionManager(w).getApplicableRegions(vector)
     
  3. Offline

    thehutch

    Ah ok thank you, also how do you use Flags I need to check if this region has PVP enabled?
     
Thread Status:
Not open for further replies.

Share This Page