From f833370bd94d0541bdf417c146b7e359a0a69baa Mon Sep 17 00:00:00 2001 From: boy0001 Date: Sat, 18 Jul 2015 15:50:25 +1000 Subject: [PATCH] Fix plot list top --- .../intellectualcrafters/plot/commands/list.java | 16 +++++++++------- .../intellectualcrafters/plot/object/Plot.java | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/intellectualcrafters/plot/commands/list.java b/src/main/java/com/intellectualcrafters/plot/commands/list.java index c5c291dfc..d3c780e5b 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/list.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/list.java @@ -202,24 +202,26 @@ public class list extends SubCommand { public int compare(Plot p1, Plot p2) { double v1 = 0; double v2 = 0; - if (p1.settings.ratings != null && p1.settings.ratings.size() > 0) { + int p1s = p1.settings.ratings != null ? p1.settings.ratings.size() : 0; + int p2s = p2.settings.ratings != null ? p2.settings.ratings.size() : 0; + if (p1.settings.ratings != null && p1s > 0) { for (Entry entry : p1.getRatings().entrySet()) { double av = entry.getValue().getAverageRating(); v1 += av * av; } - v1 /= p1.settings.ratings.size(); - v2 += p2.settings.ratings.size(); + v1 /= p1s; + v1 += p1s; } - if (p2.settings.ratings != null && p2.settings.ratings.size() > 0) { + if (p2.settings.ratings != null && p2s > 0) { for (Entry entry : p2.getRatings().entrySet()) { double av = entry.getValue().getAverageRating(); v2 += av * av; } - v2 /= p2.settings.ratings.size(); - v2 += p2.settings.ratings.size(); + v2 /= p2s; + v2 += p2s; } if (v2 == v1 && v2 != 0) { - return p2.settings.ratings.size() - p1.settings.ratings.size(); + return p2s - p1s; } return (int) Math.signum(v2 - v1); } diff --git a/src/main/java/com/intellectualcrafters/plot/object/Plot.java b/src/main/java/com/intellectualcrafters/plot/object/Plot.java index db0dc62a2..83d32697e 100644 --- a/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -327,7 +327,7 @@ public class Plot implements Cloneable { for (Rating rating : ratings) { sum += rating.getAverageRating(); } - return sum / ratings.size(); + return (sum / ratings.size()); } /**