Class MultiRegion

All Implemented Interfaces:
Cloneable

public class MultiRegion extends Overlappable
Represents a collection of Regions forming any shape
  • Constructor Details

    • MultiRegion

      public MultiRegion(List<Region> regions)
      Construct a MultiRegion using a list of Regions
      Parameters:
      regions - The list of Regions
    • MultiRegion

      public MultiRegion(Region... regions)
      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()
      Specified by:
      getStart in class Region
      Returns:
      The least extreme corner of the region, representing minimum X, Y, and Z coordinates
    • getEnd

      public org.bukkit.Location getEnd()
      Specified by:
      getEnd in class Region
      Returns:
      The most extreme corner of the region, representing maximum X, Y, and Z coordinates
    • add

      public void add(Region region)
      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

      public void subtract(Region region)
      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. Calling recalculate() 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
      Specified by:
      contains in class Region
      Parameters:
      location - The Location to check
      Returns:
      Whether the Location is contained within this MultiRegion
    • getRegions

      public List<Region> 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. Call recalculate() first.
      Specified by:
      getBlockVolume in class Region
      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. Call recalculate() first.
      Specified by:
      getVolume in class Region
      Returns:
      The volume of this MultiRegion
    • clone

      public MultiRegion clone()
      Clones this MultiRegion
      Specified by:
      clone in class Region
      Returns:
      A clone of this MultiRegion
    • expand

      public MultiRegion expand(org.bukkit.block.BlockFace direction, double amount)
      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 call recalculate() after calling this, especially if it is a retraction. This is a fairly expensive operation, so use it sparingly.
      Specified by:
      expand in class Region
      Parameters:
      direction - The direction to expand the region in
      amount - The amount to expand the region in the given direction
      Returns:
      Itself
    • 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 to expand(BlockFace, double), meaning it is expensive. Avoid calling this method if possible.
      Specified by:
      expand in class Region
      Parameters:
      posX - The amount to expand the region in the positive X direction
      negX - The amount to expand the region in the negative X direction
      posY - The amount to expand the region in the positive Y direction
      negY - The amount to expand the region in the negative Y direction
      posZ - The amount to expand the region in the positive Z direction
      negZ - 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. Since contains(Location) first checks if the given Location is within the extreme corners of a MultiRegion, this will significantly increase the performance of contains(Location) for MultiRegions which contain many Regions by allowing it to skip having to check Region.contains(Location) on many nearby Regions. This method can be called multiple times, which will further cluster the clusters. It is recommended to use autoCluster() 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

      public boolean overlaps(Overlappable overlap)
      Check if this Region overlaps with another.
      Specified by:
      overlaps in class Overlappable
      Parameters:
      overlap - The Region to check against
      Returns:
      Whether this Region overlaps with the given Region
    • getIntersection

      public MultiRegion getIntersection(Overlappable other)
      Gets a MultiRegion representing the overlap. This is somewhat expensive.
      Specified by:
      getIntersection in class Overlappable
      Parameters:
      other - The Region to check for overlap with
      Returns:
      The overlapping portions of the Regions
    • move

      public MultiRegion move(org.bukkit.util.Vector v)
      Moves this MultiRegion using the given vector
      Specified by:
      move in class Region
      Parameters:
      v - The vector to be applied to both corners of the region
      Returns:
      Itself
    • move

      public Region move(double x, double y, double z)
      Specified by:
      move in class Region
    • rotate

      public MultiRegion rotate(org.bukkit.Location center, int rotations)
      Rotates this MultiRegion and all of its sub-regions around the given point
      Specified by:
      rotate in class Region
      Parameters:
      center - The point to rotate this Region around
      rotations - The number of clockwise rotations to apply
      Returns:
      Itself
    • setWorld

      public MultiRegion setWorld(org.bukkit.World world)
      Sets the world of this MultiRegion and all of its sub-regions, while keeping the coordinates the same
      Specified by:
      setWorld in class Region
      Parameters:
      world - The world to set
      Returns:
      Itself
    • 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

      public Stream<org.bukkit.block.Block> 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. Call recalculate() first.
      Specified by:
      stream in class Region
      Returns:
      A Stream of all the blocks in this MultiRegion
    • equals

      public boolean equals(Object object)
      Determines whether this MultiRegion is equal to another Object based on its getRegions()
      Overrides:
      equals in class Region
      Parameters:
      object - The Object to compare to
      Returns:
      Whether the Object is equal to this MultiRegion
    • hashCode

      public int hashCode()
      Generates a hash code for this MultiRegion based on its Regions
      Overrides:
      hashCode in class Region
      Returns:
      The hash code of this MultiRegion
    • toString

      public String toString()
      Converts this MultiRegion to a String which can be converted back to a MultiRegion using fromString(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.
      Overrides:
      toString in class Object
      Returns:
      The String representation of this MultiRegion
    • fromString

      public static MultiRegion fromString(String input)
      Turns a String generated by toString() back into a MultiRegion
      Parameters:
      input - The String representation of a MultiRegion
      Returns:
      The MultiRegion