Class Cuboid

java.lang.Object
fr.maxlego08.zshop.zcore.utils.Cuboid
All Implemented Interfaces:
Cloneable, Iterable<org.bukkit.block.Block>, org.bukkit.configuration.serialization.ConfigurationSerializable

public class Cuboid extends Object implements Iterable<org.bukkit.block.Block>, Cloneable, org.bukkit.configuration.serialization.ConfigurationSerializable
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
     
    class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final String
    This class is a region/cuboid from one location to another.
    protected final int
     
    protected final int
     
    protected final int
     
    protected final int
     
    protected final int
     
    protected final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Cuboid(Cuboid other)
    Copy constructor.
    Construct a Cuboid using a map with the following keys: worldName, x1, x2, y1, y2, z1, z2
    Cuboid(org.bukkit.Location l1)
    Construct a one-block Cuboid at the given Location of the Cuboid.
    Cuboid(org.bukkit.Location l1, org.bukkit.Location l2)
    Construct a Cuboid given two Location objects which represent any two corners of the Cuboid.
    Cuboid(org.bukkit.World world, int x1, int y1, int z1, int x2, int y2, int z2)
    Construct a Cuboid in the given World and xyz co-ordinates
  • Method Summary

    Modifier and Type
    Method
    Description
     
    boolean
    contains(int x, int y, int z)
    Return true if the point at (x,y,z) is contained within this Cuboid.
    boolean
    contains(org.bukkit.block.Block b)
    Check if the given Block is contained within this Cuboid.
    boolean
    contains(org.bukkit.Location l)
    Check if the given Location is contained within this Cuboid.
    boolean
    containsOnly(int blockId)
    Check if the Cuboid contains only blocks of the given type
    Contract the Cuboid, returning a Cuboid with any air around the edges removed, just large enough to include all non-air blocks.
    Contract the Cuboid in the given direction, returning a new Cuboid which has no exterior empty space.
    org.bukkit.block.Block[]
    Get the Blocks at the eight corners of the Cuboid.
    expand(Cuboid.CuboidDirection dir, int amount)
    Expand the Cuboid in the given direction by the given amount.
    byte
    Get the average light level of all empty (air) blocks in the Cuboid.
    List<org.bukkit.block.Block>
    Get the blocks in the Cuboid.
    List<org.bukkit.block.Block>
    getBlocks(org.bukkit.Material material)
    Get the blocks in the Cuboid.
    Get the Cuboid big enough to hold both this Cuboid and the given one.
    org.bukkit.Location
    Get the the centre of the Cuboid.
    List<org.bukkit.Chunk>
    Get a list of the chunks which are fully or partially contained in this cuboid.
    Get the Cuboid representing the face of this Cuboid.
    org.bukkit.Location
    Get the Location of the lower northeast corner of the Cuboid (minimum XYZ co-ordinates).
    int
    Get the minimum X co-ordinate of this Cuboid
    int
    Get the minimum Y co-ordinate of this Cuboid
    int
    Get the minimum Z co-ordinate of this Cuboid
    org.bukkit.block.Block
    getRelativeBlock(int x, int y, int z)
    Get a block relative to the lower NE point of the Cuboid.
    org.bukkit.block.Block
    getRelativeBlock(org.bukkit.World w, int x, int y, int z)
    Get a block relative to the lower NE point of the Cuboid in the given World.
    int
    Get the size of this Cuboid along the X axis
    int
    Get the size of this Cuboid along the Y axis
    int
    Get the size of this Cuboid along the Z axis
    org.bukkit.Location
    Get the Location of the upper southwest corner of the Cuboid (maximum XYZ co-ordinates).
    int
    Get the maximum X co-ordinate of this Cuboid
    int
    Get the maximum Y co-ordinate of this Cuboid
    int
    Get the maximum Z co-ordinate of this Cuboid
    int
    Get the volume of this Cuboid.
    org.bukkit.World
    Get the Cuboid's world.
    inset(Cuboid.CuboidDirection dir, int amount)
    Inset (shrink) the Cuboid in the given direction by the given amount.
    Iterator<org.bukkit.block.Block>
     
    outset(Cuboid.CuboidDirection dir, int amount)
    Outset (grow) the Cuboid in the given direction by the given amount.
     
    shift(Cuboid.CuboidDirection dir, int amount)
    Shift the Cuboid in the given direction by the given amount.
     

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Field Details

    • worldName

      protected final String worldName
      This class is a region/cuboid from one location to another. It can be used for blocks protection and things like WorldEdit.
    • x1

      protected final int x1
    • y1

      protected final int y1
    • z1

      protected final int z1
    • x2

      protected final int x2
    • y2

      protected final int y2
    • z2

      protected final int z2
  • Constructor Details

    • Cuboid

      public Cuboid(org.bukkit.Location l1, org.bukkit.Location l2)
      Construct a Cuboid given two Location objects which represent any two corners of the Cuboid. Note: The 2 locations must be on the same world.
      Parameters:
      l1 - - One of the corners
      l2 - - The other corner
    • Cuboid

      public Cuboid(org.bukkit.Location l1)
      Construct a one-block Cuboid at the given Location of the Cuboid.
      Parameters:
      l1 - location of the Cuboid
    • Cuboid

      public Cuboid(Cuboid other)
      Copy constructor.
      Parameters:
      other - - The Cuboid to copy
    • Cuboid

      public Cuboid(org.bukkit.World world, int x1, int y1, int z1, int x2, int y2, int z2)
      Construct a Cuboid in the given World and xyz co-ordinates
      Parameters:
      world - - The Cuboid's world
      x1 - - X co-ordinate of corner 1
      y1 - - Y co-ordinate of corner 1
      z1 - - Z co-ordinate of corner 1
      x2 - - X co-ordinate of corner 2
      y2 - - Y co-ordinate of corner 2
      z2 - - Z co-ordinate of corner 2
    • Cuboid

      public Cuboid(Map<String,Object> map)
      Construct a Cuboid using a map with the following keys: worldName, x1, x2, y1, y2, z1, z2
      Parameters:
      map - - The map of keys.
  • Method Details

    • serialize

      public Map<String,Object> serialize()
      Specified by:
      serialize in interface org.bukkit.configuration.serialization.ConfigurationSerializable
    • getLowerNE

      public org.bukkit.Location getLowerNE()
      Get the Location of the lower northeast corner of the Cuboid (minimum XYZ co-ordinates).
      Returns:
      Location of the lower northeast corner
    • getUpperSW

      public org.bukkit.Location getUpperSW()
      Get the Location of the upper southwest corner of the Cuboid (maximum XYZ co-ordinates).
      Returns:
      Location of the upper southwest corner
    • getBlocks

      public List<org.bukkit.block.Block> getBlocks(org.bukkit.Material material)
      Get the blocks in the Cuboid.
      Returns:
      The blocks in the Cuboid
    • getBlocks

      public List<org.bukkit.block.Block> getBlocks()
      Get the blocks in the Cuboid.
      Returns:
      The blocks in the Cuboid
    • getCenter

      public org.bukkit.Location getCenter()
      Get the the centre of the Cuboid.
      Returns:
      Location at the centre of the Cuboid
    • getWorld

      public org.bukkit.World getWorld()
      Get the Cuboid's world.
      Returns:
      The World object representing this Cuboid's world
      Throws:
      IllegalStateException - if the world is not loaded
    • getSizeX

      public int getSizeX()
      Get the size of this Cuboid along the X axis
      Returns:
      Size of Cuboid along the X axis
    • getSizeY

      public int getSizeY()
      Get the size of this Cuboid along the Y axis
      Returns:
      Size of Cuboid along the Y axis
    • getSizeZ

      public int getSizeZ()
      Get the size of this Cuboid along the Z axis
      Returns:
      Size of Cuboid along the Z axis
    • getLowerX

      public int getLowerX()
      Get the minimum X co-ordinate of this Cuboid
      Returns:
      the minimum X co-ordinate
    • getLowerY

      public int getLowerY()
      Get the minimum Y co-ordinate of this Cuboid
      Returns:
      the minimum Y co-ordinate
    • getLowerZ

      public int getLowerZ()
      Get the minimum Z co-ordinate of this Cuboid
      Returns:
      the minimum Z co-ordinate
    • getUpperX

      public int getUpperX()
      Get the maximum X co-ordinate of this Cuboid
      Returns:
      the maximum X co-ordinate
    • getUpperY

      public int getUpperY()
      Get the maximum Y co-ordinate of this Cuboid
      Returns:
      the maximum Y co-ordinate
    • getUpperZ

      public int getUpperZ()
      Get the maximum Z co-ordinate of this Cuboid
      Returns:
      the maximum Z co-ordinate
    • corners

      public org.bukkit.block.Block[] corners()
      Get the Blocks at the eight corners of the Cuboid.
      Returns:
      array of Block objects representing the Cuboid corners
    • expand

      public Cuboid expand(Cuboid.CuboidDirection dir, int amount)
      Expand the Cuboid in the given direction by the given amount. Negative amounts will shrink the Cuboid in the given direction. Shrinking a cuboid's face past the opposite face is not an error and will return a valid Cuboid.
      Parameters:
      dir - - The direction in which to expand
      amount - - The number of blocks by which to expand
      Returns:
      A new Cuboid expanded by the given direction and amount
    • shift

      public Cuboid shift(Cuboid.CuboidDirection dir, int amount)
      Shift the Cuboid in the given direction by the given amount.
      Parameters:
      dir - - The direction in which to shift
      amount - - The number of blocks by which to shift
      Returns:
      A new Cuboid shifted by the given direction and amount
    • outset

      public Cuboid outset(Cuboid.CuboidDirection dir, int amount)
      Outset (grow) the Cuboid in the given direction by the given amount.
      Parameters:
      dir - - The direction in which to outset (must be Horizontal, Vertical, or Both)
      amount - - The number of blocks by which to outset
      Returns:
      A new Cuboid outset by the given direction and amount
    • inset

      public Cuboid inset(Cuboid.CuboidDirection dir, int amount)
      Inset (shrink) the Cuboid in the given direction by the given amount. Equivalent to calling outset() with a negative amount.
      Parameters:
      dir - - The direction in which to inset (must be Horizontal, Vertical, or Both)
      amount - - The number of blocks by which to inset
      Returns:
      A new Cuboid inset by the given direction and amount
    • contains

      public boolean contains(int x, int y, int z)
      Return true if the point at (x,y,z) is contained within this Cuboid.
      Parameters:
      x - - The X co-ordinate
      y - - The Y co-ordinate
      z - - The Z co-ordinate
      Returns:
      true if the given point is within this Cuboid, false otherwise
    • contains

      public boolean contains(org.bukkit.block.Block b)
      Check if the given Block is contained within this Cuboid.
      Parameters:
      b - - The Block to check for
      Returns:
      true if the Block is within this Cuboid, false otherwise
    • contains

      public boolean contains(org.bukkit.Location l)
      Check if the given Location is contained within this Cuboid.
      Parameters:
      l - - The Location to check for
      Returns:
      true if the Location is within this Cuboid, false otherwise
    • getVolume

      public int getVolume()
      Get the volume of this Cuboid.
      Returns:
      The Cuboid volume, in blocks
    • getAverageLightLevel

      public byte getAverageLightLevel()
      Get the average light level of all empty (air) blocks in the Cuboid. Returns 0 if there are no empty blocks.
      Returns:
      The average light level of this Cuboid
    • contract

      public Cuboid contract()
      Contract the Cuboid, returning a Cuboid with any air around the edges removed, just large enough to include all non-air blocks.
      Returns:
      A new Cuboid with no external air blocks
    • contract

      public Cuboid contract(Cuboid.CuboidDirection dir)
      Contract the Cuboid in the given direction, returning a new Cuboid which has no exterior empty space. E.g. A direction of Down will push the top face downwards as much as possible.
      Parameters:
      dir - - The direction in which to contract
      Returns:
      A new Cuboid contracted in the given direction
    • getFace

      public Cuboid getFace(Cuboid.CuboidDirection dir)
      Get the Cuboid representing the face of this Cuboid. The resulting Cuboid will be one block thick in the axis perpendicular to the requested face.
      Parameters:
      dir - - which face of the Cuboid to get
      Returns:
      The Cuboid representing this Cuboid's requested face
    • containsOnly

      public boolean containsOnly(int blockId)
      Check if the Cuboid contains only blocks of the given type
      Parameters:
      blockId - - The block ID to check for
      Returns:
      true if this Cuboid contains only blocks of the given type
    • getBoundingCuboid

      public Cuboid getBoundingCuboid(Cuboid other)
      Get the Cuboid big enough to hold both this Cuboid and the given one.
      Parameters:
      other - - The other cuboid.
      Returns:
      A new Cuboid large enough to hold this Cuboid and the given Cuboid
    • getRelativeBlock

      public org.bukkit.block.Block getRelativeBlock(int x, int y, int z)
      Get a block relative to the lower NE point of the Cuboid.
      Parameters:
      x - - The X co-ordinate
      y - - The Y co-ordinate
      z - - The Z co-ordinate
      Returns:
      The block at the given position
    • getRelativeBlock

      public org.bukkit.block.Block getRelativeBlock(org.bukkit.World w, int x, int y, int z)
      Get a block relative to the lower NE point of the Cuboid in the given World. This version of getRelativeBlock() should be used if being called many times, to avoid excessive calls to getWorld().
      Parameters:
      w - - The world
      x - - The X co-ordinate
      y - - The Y co-ordinate
      z - - The Z co-ordinate
      Returns:
      The block at the given position
    • getChunks

      public List<org.bukkit.Chunk> getChunks()
      Get a list of the chunks which are fully or partially contained in this cuboid.
      Returns:
      A list of Chunk objects
    • iterator

      public Iterator<org.bukkit.block.Block> iterator()
      Specified by:
      iterator in interface Iterable<org.bukkit.block.Block>
    • clone

      public Cuboid clone()
      Overrides:
      clone in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object