WorldGuard -> Checking if a User is in a Specific Region

Discussion in 'Plugin Development' started by Eggspurt, Jul 17, 2015.

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

    Eggspurt

    Basically what I want to do is /home and they can only type /home if they are in the Region Spawn. This is just an example.

    Thanks
     
  2. WorldGuardPlugin.inst().getGlobalRegionManager().get(world).getApplicableRegions(location)
     
  3. Offline

    Eggspurt

    That doesn't explain anything

    Code:
          ApplicableRegionSet set = WorldGuardPlugin.inst().getGlobalRegionManager().get(player.getWorld()).getApplicableRegions(player.getLocation());
              
    I have this but set. doesn't have anything relating to getRegionStanding or whatever. It has .equals and that doesn't work.
     
  4. @Eggspurt
    ApplicableRegionSet implements Iterable<ProtectedRegion>, you can iterate over it using a for loop
     
  5. Offline

    Eggspurt

    Would you happen to have an example?
     
  6. @Eggspurt
    Code:
    LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
    for(ProtectedRegion region : WorldGuardPlugin.inst().getGlobalRegionManager().get(player.getWorld()).getApplicableRegions(player.getLocation())) {
      if(!region.isMember(localPlayer)) {
        //The player is not a member of one of the regions here, so he's on someone elses property. Now you have the right to do with him what you want.
      }
    }
     
  7. Offline

    Eggspurt

    I mean to see if its a specific region... That's checking if it's a member of the region clearly :p
     
  8. @Eggspurt
    Maybe something like this
    Code:
    ProtectedRegion region = WorldGuardPlugin.inst().getGlobalRegionManager().get(world).getRegionExact("yourSpawnRegionName"); //Get a region by name
    if(region.contains(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()) { //Check if the location is in the region
      //The player is in the region, now allow them to use /home
    } else {
      //They're not in the region, so they're not allowed
    }
    
     
Thread Status:
Not open for further replies.

Share This Page