Class RegionManager
java.lang.Object
tfagaming.projects.minecraft.homestead.managers.RegionManager
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
This is a utility class that helps manage regions more easily. Updating and setting data to regions is generally done to the
Region object.-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancanAffordUpkeep(Region region, double upkeepCost) Checks if a region can afford its upkeep based on current bank balance.static intRemoves 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.static RegioncreateRegion(String name, org.bukkit.OfflinePlayer player) Creates a region, optionally ensuring the name is unique by appending a counter.static voiddeleteRegion(long id, org.bukkit.OfflinePlayer... player) Permanently deletes the specified region and all related data.static RegionfindRegion(long id) Retrieves the region with the exact ID, or null if none exists.static RegionfindRegion(String name) Retrieves the region with the exact name (case-insensitive), or null if none exists.getAll()Returns a list of every loaded region, directly from dynamic cache.static List<org.bukkit.OfflinePlayer> Collects every unique owner across all regions.static doubleReturns the average bank balance across all regions.static intgetGlobalRank(long id) Averages the region's ranks across all metrics to give a global standing.getInactiveRegions(long since) Returns regions with no activity (no logs) since a given timestamp.static List<org.bukkit.OfflinePlayer> Supplies owners of regions that possess a welcome sign.static RegionReturns the poorest region.Supplies regions flagged as public (passthrough + teleport-spawn).static RegionReturns a random region from the cache.static intgetRank(RegionManager.RegionSorting type, long id) Computes the 1-based rank of a region within the given sorting; 0 if not found.static longgetRegionAge(Region region) Returns how many milliseconds ago the region was created.static RegiongetRegionAtChunk(org.bukkit.Chunk chunk) Returns the region that owns the given chunk.static RegiongetRegionAtLocation(org.bukkit.Location location) Returns the region that owns the chunk at the given location.static intReturns the total number of regions in the server.Returns all region names for tab-completion purposes.getRegionsByBankRange(double min, double max) Returns regions with bank balance within a range.getRegionsHasPlayerAsMember(UUID playerId) Supplies every region that lists the given player as a member.getRegionsHasPlayerAsMember(org.bukkit.OfflinePlayer player) Supplies every region that lists the given player as a member.getRegionsInWorld(UUID worldId) Returns all regions in a specific world.getRegionsInWorld(org.bukkit.World world) Returns all regions in a specific world.getRegionsNearLocation(org.bukkit.Location location, int chunkRadius) Returns regions within a chunk radius of a location.getRegionsNeedingUpkeep(long bufferMillis) Returns regions whose upkeep is due (upkeepAt <= current time + buffer).getRegionsOwnedByPlayer(UUID ownerId) Supplies every region whose owner matches the given UUID.getRegionsOwnedByPlayer(org.bukkit.OfflinePlayer player) Supplies every region whose owner matches the given player.Alias forsortRegionsAlpha()with a more descriptive name.Returns regions that have at least one ban.Returns regions that have pending invites.Returns regions that have at least one member.Returns regions that have at least one sub-area.Supplies only regions that have a welcome sign configured.static RegionReturns the richest region.static doubleReturns the sum of all region bank balances.static booleanisNameUsed(String name) Checks whether any region already carries the supplied name, ignoring case.static booleanisPlayerInsideRegion(org.bukkit.entity.Player player, Region region) Tests whether the player's current chunk is claimed by the supplied region.static booleanisRegionEmpty(Region region) Checks if a region has no chunks and no members (essentially empty).static voidmergeRegions(Region from, Region to) Merges all data from one region into another and deletes the source region.static StringrenameRegion(Region region, String newName) Safely renames a region, ensuring the new name is unique.searchRegions(String query) Searches regions by name containing the given text (case-insensitive).static voidsendPrivateChat(Region region, org.bukkit.entity.Player author, String message) Produces a list ordered by the requested metric.Supplies all regions sorted alphabetically by name.
-
Method Details
-
createRegion
Creates a region, optionally ensuring the name is unique by appending a counter.- Parameters:
name- The region nameplayer- 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
Returns a list of every loaded region, directly from dynamic cache. -
findRegion
Retrieves the region with the exact ID, or null if none exists.- Parameters:
id- The region ID- Returns:
- The Region, or
null.
-
findRegion
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
Returns all region names for tab-completion purposes.- Returns:
- List of region names.
-
searchRegions
Searches regions by name containing the given text (case-insensitive).- Parameters:
query- The search query- Returns:
- List of matching regions.
-
getRandomRegion
Returns a random region from the cache.- Returns:
- A random region, or
nullif 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 IDplayer- Executor (optional)
-
mergeRegions
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
Safely renames a region, ensuring the new name is unique.- Parameters:
region- The region to renamenewName- The desired new name- Returns:
- The actual name assigned (may have counter appended).
-
sendPrivateChat
-
isRegionEmpty
Checks if a region has no chunks and no members (essentially empty).- Parameters:
region- The region- Returns:
trueif the region is empty.
-
getRegionAge
Returns how many milliseconds ago the region was created.- Parameters:
region- The region- Returns:
- Age in milliseconds.
-
getAllOwners
Collects every unique owner across all regions. -
sortRegionsAlpha
Supplies all regions sorted alphabetically by name. -
getRegionsSortedByName
Alias forsortRegionsAlpha()with a more descriptive name.- Returns:
- Regions sorted alphabetically.
-
getRegionsWithWelcomeSigns
Supplies only regions that have a welcome sign configured. -
getPlayersWithRegionsHasWelcomeSigns
Supplies owners of regions that possess a welcome sign. -
getRegionsOwnedByPlayer
Supplies every region whose owner matches the given player.- Parameters:
player- The player- Returns:
- List of owned regions.
-
getRegionsOwnedByPlayer
Supplies every region whose owner matches the given UUID.- Parameters:
ownerId- The owner UUID- Returns:
- List of owned regions.
-
getRegionsHasPlayerAsMember
Supplies every region that lists the given player as a member.- Parameters:
player- The player- Returns:
- List of regions.
-
getRegionsHasPlayerAsMember
Supplies every region that lists the given player as a member.- Parameters:
playerId- The player UUID- Returns:
- List of regions.
-
getPublicRegions
Supplies regions flagged as public (passthrough + teleport-spawn). -
getRegionsInWorld
Returns all regions in a specific world.- Parameters:
world- The world- Returns:
- List of regions with chunks in that world.
-
getRegionsInWorld
Returns all regions in a specific world.- Parameters:
worldId- The world UUID- Returns:
- List of regions with chunks in that world.
-
getRegionsNearLocation
Returns regions within a chunk radius of a location.- Parameters:
location- The center locationchunkRadius- The radius in chunks- Returns:
- List of nearby regions.
-
getRegionAtLocation
Returns the region that owns the chunk at the given location.- Parameters:
location- The location- Returns:
- The region, or
nullif unclaimed.
-
getRegionAtChunk
Returns the region that owns the given chunk.- Parameters:
chunk- The chunk- Returns:
- The region, or
nullif unclaimed.
-
getRegionsByBankRange
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.0if no regions.
-
getRichestRegion
Returns the richest region.- Returns:
- The region with the highest bank balance, or
null.
-
getPoorestRegion
Returns the poorest region.- Returns:
- The region with the lowest bank balance, or
null.
-
getRegionsWithSubAreas
Returns regions that have at least one sub-area.- Returns:
- List of regions with sub-areas.
-
getRegionsWithMembers
Returns regions that have at least one member.- Returns:
- List of regions with members.
-
getRegionsWithBans
Returns regions that have at least one ban.- Returns:
- List of regions with bans.
-
getRegionsWithInvites
Returns regions that have pending invites.- Returns:
- List of regions with invites.
-
getInactiveRegions
Returns regions with no activity (no logs) since a given timestamp.- Parameters:
since- The timestamp threshold- Returns:
- List of inactive regions.
-
getRegionsNeedingUpkeep
Returns regions whose upkeep is due (upkeepAt <= current time + buffer).- Parameters:
bufferMillis- Buffer time in milliseconds- Returns:
- List of regions needing upkeep.
-
canAffordUpkeep
Checks if a region can afford its upkeep based on current bank balance.- Parameters:
region- The regionupkeepCost- The upkeep cost- Returns:
trueif bank >= upkeep cost.
-
sortRegions
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
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
Checks whether any region already carries the supplied name, ignoring case. -
isPlayerInsideRegion
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.
-