Class RegionManager

java.lang.Object
com.sk89q.worldguard.protection.managers.RegionManager

public final class RegionManager extends Object
A region manager holds the regions for a world.
  • Constructor Details

    • RegionManager

      public RegionManager(RegionDatabase store, Function<String,? extends ConcurrentRegionIndex> indexFactory, FlagRegistry flagRegistry)
      Create a new index.
      Parameters:
      store - the region store
      indexFactory - the factory for creating new instances of the index
      flagRegistry - the flag registry
  • Method Details

    • getName

      public String getName()
      Get a displayable name for this store.
    • load

      public void load() throws StorageException
      Load regions from storage and replace the index on this manager with the regions loaded from the store.

      This method will block until the save completes, but it will not block access to the region data from other threads, nor will it prevent the creation or modification of regions in the index while a new collection of regions is loaded from storage.

      Throws:
      StorageException - thrown when loading fails
    • save

      public void save() throws StorageException
      Save a snapshot of all the regions as it is right now to storage.
      Throws:
      StorageException - thrown on save error
    • saveChanges

      public boolean saveChanges() throws StorageException
      Save changes to the region index to disk, preferring to only save the changes (rather than the whole index), but choosing to save the whole index if the underlying store does not support partial saves.

      This method does nothing if there are no changes.

      Returns:
      true if there were changes to be saved
      Throws:
      StorageException - thrown on save error
    • loadChunk

      public void loadChunk(com.sk89q.worldedit.math.BlockVector2 position)
      Load the regions for a chunk.
      Parameters:
      position - the position
    • loadChunks

      public void loadChunks(Collection<com.sk89q.worldedit.math.BlockVector2> positions)
      Load the regions for a chunk.
      Parameters:
      positions - a collection of positions
    • unloadChunk

      public void unloadChunk(com.sk89q.worldedit.math.BlockVector2 position)
      Unload the regions for a chunk.
      Parameters:
      position - the position
    • getRegions

      public Map<String,ProtectedRegion> getRegions()
      Get an unmodifiable map of regions containing the state of the index at the time of call.

      This call is relatively heavy (and may block other threads), so refrain from calling it frequently.

      Returns:
      a map of regions
    • setRegions

      public void setRegions(Map<String,ProtectedRegion> regions)
      Replace the index with the regions in the given map.

      The parents of the regions will also be added to the index, even if they are not in the provided map.

      Parameters:
      regions - a map of regions
    • setRegions

      public void setRegions(Collection<ProtectedRegion> regions)
      Replace the index with the regions in the given collection.

      The parents of the regions will also be added to the index, even if they are not in the provided map.

      Parameters:
      regions - a collection of regions
    • addRegion

      public void addRegion(ProtectedRegion region)
      Aad a region to the manager.

      The parents of the region will also be added to the index.

      Parameters:
      region - the region
    • hasRegion

      public boolean hasRegion(String id)
      Return whether the index contains a region by the given name, with equality determined by Normal.
      Parameters:
      id - the name of the region
      Returns:
      true if this index contains the region
    • getRegion

      @Nullable public ProtectedRegion getRegion(String id)
      Get the region named by the given name (equality determined using Normal).
      Parameters:
      id - the name of the region
      Returns:
      a region or null
    • matchRegion

      @Nullable @Deprecated public ProtectedRegion matchRegion(String pattern)
      Deprecated.
      Use exact ids with getRegion(java.lang.String)
    • removeRegion

      @Nullable public Set<ProtectedRegion> removeRegion(String id)
      Remove a region from the index with the given name, opting to remove the children of the removed region.
      Parameters:
      id - the name of the region
      Returns:
      a list of removed regions where the first entry is the region specified by id
    • removeRegion

      @Nullable public Set<ProtectedRegion> removeRegion(String id, RemovalStrategy strategy)
      Remove a region from the index with the given name.
      Parameters:
      id - the name of the region
      strategy - what to do with children
      Returns:
      a list of removed regions where the first entry is the region specified by id
    • getApplicableRegions

      public ApplicableRegionSet getApplicableRegions(com.sk89q.worldedit.math.BlockVector3 position)
      Query for effective flags and members for the given position.

      RegionQuery.QueryOption.COMPUTE_PARENTS is used.

      Parameters:
      position - the position
      Returns:
      the query object
    • getApplicableRegions

      public ApplicableRegionSet getApplicableRegions(com.sk89q.worldedit.math.BlockVector3 position, RegionQuery.QueryOption option)
      Return a region set for the given position.
      Parameters:
      position - the position
      option - the option
      Returns:
      a region set
    • getApplicableRegions

      public ApplicableRegionSet getApplicableRegions(ProtectedRegion region)
      Query for effective flags and members for the area represented by the given region.

      RegionQuery.QueryOption.COMPUTE_PARENTS is used.

      Parameters:
      region - the region
      Returns:
      the query object
    • getApplicableRegions

      public ApplicableRegionSet getApplicableRegions(ProtectedRegion region, RegionQuery.QueryOption option)
      Return a region set for the area represented by the given region.
      Parameters:
      region - the region
      option - the option
      Returns:
      a region set
    • getApplicableRegionsIDs

      public List<String> getApplicableRegionsIDs(com.sk89q.worldedit.math.BlockVector3 position)
      Get a list of region names for regions that contain the given position.
      Parameters:
      position - the position
      Returns:
      a list of names
    • overlapsUnownedRegion

      public boolean overlapsUnownedRegion(ProtectedRegion region, LocalPlayer player)
      Return whether there are any regions intersecting the given region that are not owned by the given player.
      Parameters:
      region - the region
      player - the player
      Returns:
      true if there are such intersecting regions
    • size

      public int size()
      Get the number of regions.
      Returns:
      the number of regions
    • getRegionCountOfPlayer

      public int getRegionCountOfPlayer(LocalPlayer player)
      Get the number of regions that are owned by the given player.
      Parameters:
      player - the player
      Returns:
      name number of regions that a player owns