Class ProtectedRegion

java.lang.Object
com.sk89q.worldguard.protection.regions.ProtectedRegion
All Implemented Interfaces:
ChangeTracked, Comparable<ProtectedRegion>
Direct Known Subclasses:
GlobalProtectedRegion, ProtectedCuboidRegion, ProtectedPolygonalRegion

public abstract class ProtectedRegion extends Object implements ChangeTracked, Comparable<ProtectedRegion>
Represents a region that can be indexed and have spatial queries performed against it.

Instances can be modified and access from several threads at a time.

Note: this class has a natural ordering that is inconsistent with equals. Regions with identical ids (and also the same priority) may exist in different managers (or no manager at all), so care should be taken when comparing regions that have not been obtained from a single manager.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Thrown when setting a parent would create a circular inheritance situation.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
    protected com.sk89q.worldedit.math.BlockVector3
     
    protected com.sk89q.worldedit.math.BlockVector3
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clear the parent (set the parent to null).
    int
     
    boolean
    contains(int x, int y, int z)
    Check to see if a point is inside this region.
    boolean
    contains(com.sk89q.worldedit.math.BlockVector2 position)
    Check to see if a position is contained within this region.
    abstract boolean
    contains(com.sk89q.worldedit.math.BlockVector3 pt)
    Check to see if a point is inside this region.
    boolean
    containsAny(List<com.sk89q.worldedit.math.BlockVector2> positions)
    Check to see if any of the points are inside this region projected onto the X-Z plane.
    void
    Copy attributes from another region.
    <T extends Flag<V>, V>
    V
    getFlag(T flag)
    Get a flag's value.
    Get the map of flags.
    Gets the name of this region
    Return a list of regions from the given list of regions that intersect with this region.
    com.sk89q.worldedit.math.BlockVector3
    Get a vector containing the highest X, Y, and Z components for the corner of the axis-aligned bounding box that contains this region.
    Get the domain that contains the members of this region, which does not automatically include the owners.
    com.sk89q.worldedit.math.BlockVector3
    Get a vector containing the smallest X, Y, and Z components for the corner of the axis-aligned bounding box that contains this region.
    Get the domain that contains the owners of this region.
    Get the parent of the region, if one exists.
    abstract List<com.sk89q.worldedit.math.BlockVector2>
    Get points of the region projected onto the X-Z plane.
    int
    Get the priority of the region, where higher numbers indicate a higher priority.
    abstract RegionType
    Get the type of region.
    int
     
    boolean
    Checks whether a region has members or owners.
    protected boolean
    intersects(ProtectedRegion region, Area thisArea)
    Test whether the given region intersects with this area.
    protected boolean
    Checks if the bounding box of a region intersects with with the bounding box of this region.
    protected boolean
    Compares all edges of two regions to see if any of them intersect.
    boolean
    Tests whether changes have been made.
    boolean
    Checks whether a player is a member OR OWNER of the region or any of its parents.
    boolean
    isMember(String playerName)
    Deprecated.
    Names are deprecated, this will not return players added by UUID (LocalPlayer)
    boolean
    Checks whether a player is a member of the region or any of its parents.
    boolean
    Checks whether a player is an owner of region or any of its parents.
    boolean
    isOwner(String playerName)
    Deprecated.
    Names are deprecated, this will not return owners added by UUID (LocalPlayer)
    abstract boolean
    Return whether this type of region encompasses physical area.
    boolean
     
    static boolean
    Checks to see if the given ID is a valid ID.
    void
    setDirty(boolean dirty)
    Set whether changes have been made.
    <T extends Flag<V>, V>
    void
    setFlag(T flag, V val)
    Set a flag's value.
    void
    setFlags(Map<Flag<?>,Object> flags)
    Set the map of flags.
    void
    Set the members domain.
    protected void
    setMinMaxPoints(List<com.sk89q.worldedit.math.BlockVector3> points)
    Set the minimum and maximum points of the bounding box for a region
    void
    Set the owner domain.
    void
    Set the parent of this region.
    void
    setPriority(int priority)
    Set the priority of the region, where higher numbers indicate a higher priority.
     
    abstract int
    Get the number of blocks in this region.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • GLOBAL_REGION

      public static final String GLOBAL_REGION
      See Also:
    • min

      protected com.sk89q.worldedit.math.BlockVector3 min
    • max

      protected com.sk89q.worldedit.math.BlockVector3 max
  • Method Details

    • setMinMaxPoints

      protected void setMinMaxPoints(List<com.sk89q.worldedit.math.BlockVector3> points)
      Set the minimum and maximum points of the bounding box for a region
      Parameters:
      points - the points to set with at least one entry
    • getId

      public String getId()
      Gets the name of this region
      Returns:
      the name
    • isPhysicalArea

      public abstract boolean isPhysicalArea()
      Return whether this type of region encompasses physical area.
      Returns:
      Whether physical area is encompassed
    • getMinimumPoint

      public com.sk89q.worldedit.math.BlockVector3 getMinimumPoint()
      Get a vector containing the smallest X, Y, and Z components for the corner of the axis-aligned bounding box that contains this region.
      Returns:
      the minimum point
    • getMaximumPoint

      public com.sk89q.worldedit.math.BlockVector3 getMaximumPoint()
      Get a vector containing the highest X, Y, and Z components for the corner of the axis-aligned bounding box that contains this region.
      Returns:
      the maximum point
    • getPriority

      public int getPriority()
      Get the priority of the region, where higher numbers indicate a higher priority.
      Returns:
      the priority
    • setPriority

      public void setPriority(int priority)
      Set the priority of the region, where higher numbers indicate a higher priority.
      Parameters:
      priority - the priority to set
    • getParent

      @Nullable public ProtectedRegion getParent()
      Get the parent of the region, if one exists.
      Returns:
      the parent, or null
    • setParent

      public void setParent(@Nullable ProtectedRegion parent) throws ProtectedRegion.CircularInheritanceException
      Set the parent of this region. This checks to make sure that it will not result in circular inheritance.
      Parameters:
      parent - the new parent
      Throws:
      ProtectedRegion.CircularInheritanceException - when circular inheritance is detected
    • clearParent

      public void clearParent()
      Clear the parent (set the parent to null).
    • getOwners

      public DefaultDomain getOwners()
      Get the domain that contains the owners of this region.
      Returns:
      the domain
    • setOwners

      public void setOwners(DefaultDomain owners)
      Set the owner domain.
      Parameters:
      owners - the new domain
    • getMembers

      public DefaultDomain getMembers()
      Get the domain that contains the members of this region, which does not automatically include the owners.
      Returns:
      the members
    • setMembers

      public void setMembers(DefaultDomain members)
      Set the members domain.
      Parameters:
      members - the new domain
    • hasMembersOrOwners

      public boolean hasMembersOrOwners()
      Checks whether a region has members or owners.
      Returns:
      whether there are members or owners
    • isOwner

      public boolean isOwner(LocalPlayer player)
      Checks whether a player is an owner of region or any of its parents.
      Parameters:
      player - player to check
      Returns:
      whether an owner
    • isOwner

      @Deprecated public boolean isOwner(String playerName)
      Deprecated.
      Names are deprecated, this will not return owners added by UUID (LocalPlayer)
      Checks whether a player is an owner of region or any of its parents.
      Parameters:
      playerName - player name to check
      Returns:
      whether an owner
    • isMember

      public boolean isMember(LocalPlayer player)
      Checks whether a player is a member OR OWNER of the region or any of its parents.
      Parameters:
      player - player to check
      Returns:
      whether an owner or member
    • isMember

      @Deprecated public boolean isMember(String playerName)
      Deprecated.
      Names are deprecated, this will not return players added by UUID (LocalPlayer)
      Checks whether a player is a member OR OWNER of the region or any of its parents.
      Parameters:
      playerName - player name to check
      Returns:
      whether an owner or member
    • isMemberOnly

      public boolean isMemberOnly(LocalPlayer player)
      Checks whether a player is a member of the region or any of its parents.
      Parameters:
      player - player to check
      Returns:
      whether an member
    • getFlag

      @Nullable public <T extends Flag<V>, V> V getFlag(T flag)
      Get a flag's value.
      Type Parameters:
      T - the flag type
      V - the type of the flag's value
      Parameters:
      flag - the flag to check
      Returns:
      the value or null if isn't defined
    • setFlag

      public <T extends Flag<V>, V> void setFlag(T flag, @Nullable V val)
      Set a flag's value.
      Type Parameters:
      T - the flag type
      V - the type of the flag's value
      Parameters:
      flag - the flag to check
      val - the value to set
    • getFlags

      public Map<Flag<?>,Object> getFlags()
      Get the map of flags.
      Returns:
      the map of flags currently used for this region
    • setFlags

      public void setFlags(Map<Flag<?>,Object> flags)
      Set the map of flags.

      A copy of the map will be used.

      Parameters:
      flags - the flags to set
    • copyFrom

      public void copyFrom(ProtectedRegion other)
      Copy attributes from another region.
      Parameters:
      other - the other region
    • getPoints

      public abstract List<com.sk89q.worldedit.math.BlockVector2> getPoints()
      Get points of the region projected onto the X-Z plane.
      Returns:
      the points
    • volume

      public abstract int volume()
      Get the number of blocks in this region.
      Returns:
      the volume of this region in blocks
    • contains

      public abstract boolean contains(com.sk89q.worldedit.math.BlockVector3 pt)
      Check to see if a point is inside this region.
      Parameters:
      pt - The point to check
      Returns:
      Whether pt is in this region
    • contains

      public boolean contains(com.sk89q.worldedit.math.BlockVector2 position)
      Check to see if a position is contained within this region.
      Parameters:
      position - the position to check
      Returns:
      whether position is in this region
    • contains

      public boolean contains(int x, int y, int z)
      Check to see if a point is inside this region.
      Parameters:
      x - the x coordinate to check
      y - the y coordinate to check
      z - the z coordinate to check
      Returns:
      whether this region contains the point
    • containsAny

      public boolean containsAny(List<com.sk89q.worldedit.math.BlockVector2> positions)
      Check to see if any of the points are inside this region projected onto the X-Z plane.
      Parameters:
      positions - a list of positions
      Returns:
      true if contained
    • getType

      public abstract RegionType getType()
      Get the type of region.
      Returns:
      the type
    • getIntersectingRegions

      public List<ProtectedRegion> getIntersectingRegions(Collection<ProtectedRegion> regions)
      Return a list of regions from the given list of regions that intersect with this region.
      Parameters:
      regions - a list of regions to source from
      Returns:
      the elements of regions that intersect with this region
    • intersects

      protected boolean intersects(ProtectedRegion region, Area thisArea)
      Test whether the given region intersects with this area.
      Parameters:
      region - the region to test
      thisArea - an area object for this region
      Returns:
      true if the two regions intersect
    • intersectsBoundingBox

      protected boolean intersectsBoundingBox(ProtectedRegion region)
      Checks if the bounding box of a region intersects with with the bounding box of this region.
      Parameters:
      region - the region to check
      Returns:
      whether the given region intersects
    • intersectsEdges

      protected boolean intersectsEdges(ProtectedRegion region)
      Compares all edges of two regions to see if any of them intersect.
      Parameters:
      region - the region to check
      Returns:
      whether any edges of a region intersect
    • isTransient

      public boolean isTransient()
      Returns:
      true if this region should only be kept in memory and not be saved
    • isDirty

      public boolean isDirty()
      Description copied from interface: ChangeTracked
      Tests whether changes have been made.
      Specified by:
      isDirty in interface ChangeTracked
      Returns:
      true if this region is not transient and changes have been made.
    • setDirty

      public void setDirty(boolean dirty)
      Description copied from interface: ChangeTracked
      Set whether changes have been made.
      Specified by:
      setDirty in interface ChangeTracked
      Parameters:
      dirty - a new dirty state
    • compareTo

      public int compareTo(ProtectedRegion other)
      Specified by:
      compareTo in interface Comparable<ProtectedRegion>
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • isValidId

      public static boolean isValidId(String id)
      Checks to see if the given ID is a valid ID.
      Parameters:
      id - the id to check
      Returns:
      whether the region id given is valid