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

public final class RateManager extends Object
A utility class that manages RegionRate.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    Removes all ratings with invalid references:
    - Players whose UUID no longer maps to a known player
    - Regions that no longer exist
    static void
    deleteAll(long regionId)
    Delete all ratings sent to this region.
    static void
    deleteAll(Region region)
    Delete all ratings sent to this region.
    static int
    Deletes every rating in the cache.
    static int
    Deletes all ratings submitted by a specific player.
    static int
    deleteAllRatingsByPlayer(org.bukkit.OfflinePlayer player)
    Deletes all ratings submitted by a specific player.
    static boolean
    deletePlayerRating(org.bukkit.OfflinePlayer player, long regionId)
    Deletes a specific player's rating for a region.
    static boolean
    deletePlayerRating(org.bukkit.OfflinePlayer player, Region region)
    Deletes a specific player's rating for a region.
    static double
    getAverageRating(long regionId)
    Get the average rating of all scores submitted by players.
    static double
    Get the average rating of all scores submitted by players.
    static int
    getAverageRatingRounded(long regionId)
    Returns the average rating rounded to the nearest integer (useful for star displays).
    static int
    Returns the average rating rounded to the nearest integer (useful for star displays).
    static List<Region>
    Returns the lowest-rated regions, sorted by average rating ascending.
    static int
    getModeRating(long regionId)
    Returns the mode (most common rating) for a region.
    static int
    Returns the mode (most common rating) for a region.
    static double
    Returns the average rating a specific player gives across all regions.
    static double
    getPlayerAverageRating(org.bukkit.OfflinePlayer player)
    Returns the average rating a specific player gives across all regions.
    static RegionRate
    getPlayerRate(org.bukkit.OfflinePlayer player, long regionId)
    Retrieves a player's specific rating for a region.
    static RegionRate
    getPlayerRate(org.bukkit.OfflinePlayer player, Region region)
    Retrieves a player's specific rating for a region.
    static RegionRate
    getRate(long id)
    Retrieves a specific rating by its unique ID.
    static int
    Returns the number of ratings in the server.
    static int
    getRateCount(long regionId)
    Returns the number of ratings for a region.
    static int
    Returns the number of ratings for a region.
    getRatesOfRegion(long regionId)
    Returns all ratings for a specific region.
    Returns all ratings for a specific region.
    getRatingDistribution(long regionId)
    Returns a distribution map of ratings (score -> count) for a region.
    Returns a distribution map of ratings (score -> count) for a region.
    static double
    getRatingPercentage(long regionId, int score)
    Returns the percentage of ratings that match a specific score.
    static double
    getRatingPercentage(Region region, int score)
    Returns the percentage of ratings that match a specific score.
    static List<Long>
    Returns all region IDs that a player has rated.
    static List<Long>
    getRegionsRatedByPlayer(org.bukkit.OfflinePlayer player)
    Returns all region IDs that a player has rated.
    static List<Region>
    getTopRatedRegions(int limit)
    Returns the top-rated regions, sorted by average rating descending.
    static int
    getTotalScore(long regionId)
    Returns the sum of all rating scores for a region.
    static int
    Returns the sum of all rating scores for a region.
    static List<Region>
    Returns all regions that have not received any ratings.
    static boolean
    hasRatedRegion(UUID playerId, long regionId)
    Checks if a player has rated a region using UUID only.
    static boolean
    hasRatedRegion(org.bukkit.OfflinePlayer player, long regionId)
    Checks if a player has rated a region.
    static boolean
    hasRatedRegion(org.bukkit.OfflinePlayer player, Region region)
    Checks if a player has rated a region.
    static void
    rateRegion(long regionId, org.bukkit.OfflinePlayer player, int score)
    Add a rate score from a player to a region.
    static void
    rateRegion(Region region, org.bukkit.OfflinePlayer player, int score)
    Add a rate score from a player to a region.
    static boolean
    updateRating(org.bukkit.OfflinePlayer player, long regionId, int score)
    Updates an existing rating or creates a new one.
    static boolean
    updateRating(org.bukkit.OfflinePlayer player, Region region, int score)
    Updates an existing rating or creates a new one.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getRate

      public static RegionRate getRate(long id)
      Retrieves a specific rating by its unique ID.
      Parameters:
      id - The rating ID
      Returns:
      The RegionRate, or null if not found.
    • getRatesOfRegion

      public static List<RegionRate> getRatesOfRegion(Region region)
      Returns all ratings for a specific region.
      Parameters:
      region - The region
      Returns:
      List of ratings.
    • getRatesOfRegion

      public static List<RegionRate> getRatesOfRegion(long regionId)
      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

      public static int getRateCount(Region region)
      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

      public static int getTotalScore(Region region)
      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

      public static void rateRegion(Region region, org.bukkit.OfflinePlayer player, int score)
      Add a rate score from a player to a region.
      Parameters:
      region - The region
      player - The player
      score - 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 ID
      player - The player
      score - The score; ranging from 0 to 5
    • updateRating

      public static boolean updateRating(org.bukkit.OfflinePlayer player, Region region, int score)
      Updates an existing rating or creates a new one.
      Parameters:
      player - The player
      region - The region
      score - The new score
      Returns:
      true if an existing rating was updated, false if 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 player
      regionId - The region ID
      score - The new score
      Returns:
      true if an existing rating was updated, false if a new one was created.
    • getAverageRating

      public static double getAverageRating(Region region)
      Get the average rating of all scores submitted by players.
      Parameters:
      region - The region
      Returns:
      Average rating, or 0.0 if 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.0 if no ratings.
    • getAverageRatingRounded

      public static int getAverageRatingRounded(Region region)
      Returns the average rating rounded to the nearest integer (useful for star displays).
      Parameters:
      region - The region
      Returns:
      Rounded rating, or 0 if 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 0 if no ratings.
    • getModeRating

      public static int getModeRating(Region region)
      Returns the mode (most common rating) for a region.
      Parameters:
      region - The region
      Returns:
      Mode score, or 0 if 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 0 if no ratings.
    • getRatingDistribution

      public static Map<Integer,Integer> getRatingDistribution(Region region)
      Returns a distribution map of ratings (score -> count) for a region.
      Parameters:
      region - The region
      Returns:
      Map of score to count.
    • getRatingDistribution

      public static Map<Integer,Integer> getRatingDistribution(long regionId)
      Returns a distribution map of ratings (score -> count) for a region.
      Parameters:
      regionId - The region ID
      Returns:
      Map of score to count.
    • getRatingPercentage

      public static double getRatingPercentage(Region region, int score)
      Returns the percentage of ratings that match a specific score.
      Parameters:
      region - The region
      score - 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 ID
      score - The score to check
      Returns:
      Percentage from 0.0 to 100.0.
    • getTopRatedRegions

      public static List<Region> getTopRatedRegions(int limit)
      Returns the top-rated regions, sorted by average rating descending.
      Parameters:
      limit - Maximum number of results
      Returns:
      List of top-rated regions.
    • getLowestRatedRegions

      public static List<Region> getLowestRatedRegions(int limit)
      Returns the lowest-rated regions, sorted by average rating ascending.
      Parameters:
      limit - Maximum number of results
      Returns:
      List of lowest-rated regions.
    • getUnratedRegions

      public static List<Region> 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.0 if no ratings.
    • getPlayerAverageRating

      public static double getPlayerAverageRating(UUID playerId)
      Returns the average rating a specific player gives across all regions.
      Parameters:
      playerId - The player UUID
      Returns:
      Average score given, or 0.0 if no ratings.
    • getRegionsRatedByPlayer

      public static List<Long> getRegionsRatedByPlayer(org.bukkit.OfflinePlayer player)
      Returns all region IDs that a player has rated.
      Parameters:
      player - The player
      Returns:
      List of region IDs.
    • getRegionsRatedByPlayer

      public static List<Long> getRegionsRatedByPlayer(UUID playerId)
      Returns all region IDs that a player has rated.
      Parameters:
      playerId - The player UUID
      Returns:
      List of region IDs.
    • hasRatedRegion

      public static boolean hasRatedRegion(org.bukkit.OfflinePlayer player, Region region)
      Checks if a player has rated a region.
      Parameters:
      player - The player
      region - The region
      Returns:
      true if 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 player
      regionId - The region ID
      Returns:
      true if the player has rated the region.
    • hasRatedRegion

      public static boolean hasRatedRegion(UUID playerId, long regionId)
      Checks if a player has rated a region using UUID only.
      Parameters:
      playerId - The player UUID
      regionId - The region ID
      Returns:
      true if the player has rated the region.
    • getPlayerRate

      public static RegionRate getPlayerRate(org.bukkit.OfflinePlayer player, Region region)
      Retrieves a player's specific rating for a region.
      Parameters:
      player - The player
      region - The region
      Returns:
      The RegionRate, or null if not found.
    • getPlayerRate

      public static RegionRate getPlayerRate(org.bukkit.OfflinePlayer player, long regionId)
      Retrieves a player's specific rating for a region.
      Parameters:
      player - The player
      regionId - The region ID
      Returns:
      The RegionRate, or null if not found.
    • deletePlayerRating

      public static boolean deletePlayerRating(org.bukkit.OfflinePlayer player, Region region)
      Deletes a specific player's rating for a region.
      Parameters:
      player - The player
      region - The region
      Returns:
      true if 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 player
      regionId - The region ID
      Returns:
      true if 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

      public static int deleteAllRatingsByPlayer(UUID playerId)
      Deletes all ratings submitted by a specific player.
      Parameters:
      playerId - The player UUID
      Returns:
      The number of ratings deleted.
    • deleteAll

      public static void deleteAll(Region region)
      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.