From 7c6c19ba632e0d53e2b1170bee59862aa3339c2f Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Wed, 30 Nov 2016 16:07:16 +1100 Subject: [PATCH] Fixes #740 --- .../plot/commands/Rate.java | 72 +++++++++++-------- .../intellectualcrafters/plot/config/C.java | 2 + .../plot/util/Permissions.java | 6 +- 3 files changed, 50 insertions(+), 30 deletions(-) diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Rate.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Rate.java index f3582c160..d21845fb7 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Rate.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Rate.java @@ -28,7 +28,7 @@ import java.util.UUID; @CommandDeclaration(command = "rate", permission = "plots.rate", description = "Rate the plot", - usage = "/plot rate [#|next]", + usage = "/plot rate [#|next|purge]", aliases = "rt", category = CommandCategory.INFO, requiredType = RequiredType.NONE) @@ -37,40 +37,54 @@ public class Rate extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { if (args.length == 1) { - if (args[0].equalsIgnoreCase("next")) { - ArrayList plots = new ArrayList<>(PS.get().getBasePlots()); - Collections.sort(plots, new Comparator() { - @Override - public int compare(Plot p1, Plot p2) { - double v1 = 0; - if (!p1.getRatings().isEmpty()) { - for (Entry entry : p1.getRatings().entrySet()) { - v1 -= 11 - entry.getValue().getAverageRating(); + switch (args[0].toLowerCase()) { + case "next": { + ArrayList plots = new ArrayList<>(PS.get().getBasePlots()); + Collections.sort(plots, new Comparator() { + @Override + public int compare(Plot p1, Plot p2) { + double v1 = 0; + if (!p1.getRatings().isEmpty()) { + for (Entry entry : p1.getRatings().entrySet()) { + v1 -= 11 - entry.getValue().getAverageRating(); + } } - } - double v2 = 0; - if (!p2.getRatings().isEmpty()) { - for (Entry entry : p2.getRatings().entrySet()) { - v2 -= 11 - entry.getValue().getAverageRating(); + double v2 = 0; + if (!p2.getRatings().isEmpty()) { + for (Entry entry : p2.getRatings().entrySet()) { + v2 -= 11 - entry.getValue().getAverageRating(); + } } + if (v1 == v2) { + return -0; + } + return v2 > v1 ? 1 : -1; } - if (v1 == v2) { - return -0; + }); + UUID uuid = player.getUUID(); + for (Plot p : plots) { + if ((!Settings.Done.REQUIRED_FOR_RATINGS || p.hasFlag(Flags.DONE)) && p.isBasePlot() && (p.hasRatings() || !p.getRatings() + .containsKey(uuid)) && !p.isAdded(uuid)) { + p.teleportPlayer(player); + MainUtil.sendMessage(player, C.RATE_THIS); + return true; } - return v2 > v1 ? 1 : -1; - } - }); - UUID uuid = player.getUUID(); - for (Plot p : plots) { - if ((!Settings.Done.REQUIRED_FOR_RATINGS || p.hasFlag(Flags.DONE)) && p.isBasePlot() && (p.hasRatings() || !p.getRatings() - .containsKey(uuid)) && !p.isAdded(uuid)) { - p.teleportPlayer(player); - MainUtil.sendMessage(player, C.RATE_THIS); - return true; } + MainUtil.sendMessage(player, C.FOUND_NO_PLOTS); + return false; + } + case "purge": { + final Plot plot = player.getCurrentPlot(); + if (plot == null) { + return !sendMessage(player, C.NOT_IN_PLOT); + } + if (!Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_RATE, true)) { + return false; + } + plot.clearRatings(); + C.RATINGS_PURGED.send(player); + return true; } - MainUtil.sendMessage(player, C.FOUND_NO_PLOTS); - return false; } } final Plot plot = player.getCurrentPlot(); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/config/C.java b/Core/src/main/java/com/intellectualcrafters/plot/config/C.java index 4b57e5026..845f4cdcd 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -71,6 +71,7 @@ public enum C { PERMISSION_ADMIN_INTERACT_OTHER("plots.admin.interact.other", "static.permissions"), PERMISSION_ADMIN_BUILD_HEIGHTLIMIT("plots.admin.build.heightlimit", "static.permissions"), PERMISSION_ADMIN_UPDATE("plots.admin.command.update", "static.permissions"), + PERMISSION_ADMIN_COMMAND_RATE("plots.admin.command.rate", "static.permissions"), PERMISSION_ADMIN_COMMAND_TRUST("plots.admin.command.trust", "static.permissions"), PERMISSION_TRUST_EVERYONE("plots.trust.everyone", "static.permissions"), PERMISSION_AREA_CREATE("plots.area.create", "static.permissions"), @@ -311,6 +312,7 @@ public enum C { /* * Ratings */ + RATINGS_PURGED("$2Purged ratings for this plot", "Ratings"), RATING_NOT_VALID("$2You need to specify a number between 1 and 10", "Ratings"), RATING_ALREADY_EXISTS("$2You have already rated plot $2%s", "Ratings"), RATING_APPLIED("$4You successfully rated plot $2%s", "Ratings"), diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/Permissions.java b/Core/src/main/java/com/intellectualcrafters/plot/util/Permissions.java index 5bd4a15c6..a20cfd474 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/Permissions.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/Permissions.java @@ -13,7 +13,11 @@ import java.util.HashMap; * - Checking the PlotPlayer class directly will not take the above into account
*/ public class Permissions { - + + public static boolean hasPermission(PlotPlayer player, C caption, boolean notify) { + return hasPermission(player, caption.s(), notify); + } + /** * Check if a player has a permission (C class helps keep track of permissions). * @param player