diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PS.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PS.java index 176b03572..52335e032 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PS.java @@ -1351,7 +1351,7 @@ public class PS { log(C.PREFIX.s() + "&6Debug Mode Enabled (Default). Edit the config to turn this off."); } Settings.CONSOLE_COLOR = config.getBoolean("console.color"); - if (!config.getBoolean("chat.fancy") || !IMP.checkVersion(1, 7, 0)) { + if (!config.getBoolean("chat.fancy") || !IMP.checkVersion(1, 8, 0)) { Settings.FANCY_CHAT = false; } Settings.METRICS = config.getBoolean("metrics"); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Rate.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Rate.java index c8a95206e..726ced113 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Rate.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Rate.java @@ -38,6 +38,7 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotInventory; import com.intellectualcrafters.plot.object.PlotItemStack; import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.Rating; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.TaskManager; @@ -58,19 +59,19 @@ public class Rate extends SubCommand { Collections.sort(plots, new Comparator() { @Override public int compare(Plot p1, Plot p2) { - int v1 = 0; - int v2 = 0; + double v1 = 0; + double v2 = 0; if (p1.settings.ratings != null) { - for (Entry entry : p1.settings.ratings.entrySet()) { - v1 -= 11 - entry.getValue(); + for (Entry entry : p1.getRatings().entrySet()) { + v1 -= 11 - entry.getValue().getAverageRating(); } } if (p2.settings.ratings != null) { - for (Entry entry : p2.settings.ratings.entrySet()) { - v2 -= 11 - entry.getValue(); + for (Entry entry : p2.getRatings().entrySet()) { + v2 -= 11 - entry.getValue().getAverageRating(); } } - return v2 - v1; + return v2 > v1 ? 1 : -1; } }); UUID uuid = player.getUUID(); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/list.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/list.java index 9a4d57622..1971132ab 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/list.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/list.java @@ -39,6 +39,7 @@ import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.object.BukkitPlayer; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.Rating; import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Perm; @@ -177,15 +178,17 @@ public class list extends SubCommand { double v1 = 0; double v2 = 0; if (p1.settings.ratings != null && p1.settings.ratings.size() > 0) { - for (Entry entry : p1.settings.ratings.entrySet()) { - v1 += entry.getValue() * entry.getValue(); + for (Entry entry : p1.getRatings().entrySet()) { + double av = entry.getValue().getAverageRating(); + v1 += av * av; } v1 /= p1.settings.ratings.size(); v2 += p2.settings.ratings.size(); } if (p2.settings.ratings != null && p2.settings.ratings.size() > 0) { - for (Entry entry : p2.settings.ratings.entrySet()) { - v2 += entry.getValue() * entry.getValue(); + for (Entry entry : p2.getRatings().entrySet()) { + double av = entry.getValue().getAverageRating(); + v2 += av * av; } v2 /= p2.settings.ratings.size(); v2 += p2.settings.ratings.size(); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Plot.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Plot.java index f9d3836a6..ed263f75c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -22,7 +22,9 @@ package com.intellectualcrafters.plot.object; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.HashSet; +import java.util.Map.Entry; import java.util.UUID; import com.intellectualcrafters.plot.PS; @@ -64,7 +66,9 @@ public class Plot implements Cloneable { */ public ArrayList denied; /** - * External settings class + * External settings class
+ * - Please favor the methods over direct access to this class
+ * - The methods are more likely to be left unchanged from version changes
*/ public PlotSettings settings; /** @@ -297,6 +301,19 @@ public class Plot implements Cloneable { return MainUtil.getPlotHome(this); } + /** + * Get the ratings associated with a plot
+ * - The rating object may contain multiple categories + * @return Map of user who rated to the rating + */ + public HashMap getRatings() { + HashMap map = new HashMap(); + for (Entry entry : settings.ratings.entrySet()) { + map.put(entry.getKey(), new Rating(entry.getValue())); + } + return map; + } + /** * Set the home location * @param loc diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Rating.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Rating.java new file mode 100644 index 000000000..6f04e54fc --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Rating.java @@ -0,0 +1,49 @@ +package com.intellectualcrafters.plot.object; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map.Entry; + +import com.intellectualcrafters.plot.config.Settings; + +public class Rating { + + /** + * This is a map of the rating category to the rating value + */ + private HashMap ratingMap; + + public Rating(int value) { + if (Settings.RATING_CATEGORIES != null && Settings.RATING_CATEGORIES.size() > 1) { + for (int i = 0 ; i < Settings.RATING_CATEGORIES.size(); i++) { + ratingMap.put(Settings.RATING_CATEGORIES.get(i), (value % 10) - 1); + value /= 10; + } + } + else { + ratingMap.put(null, value); + } + } + + public List getCategories() { + if (ratingMap.size() == 1) { + return new ArrayList<>(); + } + return new ArrayList<>(ratingMap.keySet()); + } + + public double getAverageRating() { + double total = 0; + for (Entry entry : ratingMap.entrySet()) { + total += entry.getValue(); + } + return total / (double) ratingMap.size(); + } + + public Integer getRating(String category) { + return ratingMap.get(category); + } + + +}