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

public final class RegionManager extends Object
Handles creating, deleting, and updating regions.
This is a utility class that helps manage regions more easily. Updating and setting data to regions is generally done to the Region object.
  • Method Details

    • createRegion

      public static Region createRegion(String name, org.bukkit.OfflinePlayer player)
      Creates a region, optionally ensuring the name is unique by appending a counter.
      Parameters:
      name - The region name
      player - The owner of the region
      Returns:
      The created region.
    • getRegionCount

      public static int getRegionCount()
      Returns the total number of regions in the server.
      Returns:
      Region count.
    • getAll

      public static List<Region> getAll()
      Returns a list of every loaded region, directly from dynamic cache.
    • findRegion

      public static Region findRegion(long id)
      Retrieves the region with the exact ID, or null if none exists.
      Parameters:
      id - The region ID
      Returns:
      The Region, or null.
    • findRegion

      public static Region findRegion(String name)
      Retrieves the region with the exact name (case-insensitive), or null if none exists.
      Parameters:
      name - The region name
      Returns:
      The Region, or null.
    • getRegionNames

      public static List<String> getRegionNames()
      Returns all region names for tab-completion purposes.
      Returns:
      List of region names.
    • searchRegions

      public static List<Region> searchRegions(String query)
      Searches regions by name containing the given text (case-insensitive).
      Parameters:
      query - The search query
      Returns:
      List of matching regions.
    • getRandomRegion

      public static Region getRandomRegion()
      Returns a random region from the cache.
      Returns:
      A random region, or null if none exist.
    • deleteRegion

      public static void deleteRegion(long id, org.bukkit.OfflinePlayer... player)
      Permanently deletes the specified region and all related data. If configured, all linked chunks are regenerated via FastAsyncWorldEdit.
      Parameters:
      id - The region ID
      player - Executor (optional)
    • mergeRegions

      public static void mergeRegions(Region from, Region to)
      Merges all data from one region into another and deletes the source region. Transfers bank balance, chunks, sub-areas, and members.
      Parameters:
      from - The region to merge from (will be deleted)
      to - The region to merge into
    • renameRegion

      public static String renameRegion(Region region, String newName)
      Safely renames a region, ensuring the new name is unique.
      Parameters:
      region - The region to rename
      newName - The desired new name
      Returns:
      The actual name assigned (may have counter appended).
    • sendPrivateChat

      public static void sendPrivateChat(Region region, org.bukkit.entity.Player author, String message)
    • isRegionEmpty

      public static boolean isRegionEmpty(Region region)
      Checks if a region has no chunks and no members (essentially empty).
      Parameters:
      region - The region
      Returns:
      true if the region is empty.
    • getRegionAge

      public static long getRegionAge(Region region)
      Returns how many milliseconds ago the region was created.
      Parameters:
      region - The region
      Returns:
      Age in milliseconds.
    • getAllOwners

      public static List<org.bukkit.OfflinePlayer> getAllOwners()
      Collects every unique owner across all regions.
    • sortRegionsAlpha

      public static List<Region> sortRegionsAlpha()
      Supplies all regions sorted alphabetically by name.
    • getRegionsSortedByName

      public static List<Region> getRegionsSortedByName()
      Alias for sortRegionsAlpha() with a more descriptive name.
      Returns:
      Regions sorted alphabetically.
    • getRegionsWithWelcomeSigns

      public static List<Region> getRegionsWithWelcomeSigns()
      Supplies only regions that have a welcome sign configured.
    • getPlayersWithRegionsHasWelcomeSigns

      public static List<org.bukkit.OfflinePlayer> getPlayersWithRegionsHasWelcomeSigns()
      Supplies owners of regions that possess a welcome sign.
    • getRegionsOwnedByPlayer

      public static List<Region> getRegionsOwnedByPlayer(org.bukkit.OfflinePlayer player)
      Supplies every region whose owner matches the given player.
      Parameters:
      player - The player
      Returns:
      List of owned regions.
    • getRegionsOwnedByPlayer

      public static List<Region> getRegionsOwnedByPlayer(UUID ownerId)
      Supplies every region whose owner matches the given UUID.
      Parameters:
      ownerId - The owner UUID
      Returns:
      List of owned regions.
    • getRegionsHasPlayerAsMember

      public static List<Region> getRegionsHasPlayerAsMember(org.bukkit.OfflinePlayer player)
      Supplies every region that lists the given player as a member.
      Parameters:
      player - The player
      Returns:
      List of regions.
    • getRegionsHasPlayerAsMember

      public static List<Region> getRegionsHasPlayerAsMember(UUID playerId)
      Supplies every region that lists the given player as a member.
      Parameters:
      playerId - The player UUID
      Returns:
      List of regions.
    • getPublicRegions

      public static List<Region> getPublicRegions()
      Supplies regions flagged as public (passthrough + teleport-spawn).
    • getRegionsInWorld

      public static List<Region> getRegionsInWorld(org.bukkit.World world)
      Returns all regions in a specific world.
      Parameters:
      world - The world
      Returns:
      List of regions with chunks in that world.
    • getRegionsInWorld

      public static List<Region> getRegionsInWorld(UUID worldId)
      Returns all regions in a specific world.
      Parameters:
      worldId - The world UUID
      Returns:
      List of regions with chunks in that world.
    • getRegionsNearLocation

      public static List<Region> getRegionsNearLocation(org.bukkit.Location location, int chunkRadius)
      Returns regions within a chunk radius of a location.
      Parameters:
      location - The center location
      chunkRadius - The radius in chunks
      Returns:
      List of nearby regions.
    • getRegionAtLocation

      public static Region getRegionAtLocation(org.bukkit.Location location)
      Returns the region that owns the chunk at the given location.
      Parameters:
      location - The location
      Returns:
      The region, or null if unclaimed.
    • getRegionAtChunk

      public static Region getRegionAtChunk(org.bukkit.Chunk chunk)
      Returns the region that owns the given chunk.
      Parameters:
      chunk - The chunk
      Returns:
      The region, or null if unclaimed.
    • getRegionsByBankRange

      public static List<Region> getRegionsByBankRange(double min, double max)
      Returns regions with bank balance within a range.
      Parameters:
      min - Minimum bank balance (inclusive)
      max - Maximum bank balance (inclusive)
      Returns:
      List of regions.
    • getTotalServerBank

      public static double getTotalServerBank()
      Returns the sum of all region bank balances.
      Returns:
      Total server wealth in regions.
    • getAverageBank

      public static double getAverageBank()
      Returns the average bank balance across all regions.
      Returns:
      Average balance, or 0.0 if no regions.
    • getRichestRegion

      public static Region getRichestRegion()
      Returns the richest region.
      Returns:
      The region with the highest bank balance, or null.
    • getPoorestRegion

      public static Region getPoorestRegion()
      Returns the poorest region.
      Returns:
      The region with the lowest bank balance, or null.
    • getRegionsWithSubAreas

      public static List<Region> getRegionsWithSubAreas()
      Returns regions that have at least one sub-area.
      Returns:
      List of regions with sub-areas.
    • getRegionsWithMembers

      public static List<Region> getRegionsWithMembers()
      Returns regions that have at least one member.
      Returns:
      List of regions with members.
    • getRegionsWithBans

      public static List<Region> getRegionsWithBans()
      Returns regions that have at least one ban.
      Returns:
      List of regions with bans.
    • getRegionsWithInvites

      public static List<Region> getRegionsWithInvites()
      Returns regions that have pending invites.
      Returns:
      List of regions with invites.
    • getInactiveRegions

      public static List<Region> getInactiveRegions(long since)
      Returns regions with no activity (no logs) since a given timestamp.
      Parameters:
      since - The timestamp threshold
      Returns:
      List of inactive regions.
    • getRegionsNeedingUpkeep

      public static List<Region> getRegionsNeedingUpkeep(long bufferMillis)
      Returns regions whose upkeep is due (upkeepAt <= current time + buffer).
      Parameters:
      bufferMillis - Buffer time in milliseconds
      Returns:
      List of regions needing upkeep.
    • canAffordUpkeep

      public static boolean canAffordUpkeep(Region region, double upkeepCost)
      Checks if a region can afford its upkeep based on current bank balance.
      Parameters:
      region - The region
      upkeepCost - The upkeep cost
      Returns:
      true if bank >= upkeep cost.
    • sortRegions

      public static List<Region> sortRegions(RegionManager.RegionSorting type)
      Produces a list ordered by the requested metric. Ordering is descending for numeric criteria, ascending for creation date.
      Parameters:
      type - The sorting method
      Returns:
      Sorted list of regions.
    • getRank

      public static int getRank(RegionManager.RegionSorting type, long id)
      Computes the 1-based rank of a region within the given sorting; 0 if not found.
    • getGlobalRank

      public static int getGlobalRank(long id)
      Averages the region's ranks across all metrics to give a global standing. Missing regions in a category count as last place.
      Parameters:
      id - The region ID
      Returns:
      Average rank across all categories.
    • isNameUsed

      public static boolean isNameUsed(String name)
      Checks whether any region already carries the supplied name, ignoring case.
    • isPlayerInsideRegion

      public static boolean isPlayerInsideRegion(org.bukkit.entity.Player player, Region region)
      Tests whether the player's current chunk is claimed by the supplied region.
    • cleanupInvalidRegions

      public static int cleanupInvalidRegions()
      Removes all regions with invalid references:
      - Owners whose UUID no longer maps to a known player
      - Worlds that no longer exist (for spawn location and welcome sign)

      Also cleans invalid spawn locations and welcome signs.
      Returns:
      Number of corrupted regions removed + fixes applied.