Solved World Guard API

Discussion in 'Plugin Development' started by Clybzotik, Feb 10, 2019.

  1. Offline

    Clybzotik

    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?
     
  2. Offline

    Tango_

    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;
        }
    
     
  3. Offline

    Clybzotik

    I dont know region name, how i can get it?
     
  4. Offline

    Tango_

    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.
     

Share This Page