Class SubAreaManager

java.lang.Object
tfagaming.projects.minecraft.homestead.managers.SubAreaManager

public final class SubAreaManager extends Object
A utility class that manages SubArea creation, deletion, and queries.
  • Method Details

    • createSubArea

      public static SubArea createSubArea(Region region, String name, org.bukkit.World world, org.bukkit.block.Block point1, org.bukkit.block.Block point2)
      Create a new sub-area.
      Parameters:
      region - The region
      name - The sub-area name
      world - The world
      point1 - The first corner point
      point2 - The second corner point
      Returns:
      The created SubArea.
    • createSubArea

      public static SubArea createSubArea(long regionId, String name, org.bukkit.World world, org.bukkit.block.Block point1, org.bukkit.block.Block point2, long flags)
      Create a new sub-area.
      Parameters:
      regionId - The region ID
      name - The sub-area name
      world - The world
      point1 - The first corner point
      point2 - The second corner point
      flags - Default global player flags
      Returns:
      The created SubArea.
    • getAll

      public static List<SubArea> getAll()
      Returns an immutable view of every loaded sub-area.
      Returns:
      List of all sub-areas.
    • getSubAreaCount

      public static int getSubAreaCount()
      Returns the number of sub-areas in the server.
      Returns:
      Sub-area count.
    • getSubAreaCount

      public static int getSubAreaCount(Region region)
      Returns the number of sub-areas in a region.
      Parameters:
      region - The region
      Returns:
      Sub-area count.
    • getSubAreaCount

      public static int getSubAreaCount(long regionId)
      Returns the number of sub-areas in a region.
      Parameters:
      regionId - The region ID
      Returns:
      Sub-area count.
    • hasSubAreas

      public static boolean hasSubAreas(Region region)
      Checks if a region has any sub-areas.
      Parameters:
      region - The region
      Returns:
      true if sub-areas exist.
    • hasSubAreas

      public static boolean hasSubAreas(long regionId)
      Checks if a region has any sub-areas.
      Parameters:
      regionId - The region ID
      Returns:
      true if sub-areas exist.
    • getSubAreasOfRegion

      public static List<SubArea> getSubAreasOfRegion(Region region)
      Get sub-areas of a region.
      Parameters:
      region - The region
      Returns:
      List of sub-areas.
    • getSubAreasOfRegion

      public static List<SubArea> getSubAreasOfRegion(long regionId)
      Get sub-areas of a region.
      Parameters:
      regionId - The region ID
      Returns:
      List of sub-areas.
    • getSubAreasInWorld

      public static List<SubArea> getSubAreasInWorld(org.bukkit.World world)
      Returns all sub-areas in a specific world.
      Parameters:
      world - The world
      Returns:
      List of sub-areas.
    • getSubAreasInWorld

      public static List<SubArea> getSubAreasInWorld(UUID worldId)
      Returns all sub-areas in a specific world.
      Parameters:
      worldId - The world UUID
      Returns:
      List of sub-areas.
    • getSubAreaNames

      public static List<String> getSubAreaNames(Region region)
      Returns all sub-area names for a region (useful for GUIs).
      Parameters:
      region - The region
      Returns:
      List of names.
    • getSubAreaNames

      public static List<String> getSubAreaNames(long regionId)
      Returns all sub-area names for a region.
      Parameters:
      regionId - The region ID
      Returns:
      List of names.
    • findSubArea

      public static SubArea findSubArea(long id)
      Retrieves the sub-area with the exact ID, or null if none exists.
      Parameters:
      id - The sub-area ID
      Returns:
      The SubArea, or null.
    • findSubArea

      public static SubArea findSubArea(long regionId, String name)
      Retrieves the sub-area with the exact name (case-insensitive) within a region, or null if none exists.
      Parameters:
      regionId - The region ID
      name - The sub-area name
      Returns:
      The SubArea, or null.
    • findSubAreaHasBlockInside

      public static SubArea findSubAreaHasBlockInside(org.bukkit.block.Block block)
      Finds the sub-area containing the given block.
      Parameters:
      block - The block
      Returns:
      The SubArea, or null.
    • findSubAreaHasLocationInside

      public static SubArea findSubAreaHasLocationInside(org.bukkit.Location location)
      Finds the sub-area containing the given location.
      Parameters:
      location - The location
      Returns:
      The SubArea, or null.
    • findSubAreaByLocationInRegion

      public static SubArea findSubAreaByLocationInRegion(org.bukkit.Location location, long regionId)
      Finds the sub-area containing the given location, scoped to a specific region.
      Parameters:
      location - The location
      regionId - The region ID to search within
      Returns:
      The SubArea, or null.
    • isLocationInAnySubArea

      public static boolean isLocationInAnySubArea(org.bukkit.Location location)
      Checks if a location is inside any sub-area on the server.
      Parameters:
      location - The location
      Returns:
      true if inside any sub-area.
    • isBlockInAnySubArea

      public static boolean isBlockInAnySubArea(org.bukkit.block.Block block)
      Checks if a block is inside any sub-area on the server.
      Parameters:
      block - The block
      Returns:
      true if inside any sub-area.
    • isPlayerInSubArea

      public static boolean isPlayerInSubArea(org.bukkit.entity.Player player, SubArea subArea)
      Checks if a player is currently inside a specific sub-area.
      Parameters:
      player - The player
      subArea - The sub-area
      Returns:
      true if the player is inside.
    • getSubAreasIntersecting

      public static List<SubArea> getSubAreasIntersecting(SubArea subArea)
      Returns all sub-areas that intersect (overlap) with the given sub-area.
      Parameters:
      subArea - The sub-area to check
      Returns:
      List of intersecting sub-areas (excluding itself).
    • getSubAreasIntersectingRegion

      public static List<SubArea> getSubAreasIntersectingRegion(Region region)
      Returns all sub-areas in a region that intersect with region chunks.
      Parameters:
      region - The region
      Returns:
      List of sub-areas that overlap with the region's claimed chunks.
    • getSubAreasIntersectingRegion

      public static List<SubArea> getSubAreasIntersectingRegion(long regionId)
      Returns all sub-areas in a region that intersect with region chunks.
      Parameters:
      regionId - The region ID
      Returns:
      List of sub-areas that overlap with the region's claimed chunks.
    • getTotalVolume

      public static int getTotalVolume(Region region)
      Returns the total volume (in blocks) of all sub-areas in a region.
      Parameters:
      region - The region
      Returns:
      Total volume.
    • getTotalVolume

      public static int getTotalVolume(long regionId)
      Returns the total volume (in blocks) of all sub-areas in a region.
      Parameters:
      regionId - The region ID
      Returns:
      Total volume.
    • getLargestSubArea

      public static SubArea getLargestSubArea(Region region)
      Returns the largest sub-area in a region by volume.
      Parameters:
      region - The region
      Returns:
      The largest SubArea, or null.
    • getLargestSubArea

      public static SubArea getLargestSubArea(long regionId)
      Returns the largest sub-area in a region by volume.
      Parameters:
      regionId - The region ID
      Returns:
      The largest SubArea, or null.
    • getSubAreasByVolumeRange

      public static List<SubArea> getSubAreasByVolumeRange(Region region, int minVolume, int maxVolume)
      Returns sub-areas filtered by volume range.
      Parameters:
      region - The region
      minVolume - Minimum volume (inclusive)
      maxVolume - Maximum volume (inclusive)
      Returns:
      List of matching sub-areas.
    • getSubAreasByVolumeRange

      public static List<SubArea> getSubAreasByVolumeRange(long regionId, int minVolume, int maxVolume)
      Returns sub-areas filtered by volume range.
      Parameters:
      regionId - The region ID
      minVolume - Minimum volume (inclusive)
      maxVolume - Maximum volume (inclusive)
      Returns:
      List of matching sub-areas.
    • getSubAreaCenter

      public static org.bukkit.Location getSubAreaCenter(SubArea subArea)
      Calculates the center location of a sub-area.
      Parameters:
      subArea - The sub-area
      Returns:
      The center location, or null if world is unloaded.
    • getSubAreaCorners

      public static List<org.bukkit.Location> getSubAreaCorners(SubArea subArea)
      Returns all 8 corner blocks of a sub-area.
      Parameters:
      subArea - The sub-area
      Returns:
      List of corner locations.
    • getPlayerSubAreas

      public static List<SubArea> getPlayerSubAreas(org.bukkit.entity.Player player)
      Returns all sub-areas a player is a member of.
      Parameters:
      player - The player
      Returns:
      List of sub-areas.
    • getPlayerSubAreas

      public static List<SubArea> getPlayerSubAreas(UUID playerId)
      Returns all sub-areas a player is a member of.
      Parameters:
      playerId - The player UUID
      Returns:
      List of sub-areas.
    • renameSubArea

      public static String renameSubArea(SubArea subArea, String newName)
      Safely renames a sub-area, ensuring uniqueness within the region.
      Parameters:
      subArea - The sub-area to rename
      newName - The desired name
      Returns:
      The actual name assigned (may have counter appended).
    • resizeSubArea

      public static void resizeSubArea(SubArea subArea, org.bukkit.block.Block point1, org.bukkit.block.Block point2)
      Resizes a sub-area to new corner points.
      Parameters:
      subArea - The sub-area
      point1 - The new first corner
      point2 - The new second corner
    • expandSubArea

      public static void expandSubArea(SubArea subArea, int amount)
      Expands a sub-area by the given amount in all directions.
      Parameters:
      subArea - The sub-area
      amount - Blocks to expand (must be positive)
    • deleteSubArea

      public static void deleteSubArea(long id)
      Permanently deletes the specified sub-area and its related members.
      Parameters:
      id - The sub-area ID
    • deleteSubAreasOfRegion

      public static int deleteSubAreasOfRegion(Region region)
      Deletes all sub-areas belonging to a region.
      Parameters:
      region - The region
      Returns:
      The number of sub-areas deleted.
    • deleteSubAreasOfRegion

      public static int deleteSubAreasOfRegion(long regionId)
      Deletes all sub-areas belonging to a region.
      Parameters:
      regionId - The region ID
      Returns:
      The number of sub-areas deleted.
    • isNameUsed

      public static boolean isNameUsed(long regionId, String name)
      Checks whether any sub-area in the region already carries the supplied name, ignoring case.
      Parameters:
      regionId - The region ID
      name - The name to check
      Returns:
      true if the name is used.
    • cleanupInvalidSubAreas

      public static int cleanupInvalidSubAreas()
      Removes all sub-areas with invalid references: - Worlds that no longer exist - Regions that no longer exist - Members whose player UUID no longer maps to a known player
      Returns:
      Number of corrupted sub-areas removed + member fixes.