Class RegionManager
java.lang.Object
me.tayebyassine.homestead.managers.RegionManager
-
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) 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> Returns 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) Sends a private chat message to all online members and the owner of a region.Produces a list ordered by the requested metric.Supplies all regions sorted alphabetically by name.
-
Method Details
-
createRegion
-
getRegionCount
public static int getRegionCount()Returns the total number of regions in the server.- Returns:
- region count
-
getAll
-
findRegion
Retrieves the region with the exact ID, or null if none exists.- Parameters:
id- the region ID- Returns:
- the region, or
null
-
findRegion
-
getRegionNames
-
getRandomRegion
Returns a random region from the cache.- Returns:
- a random region, or
nullif none exist
-
getAllOwners
Returns every unique owner across all regions.- Returns:
- list of owner players
-
searchRegions
-
sortRegionsAlpha
-
getRegionsSortedByName
Alias forsortRegionsAlpha()with a more descriptive name.- Returns:
- regions sorted alphabetically
-
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
-
deleteRegion
public static void deleteRegion(long id) Permanently deletes the specified region and all related data. If configured, all linked chunks are regenerated via FastAsyncWorldEdit.- Parameters:
id- the region ID
-
mergeRegions
-
renameRegion
-
sendPrivateChat
Sends a private chat message to all online members and the owner of a region. Optionally logs the message if configured.- Parameters:
region- the region to chat inauthor- the player sending the messagemessage- the message content
-
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
-
getRegionsOwnedByPlayer
-
getRegionsOwnedByPlayer
-
getRegionsHasPlayerAsMember
-
getRegionsHasPlayerAsMember
-
getPublicRegions
-
isPlayerInsideRegion
Tests whether the player's current chunk is claimed by the supplied region.- Parameters:
player- the playerregion- the region- Returns:
trueif the player is inside the region
-
getRegionsInWorld
-
getRegionsInWorld
-
getRegionsNearLocation
-
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
-
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
-
getRegionsWithWelcomeSigns
-
getPlayersWithRegionsHasWelcomeSigns
Supplies owners of regions that possess a welcome sign.- Returns:
- list of players who own regions with welcome signs
-
getRegionsWithSubAreas
-
getRegionsWithMembers
-
getRegionsWithBans
-
getRegionsWithInvites
-
getInactiveRegions
-
getRegionsNeedingUpkeep
-
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
-
getRank
Computes the 1-based rank of a region within the given sorting; 0 if not found.- Parameters:
type- the sorting methodid- the region ID- Returns:
- 1-based rank, or
0if 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.- Parameters:
name- the name to check- Returns:
trueif the name is used
-
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
-