Class RegionManager
java.lang.Object
com.sk89q.worldguard.protection.managers.RegionManager
A region manager holds the regions for a world.
-
Constructor Summary
ConstructorsConstructorDescriptionRegionManager
(RegionDatabase store, Function<String, ? extends ConcurrentRegionIndex> indexFactory, FlagRegistry flagRegistry) Create a new index. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addRegion
(ProtectedRegion region) Aad a region to the manager.getApplicableRegions
(com.sk89q.worldedit.math.BlockVector3 position) Query for effective flags and members for the given position.getApplicableRegions
(com.sk89q.worldedit.math.BlockVector3 position, RegionQuery.QueryOption option) Return a region set for the given position.getApplicableRegions
(ProtectedRegion region) Query for effective flags and members for the area represented by the given region.getApplicableRegions
(ProtectedRegion region, RegionQuery.QueryOption option) Return a region set for the area represented by the given region.getApplicableRegionsIDs
(com.sk89q.worldedit.math.BlockVector3 position) Get a list of region names for regions that contain the given position.getName()
Get a displayable name for this store.Get the region named by the given name (equality determined usingNormal
).int
getRegionCountOfPlayer
(LocalPlayer player) Get the number of regions that are owned by the given player.Get an unmodifiable map of regions containing the state of the index at the time of call.boolean
Return whether the index contains a region by the given name, with equality determined byNormal
.void
load()
Load regions from storage and replace the index on this manager with the regions loaded from the store.void
loadChunk
(com.sk89q.worldedit.math.BlockVector2 position) Load the regions for a chunk.void
loadChunks
(Collection<com.sk89q.worldedit.math.BlockVector2> positions) Load the regions for a chunk.matchRegion
(String pattern) Deprecated.boolean
overlapsUnownedRegion
(ProtectedRegion region, LocalPlayer player) Return whether there are any regions intersecting the given region that are not owned by the given player.removeRegion
(String id) Remove a region from the index with the given name, opting to remove the children of the removed region.removeRegion
(String id, RemovalStrategy strategy) Remove a region from the index with the given name.void
save()
Save a snapshot of all the regions as it is right now to storage.boolean
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.void
setRegions
(Collection<ProtectedRegion> regions) Replace the index with the regions in the given collection.void
setRegions
(Map<String, ProtectedRegion> regions) Replace the index with the regions in the given map.int
size()
Get the number of regions.void
unloadChunk
(com.sk89q.worldedit.math.BlockVector2 position) Unload the regions for a chunk.
-
Constructor Details
-
RegionManager
public RegionManager(RegionDatabase store, Function<String, ? extends ConcurrentRegionIndex> indexFactory, FlagRegistry flagRegistry) Create a new index.- Parameters:
store
- the region storeindexFactory
- the factory for creating new instances of the indexflagRegistry
- the flag registry
-
-
Method Details
-
getName
Get a displayable name for this store. -
load
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
Save a snapshot of all the regions as it is right now to storage.- Throws:
StorageException
- thrown on save error
-
saveChanges
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
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
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
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
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
Aad a region to the manager.The parents of the region will also be added to the index.
- Parameters:
region
- the region
-
hasRegion
Return whether the index contains a region by the given name, with equality determined byNormal
.- Parameters:
id
- the name of the region- Returns:
- true if this index contains the region
-
getRegion
Get the region named by the given name (equality determined usingNormal
).- Parameters:
id
- the name of the region- Returns:
- a region or
null
-
matchRegion
Deprecated.Use exact ids withgetRegion(java.lang.String)
-
removeRegion
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
Remove a region from the index with the given name.- Parameters:
id
- the name of the regionstrategy
- what to do with children- Returns:
- a list of removed regions where the first entry is the region specified by
id
-
getApplicableRegions
Query for effective flags and members for the given position.- 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 positionoption
- the option- Returns:
- a region set
-
getApplicableRegions
Query for effective flags and members for the area represented by the given region.- 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 regionoption
- the option- Returns:
- a region set
-
getApplicableRegionsIDs
Get a list of region names for regions that contain the given position.- Parameters:
position
- the position- Returns:
- a list of names
-
overlapsUnownedRegion
Return whether there are any regions intersecting the given region that are not owned by the given player.- Parameters:
region
- the regionplayer
- 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
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
-
getRegion(java.lang.String)