Package redempt.redlib.region
Class MultiRegion
java.lang.Object
redempt.redlib.region.Region
redempt.redlib.region.Overlappable
redempt.redlib.region.MultiRegion
- All Implemented Interfaces:
Cloneable
Represents a collection of Regions forming any shape
-
Constructor Summary
ConstructorDescriptionMultiRegion
(List<Region> regions) Construct a MultiRegion using a list of RegionsMultiRegion
(Region... regions) Construct a MultiRegion using a vararg of Regions -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a Region to this MultiRegionvoid
automatically clusters regions in clusters of 10 until there are less than 25 top-level regionsclone()
Clones this MultiRegionvoid
cluster
(int per) Smartly groups Regions in close proximity into clusters.boolean
contains
(org.bukkit.Location location) Checks whether this MultiRegion contains the given Locationvoid
Flattens any clusters in this MultiRegion so that it is composed only of cuboid Regionsboolean
Determines whether this MultiRegion is equal to another Object based on itsgetRegions()
expand
(double posX, double negX, double posY, double negY, double posZ, double negZ) Expands the region, or retracts if negative.expand
(org.bukkit.block.BlockFace direction, double amount) Expands the MultiRegion in a given direction, or retracts if negative.static MultiRegion
fromString
(String input) Turns a String generated bytoString()
back into a MultiRegionint
Sums the block volume of all the Regions that make up this MultiRegion.org.bukkit.Location
getEnd()
getIntersection
(Overlappable other) Gets a MultiRegion representing the overlap.int
Recursively gets the number of Regions in this MultiRegionGets all the cuboid Regions that form this MultiRegionorg.bukkit.Location
getStart()
double
Sums the volume of all the Regions that make up this MultiRegion.int
hashCode()
Generates a hash code for this MultiRegion based on its Regionsboolean
move
(double x, double y, double z) move
(org.bukkit.util.Vector v) Moves this MultiRegion using the given vectorboolean
overlaps
(Overlappable overlap) Check if this Region overlaps with another.void
Recalculates this region to ensure it is using close to the least possible number of sub-regions with no overlaps.void
recalculate
(boolean autoCluster) Recalculates this region to ensure it is using close to the least possible number of sub-regions with no overlaps.rotate
(org.bukkit.Location center, int rotations) Rotates this MultiRegion and all of its sub-regions around the given pointprotected void
setLocations
(org.bukkit.Location start, org.bukkit.Location end) setWorld
(org.bukkit.World world) Sets the world of this MultiRegion and all of its sub-regions, while keeping the coordinates the sameStream<org.bukkit.block.Block>
stream()
A Stream of all the blocks in all of the Regions within this MultiRegion.void
Subtracts a Region from this MultiRegion.toString()
Converts this MultiRegion to a String which can be converted back to a MultiRegion usingfromString(String)
Please use this to persist MultiRegions, as most of the operations for manipulating a MultiRegion are far more expensive than the same operations would be for a Region.Methods inherited from class redempt.redlib.region.Region
contains, disableEvents, enableEvents, forEachBlock, getBlockDimensions, getCenter, getChunks, getCorners, getDimensions, getEntities, getEntities, getLoadedChunks, getPlayers, getWorld, measure, measureBlocks, protect, protect, toCuboid
-
Constructor Details
-
MultiRegion
Construct a MultiRegion using a list of Regions- Parameters:
regions
- The list of Regions
-
MultiRegion
Construct a MultiRegion using a vararg of Regions- Parameters:
regions
- The vararg of Regions
-
-
Method Details
-
setLocations
protected void setLocations(org.bukkit.Location start, org.bukkit.Location end) -
getStart
public org.bukkit.Location getStart() -
getEnd
public org.bukkit.Location getEnd() -
add
Adds a Region to this MultiRegion- Parameters:
region
- The Overlappable Region to add- Throws:
IllegalArgumentException
- if the Region is not Overlappable or is in another world
-
subtract
Subtracts a Region from this MultiRegion. A subtracted Region overrides all positive Regions, meaning adding a Region that overlaps a previously subtracted Region will not add the overlapping blocks. Callingrecalculate()
will coalesce into only added Regions.- Parameters:
region
- The Region to subtract
-
contains
public boolean contains(org.bukkit.Location location) Checks whether this MultiRegion contains the given Location -
getRegions
Gets all the cuboid Regions that form this MultiRegion- Returns:
- The list of Regions that form this MultiRegion
-
getBlockVolume
public int getBlockVolume()Sums the block volume of all the Regions that make up this MultiRegion. Will be inaccurate if any of the Regions overlap. Callrecalculate()
first.- Specified by:
getBlockVolume
in classRegion
- Returns:
- The volume of this MultiRegion
-
getVolume
public double getVolume()Sums the volume of all the Regions that make up this MultiRegion. Will be inaccurate if any of the Regions overlap. Callrecalculate()
first. -
clone
Clones this MultiRegion -
expand
Expands the MultiRegion in a given direction, or retracts if negative. Expanding takes a one-block wide slice on the face of the direction given, and duplicates it forward in that direction the given number of times. Retracting subtracts a region of n width in the direction given on the face of the direction. It is highly recommended to callrecalculate()
after calling this, especially if it is a retraction. This is a fairly expensive operation, so use it sparingly. -
expand
public MultiRegion expand(double posX, double negX, double posY, double negY, double posZ, double negZ) Expands the region, or retracts if negative. This makes 6 calls toexpand(BlockFace, double)
, meaning it is expensive. Avoid calling this method if possible.- Specified by:
expand
in classRegion
- Parameters:
posX
- The amount to expand the region in the positive X directionnegX
- The amount to expand the region in the negative X directionposY
- The amount to expand the region in the positive Y directionnegY
- The amount to expand the region in the negative Y directionposZ
- The amount to expand the region in the positive Z directionnegZ
- The amount to expand the region in the negative Z direction- Returns:
- Itself
-
autoCluster
public void autoCluster()automatically clusters regions in clusters of 10 until there are less than 25 top-level regions -
cluster
public void cluster(int per) Smartly groups Regions in close proximity into clusters. Sincecontains(Location)
first checks if the given Location is within the extreme corners of a MultiRegion, this will significantly increase the performance ofcontains(Location)
for MultiRegions which contain many Regions by allowing it to skip having to checkRegion.contains(Location)
on many nearby Regions. This method can be called multiple times, which will further cluster the clusters. It is recommended to useautoCluster()
in most cases.- Parameters:
per
- The number of Regions that should be in each cluster
-
decluster
public void decluster()Flattens any clusters in this MultiRegion so that it is composed only of cuboid Regions -
isClustered
public boolean isClustered()- Returns:
- Whether this MultiRegion has been clustered into smaller Regions
-
getRegionCount
public int getRegionCount()Recursively gets the number of Regions in this MultiRegion- Returns:
- The total number of cuboid Regions composing this MultiRegion
-
overlaps
Check if this Region overlaps with another.- Specified by:
overlaps
in classOverlappable
- Parameters:
overlap
- The Region to check against- Returns:
- Whether this Region overlaps with the given Region
-
getIntersection
Gets a MultiRegion representing the overlap. This is somewhat expensive.- Specified by:
getIntersection
in classOverlappable
- Parameters:
other
- The Region to check for overlap with- Returns:
- The overlapping portions of the Regions
-
move
Moves this MultiRegion using the given vector -
move
-
rotate
Rotates this MultiRegion and all of its sub-regions around the given point -
setWorld
Sets the world of this MultiRegion and all of its sub-regions, while keeping the coordinates the same -
recalculate
public void recalculate()Recalculates this region to ensure it is using close to the least possible number of sub-regions with no overlaps. This will coalesce the MultiRegion into only added Regions, but subtracted Regions will not be included in any of the Regions. Calling this method is somewhat expensive, but will make all other operations on this MultiRegion faster. After recalculating the regions, automatically clusters them in clusters of 10 until there are less than 25 top-level regions. -
recalculate
public void recalculate(boolean autoCluster) Recalculates this region to ensure it is using close to the least possible number of sub-regions with no overlaps. This will coalesce the MultiRegion into only added Regions, but subtracted Regions will not be included in any of the Regions. Calling this method is somewhat expensive, but will make all other operations on this MultiRegion faster.- Parameters:
autoCluster
- Whether to automatically cluster regions in clusters of 10 until there are less than 25 top-level regions
-
stream
A Stream of all the blocks in all of the Regions within this MultiRegion. May iterate the same block multiple times if any of the Regions overlap. Callrecalculate()
first. -
equals
Determines whether this MultiRegion is equal to another Object based on itsgetRegions()
-
hashCode
public int hashCode()Generates a hash code for this MultiRegion based on its Regions -
toString
Converts this MultiRegion to a String which can be converted back to a MultiRegion usingfromString(String)
Please use this to persist MultiRegions, as most of the operations for manipulating a MultiRegion are far more expensive than the same operations would be for a Region. If its shape is static, and it needs to be reused, save it. -
fromString
Turns a String generated bytoString()
back into a MultiRegion- Parameters:
input
- The String representation of a MultiRegion- Returns:
- The MultiRegion
-