Solved [ASK] Checking if player is in a WorldGuard region

Discussion in 'Spigot Plugin Development' started by Gober, Jul 8, 2018.

  1. What I want to check is how to check if Player Is Inside a WorldGuard Region / Not.
    I tried:
    Code (Java):
             
      for (String g : allowedregions) {
                        for (final ProtectedRegion reg : WGBukkit.getRegionManager(playerworld).getApplicableRegions(playerlocation)) {
                            if (reg.toString() == null) return; //This one is to check if player is in a WG Region / Not. (Doesnt work)
                            if (!reg.getId().equalsIgnoreCase(g)) {
                                return;
                            }
                        }
                    }
     
  2. region.contains(int x, int y)
     
  3. Code (Java):
        @EventHandler
        public void onMoveEvent(PlayerMoveEvent e) {
            ApplicableRegionSet regions = plugin.getWorldGuard().getRegionManager(e.getFrom().getWorld()).getApplicableRegions(e.getTo());
            if (regions.size() == 0) {
                //Do if not inside a region
            }
        }
     
    • Winner Winner x 1
  4. This is some old code I have on an old plugin. Be aware that the code is old and could be changed.
    Code (Java):

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

       public static boolean isInsideRegion(Player p, ArrayList<String> list) {
           RegionManager rm = WGBukkit.getRegionManager(p.getWorld());
           ApplicableRegionSet loc = rm.getApplicableRegions(p.getLocation());
       
           for (ProtectedRegion regionList : loc) {
               if (!isGlobal(p) && list.contains(regionList.getId().toLowerCase())) {
                   return true;
               }
           }
           return false;
       }

       public static List<String> getRegionList(Player p) {
           RegionManager rm = WGBukkit.getRegionManager(p.getWorld());
           ApplicableRegionSet loc = rm.getApplicableRegions(p.getLocation());
           ArrayList<String> list = new ArrayList<String>();
           if (isGlobal(p)) {
               return null;
           } else {
               for (ProtectedRegion regionList : loc) {
                   list.add(regionList.getId().toLowerCase());
               }
               return list;
           }
       }
     
     
    • Informative Informative x 1