Seeing if a player is in a region

Discussion in 'Spigot Plugin Development' started by MrXboxPlayer, Aug 10, 2018.

  1. Hey!

    I was wondering, by using the WorldGuard or WorldEdit API, how would I make an if statement like:

    if the player is in the region "spawn"

    If you could leave some code snippets, or do some explaining it would be much appreciated.

    Thank you and have an amazing day!
     
  2. Right out of my Utils class:
    Code (Java):

    public static boolean isGlobal(Player p) {
           RegionManager rm = WGBukkit.getRegionManager(p.getWorld());
           ApplicableRegionSet loc = rm.getApplicableRegions(p.getLocation());
           return loc.size() == 0;
       }

    public static boolean isInsideRegion(Player p, String region) {
           RegionManager rm = WGBukkit.getRegionManager(p.getWorld());
           ApplicableRegionSet loc = rm.getApplicableRegions(p.getLocation());
           if (isGlobal(p)) return false;
           for (ProtectedRegion regionList : loc) {
               if (regionList.getId().equals(region))
                   return true;
           }
           return false;
       }