Class RateManager
java.lang.Object
tfagaming.projects.minecraft.homestead.managers.RateManager
A utility class that manages
RegionRate.-
Method Summary
Modifier and TypeMethodDescriptionstatic intRemoves all ratings with invalid references:
- Players whose UUID no longer maps to a known player
- Regions that no longer existstatic voiddeleteAll(long regionId) Delete all ratings sent to this region.static voidDelete all ratings sent to this region.static intDeletes every rating in the cache.static intdeleteAllRatingsByPlayer(UUID playerId) Deletes all ratings submitted by a specific player.static intdeleteAllRatingsByPlayer(org.bukkit.OfflinePlayer player) Deletes all ratings submitted by a specific player.static booleandeletePlayerRating(org.bukkit.OfflinePlayer player, long regionId) Deletes a specific player's rating for a region.static booleandeletePlayerRating(org.bukkit.OfflinePlayer player, Region region) Deletes a specific player's rating for a region.static doublegetAverageRating(long regionId) Get the average rating of all scores submitted by players.static doublegetAverageRating(Region region) Get the average rating of all scores submitted by players.static intgetAverageRatingRounded(long regionId) Returns the average rating rounded to the nearest integer (useful for star displays).static intgetAverageRatingRounded(Region region) Returns the average rating rounded to the nearest integer (useful for star displays).getLowestRatedRegions(int limit) Returns the lowest-rated regions, sorted by average rating ascending.static intgetModeRating(long regionId) Returns the mode (most common rating) for a region.static intgetModeRating(Region region) Returns the mode (most common rating) for a region.static doublegetPlayerAverageRating(UUID playerId) Returns the average rating a specific player gives across all regions.static doublegetPlayerAverageRating(org.bukkit.OfflinePlayer player) Returns the average rating a specific player gives across all regions.static RegionRategetPlayerRate(org.bukkit.OfflinePlayer player, long regionId) Retrieves a player's specific rating for a region.static RegionRategetPlayerRate(org.bukkit.OfflinePlayer player, Region region) Retrieves a player's specific rating for a region.static RegionRategetRate(long id) Retrieves a specific rating by its unique ID.static intReturns the number of ratings in the server.static intgetRateCount(long regionId) Returns the number of ratings for a region.static intgetRateCount(Region region) Returns the number of ratings for a region.static List<RegionRate> getRatesOfRegion(long regionId) Returns all ratings for a specific region.static List<RegionRate> getRatesOfRegion(Region region) Returns all ratings for a specific region.getRatingDistribution(long regionId) Returns a distribution map of ratings (score -> count) for a region.getRatingDistribution(Region region) Returns a distribution map of ratings (score -> count) for a region.static doublegetRatingPercentage(long regionId, int score) Returns the percentage of ratings that match a specific score.static doublegetRatingPercentage(Region region, int score) Returns the percentage of ratings that match a specific score.getRegionsRatedByPlayer(UUID playerId) Returns all region IDs that a player has rated.getRegionsRatedByPlayer(org.bukkit.OfflinePlayer player) Returns all region IDs that a player has rated.getTopRatedRegions(int limit) Returns the top-rated regions, sorted by average rating descending.static intgetTotalScore(long regionId) Returns the sum of all rating scores for a region.static intgetTotalScore(Region region) Returns the sum of all rating scores for a region.Returns all regions that have not received any ratings.static booleanhasRatedRegion(UUID playerId, long regionId) Checks if a player has rated a region using UUID only.static booleanhasRatedRegion(org.bukkit.OfflinePlayer player, long regionId) Checks if a player has rated a region.static booleanhasRatedRegion(org.bukkit.OfflinePlayer player, Region region) Checks if a player has rated a region.static voidrateRegion(long regionId, org.bukkit.OfflinePlayer player, int score) Add a rate score from a player to a region.static voidrateRegion(Region region, org.bukkit.OfflinePlayer player, int score) Add a rate score from a player to a region.static booleanupdateRating(org.bukkit.OfflinePlayer player, long regionId, int score) Updates an existing rating or creates a new one.static booleanupdateRating(org.bukkit.OfflinePlayer player, Region region, int score) Updates an existing rating or creates a new one.
-
Method Details
-
getRate
Retrieves a specific rating by its unique ID.- Parameters:
id- The rating ID- Returns:
- The
RegionRate, ornullif not found.
-
getRatesOfRegion
Returns all ratings for a specific region.- Parameters:
region- The region- Returns:
- List of ratings.
-
getRatesOfRegion
Returns all ratings for a specific region.- Parameters:
regionId- The region ID- Returns:
- List of ratings.
-
getRateCount
public static int getRateCount()Returns the number of ratings in the server.- Returns:
- Rating count.
-
getRateCount
Returns the number of ratings for a region.- Parameters:
region- The region- Returns:
- Rating count.
-
getRateCount
public static int getRateCount(long regionId) Returns the number of ratings for a region.- Parameters:
regionId- The region ID- Returns:
- Rating count.
-
getTotalScore
Returns the sum of all rating scores for a region.- Parameters:
region- The region- Returns:
- Total score.
-
getTotalScore
public static int getTotalScore(long regionId) Returns the sum of all rating scores for a region.- Parameters:
regionId- The region ID- Returns:
- Total score.
-
rateRegion
Add a rate score from a player to a region.- Parameters:
region- The regionplayer- The playerscore- The score; ranging from 0 to 5
-
rateRegion
public static void rateRegion(long regionId, org.bukkit.OfflinePlayer player, int score) Add a rate score from a player to a region.- Parameters:
regionId- The region IDplayer- The playerscore- The score; ranging from 0 to 5
-
updateRating
Updates an existing rating or creates a new one.- Parameters:
player- The playerregion- The regionscore- The new score- Returns:
trueif an existing rating was updated,falseif a new one was created.
-
updateRating
public static boolean updateRating(org.bukkit.OfflinePlayer player, long regionId, int score) Updates an existing rating or creates a new one.- Parameters:
player- The playerregionId- The region IDscore- The new score- Returns:
trueif an existing rating was updated,falseif a new one was created.
-
getAverageRating
Get the average rating of all scores submitted by players.- Parameters:
region- The region- Returns:
- Average rating, or
0.0if no ratings.
-
getAverageRating
public static double getAverageRating(long regionId) Get the average rating of all scores submitted by players.- Parameters:
regionId- The region ID- Returns:
- Average rating, or
0.0if no ratings.
-
getAverageRatingRounded
Returns the average rating rounded to the nearest integer (useful for star displays).- Parameters:
region- The region- Returns:
- Rounded rating, or
0if no ratings.
-
getAverageRatingRounded
public static int getAverageRatingRounded(long regionId) Returns the average rating rounded to the nearest integer (useful for star displays).- Parameters:
regionId- The region ID- Returns:
- Rounded rating, or
0if no ratings.
-
getModeRating
Returns the mode (most common rating) for a region.- Parameters:
region- The region- Returns:
- Mode score, or
0if no ratings.
-
getModeRating
public static int getModeRating(long regionId) Returns the mode (most common rating) for a region.- Parameters:
regionId- The region ID- Returns:
- Mode score, or
0if no ratings.
-
getRatingDistribution
Returns a distribution map of ratings (score -> count) for a region.- Parameters:
region- The region- Returns:
- Map of score to count.
-
getRatingDistribution
Returns a distribution map of ratings (score -> count) for a region.- Parameters:
regionId- The region ID- Returns:
- Map of score to count.
-
getRatingPercentage
Returns the percentage of ratings that match a specific score.- Parameters:
region- The regionscore- The score to check- Returns:
- Percentage from 0.0 to 100.0.
-
getRatingPercentage
public static double getRatingPercentage(long regionId, int score) Returns the percentage of ratings that match a specific score.- Parameters:
regionId- The region IDscore- The score to check- Returns:
- Percentage from 0.0 to 100.0.
-
getTopRatedRegions
Returns the top-rated regions, sorted by average rating descending.- Parameters:
limit- Maximum number of results- Returns:
- List of top-rated regions.
-
getLowestRatedRegions
Returns the lowest-rated regions, sorted by average rating ascending.- Parameters:
limit- Maximum number of results- Returns:
- List of lowest-rated regions.
-
getUnratedRegions
Returns all regions that have not received any ratings.- Returns:
- List of unrated regions.
-
getPlayerAverageRating
public static double getPlayerAverageRating(org.bukkit.OfflinePlayer player) Returns the average rating a specific player gives across all regions.- Parameters:
player- The player- Returns:
- Average score given, or
0.0if no ratings.
-
getPlayerAverageRating
Returns the average rating a specific player gives across all regions.- Parameters:
playerId- The player UUID- Returns:
- Average score given, or
0.0if no ratings.
-
getRegionsRatedByPlayer
Returns all region IDs that a player has rated.- Parameters:
player- The player- Returns:
- List of region IDs.
-
getRegionsRatedByPlayer
Returns all region IDs that a player has rated.- Parameters:
playerId- The player UUID- Returns:
- List of region IDs.
-
hasRatedRegion
Checks if a player has rated a region.- Parameters:
player- The playerregion- The region- Returns:
trueif the player has rated the region.
-
hasRatedRegion
public static boolean hasRatedRegion(org.bukkit.OfflinePlayer player, long regionId) Checks if a player has rated a region.- Parameters:
player- The playerregionId- The region ID- Returns:
trueif the player has rated the region.
-
hasRatedRegion
Checks if a player has rated a region using UUID only.- Parameters:
playerId- The player UUIDregionId- The region ID- Returns:
trueif the player has rated the region.
-
getPlayerRate
Retrieves a player's specific rating for a region.- Parameters:
player- The playerregion- The region- Returns:
- The
RegionRate, ornullif not found.
-
getPlayerRate
Retrieves a player's specific rating for a region.- Parameters:
player- The playerregionId- The region ID- Returns:
- The
RegionRate, ornullif not found.
-
deletePlayerRating
Deletes a specific player's rating for a region.- Parameters:
player- The playerregion- The region- Returns:
trueif a rating was found and deleted.
-
deletePlayerRating
public static boolean deletePlayerRating(org.bukkit.OfflinePlayer player, long regionId) Deletes a specific player's rating for a region.- Parameters:
player- The playerregionId- The region ID- Returns:
trueif a rating was found and deleted.
-
deleteAllRatingsByPlayer
public static int deleteAllRatingsByPlayer(org.bukkit.OfflinePlayer player) Deletes all ratings submitted by a specific player.- Parameters:
player- The player- Returns:
- The number of ratings deleted.
-
deleteAllRatingsByPlayer
Deletes all ratings submitted by a specific player.- Parameters:
playerId- The player UUID- Returns:
- The number of ratings deleted.
-
deleteAll
Delete all ratings sent to this region.- Parameters:
region- The region
-
deleteAll
public static void deleteAll(long regionId) Delete all ratings sent to this region.- Parameters:
regionId- The region ID
-
deleteAllRatings
public static int deleteAllRatings()Deletes every rating in the cache. Use with caution.- Returns:
- The number of ratings deleted.
-
cleanupInvalidRatings
public static int cleanupInvalidRatings()Removes all ratings with invalid references:
- Players whose UUID no longer maps to a known player
- Regions that no longer exist- Returns:
- Number of corrupted ratings removed.
-