Hi, looked at all the documentation but could not find a method allowing to get the region knowing the location and the player. How i can do this?
Assuming you know the region name, you can use this to see if the players current location is inside a specific region. Code: public boolean isInRegion(Location loc, String region) { if(loc != null) { com.sk89q.worldedit.Vector v = new com.sk89q.worldedit.Vector(loc.getX(), loc.getBlockY(), loc.getZ()); return WGBukkit.getRegionManager(loc.getWorld()).getApplicableRegionsIDs(v).contains(region); } return false; }
Well if you don't know the region name, then you could do this: You can put this inside a move event for example, or pass through a players location into a method. Code: WorldGuardPlugin worldGuard = WGBukkit.getPlugin(); RegionManager regionManager = worldGuard.getRegionManager(player.getWorld()); ApplicableRegionSet regionsAtLocation = regionManager.getApplicableRegions(player.getLocation()); for (ProtectedRegion reg : regionsAtLocation) { Bukkit.broadcastMessage("Inside Region: " + reg.getId()); } Its a region set because the player could be in multiple regions at once.