Package dev.oumaimaa.kawaiiapi.region
Class Region
java.lang.Object
dev.oumaimaa.kawaiiapi.region.Region
Represents a cuboid region defined by two corner points.
Provides modern utilities for region manipulation, entity queries, and block operations
without deprecated APIs.
Features:
- Efficient entity retrieval using modern chunk-based queries
- Region overlap detection
- Region expansion and contraction
- Type-safe entity filtering
- Comprehensive boundary calculations
- Version:
- 1.0
- Author:
- KawaiiDevelopment
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@NotNull List<org.bukkit.block.Block> Gets a list of all blocks within this region.@NotNull Regionclone()Creates a copy of this region.booleanChecks if this region completely contains another region.@NotNull Regioncontract(int amount) Contracts the region in all directions by the specified amount.@NotNull Regionexpand(int amount) Expands the region in all directions by the specified amount.@NotNull org.bukkit.LocationGets the center location of the region.org.bukkit.Locationorg.bukkit.Location@NotNull List<org.bukkit.entity.Entity> Gets all entities within this region using modern chunk-based search.<T extends org.bukkit.entity.Entity>
@NotNull List<T> getEntitiesByType(@NotNull Class<T> entityClass) Gets all entities of a specific type within this region.doubleGets the height (Y-axis) of the region.@NotNull org.bukkit.LocationGets the maximum corner point of the region.@NotNull org.bukkit.LocationGets the minimum corner point of the region.@NotNull List<org.bukkit.entity.Player> Gets all players within this region.intGets the total number of blocks in this region.@Nullable org.bukkit.WorldgetWorld()Gets the world this region is located in.doubleGets the width (X-axis) of the region.doubleGets the depth (Z-axis) of the region.booleanisIn(@NotNull org.bukkit.Location loc) Checks if a location is within this region.booleanisPlayerIn(@NotNull org.bukkit.entity.Player player) Checks if a player is within this region.booleanisSet()Checks if both corners of the region are set.booleanChecks if this region overlaps with another region.voidsetCorner1(org.bukkit.Location corner1) voidsetCorner2(org.bukkit.Location corner2) toString()
-
Constructor Details
-
Region
public Region()Creates an uninitialized region with null corners. -
Region
public Region(@NotNull @NotNull org.bukkit.Location corner1, @NotNull @NotNull org.bukkit.Location corner2) Creates a region with the specified corner locations.- Parameters:
corner1- The first corner locationcorner2- The second corner location- Throws:
IllegalArgumentException- if corners are in different worlds or null
-
-
Method Details
-
isSet
public boolean isSet()Checks if both corners of the region are set.- Returns:
- true if the region is fully defined
-
getWorld
@Nullable public @Nullable org.bukkit.World getWorld()Gets the world this region is located in.- Returns:
- The world, or null if region is not set
-
isIn
public boolean isIn(@NotNull @NotNull org.bukkit.Location loc) Checks if a location is within this region.- Parameters:
loc- The location to check- Returns:
- true if the location is inside the region
- Throws:
IllegalStateException- if the region is not fully set
-
getTotalBlockSize
public int getTotalBlockSize()Gets the total number of blocks in this region.- Returns:
- The block count
-
getHeight
public double getHeight()Gets the height (Y-axis) of the region.- Returns:
- The height in blocks
-
getXWidth
public double getXWidth()Gets the width (X-axis) of the region.- Returns:
- The width in blocks
-
getZWidth
public double getZWidth()Gets the depth (Z-axis) of the region.- Returns:
- The depth in blocks
-
blockList
Gets a list of all blocks within this region. WARNING: This can be very memory-intensive for large regions. Consider using streaming methods for large regions.- Returns:
- List of all blocks in the region
- Throws:
IllegalStateException- if the region is not fully set
-
isPlayerIn
public boolean isPlayerIn(@NotNull @NotNull org.bukkit.entity.Player player) Checks if a player is within this region.- Parameters:
player- The player to check- Returns:
- true if the player is in the region
-
getEntities
Gets all entities within this region using modern chunk-based search. More efficient than the old block-by-block approach.- Returns:
- List of entities in the region
- Throws:
IllegalStateException- if the region is not fully set
-
getEntitiesByType
@NotNull public <T extends org.bukkit.entity.Entity> @NotNull List<T> getEntitiesByType(@NotNull @NotNull Class<T> entityClass) Gets all entities of a specific type within this region.- Type Parameters:
T- The entity type- Parameters:
entityClass- The class of entities to filter for- Returns:
- List of entities matching the type
-
getPlayers
Gets all players within this region.- Returns:
- List of players in the region
-
getCenter
@NotNull public @NotNull org.bukkit.Location getCenter()Gets the center location of the region.- Returns:
- The center location
- Throws:
IllegalStateException- if the region is not fully set
-
getMinimumPoint
@NotNull public @NotNull org.bukkit.Location getMinimumPoint()Gets the minimum corner point of the region.- Returns:
- Location of the minimum corner (lowest x, y, z)
- Throws:
IllegalStateException- if the region is not fully set
-
getMaximumPoint
@NotNull public @NotNull org.bukkit.Location getMaximumPoint()Gets the maximum corner point of the region.- Returns:
- Location of the maximum corner (highest x, y, z)
- Throws:
IllegalStateException- if the region is not fully set
-
expand
Expands the region in all directions by the specified amount.- Parameters:
amount- The amount to expand by (in blocks)- Returns:
- This region instance for method chaining
- Throws:
IllegalStateException- if the region is not fully set
-
contract
Contracts the region in all directions by the specified amount.- Parameters:
amount- The amount to contract by (in blocks)- Returns:
- This region instance for method chaining
-
overlaps
Checks if this region overlaps with another region.- Parameters:
other- The other region to check- Returns:
- true if the regions overlap
-
contains
Checks if this region completely contains another region.- Parameters:
other- The region to check- Returns:
- true if this region contains the other region
-
clone
-
toString
-
getCorner1
public org.bukkit.Location getCorner1() -
setCorner1
public void setCorner1(org.bukkit.Location corner1) -
getCorner2
public org.bukkit.Location getCorner2() -
setCorner2
public void setCorner2(org.bukkit.Location corner2)
-