mirror of
				https://github.com/IntellectualSites/PlotSquared.git
				synced 2025-10-31 01:23:44 +01:00 
			
		
		
		
	Fixes #740
This commit is contained in:
		| @@ -28,7 +28,7 @@ import java.util.UUID; | |||||||
| @CommandDeclaration(command = "rate", | @CommandDeclaration(command = "rate", | ||||||
|         permission = "plots.rate", |         permission = "plots.rate", | ||||||
|         description = "Rate the plot", |         description = "Rate the plot", | ||||||
|         usage = "/plot rate [#|next]", |         usage = "/plot rate [#|next|purge]", | ||||||
|         aliases = "rt", |         aliases = "rt", | ||||||
|         category = CommandCategory.INFO, |         category = CommandCategory.INFO, | ||||||
|         requiredType = RequiredType.NONE) |         requiredType = RequiredType.NONE) | ||||||
| @@ -37,40 +37,54 @@ public class Rate extends SubCommand { | |||||||
|     @Override |     @Override | ||||||
|     public boolean onCommand(final PlotPlayer player, String[] args) { |     public boolean onCommand(final PlotPlayer player, String[] args) { | ||||||
|         if (args.length == 1) { |         if (args.length == 1) { | ||||||
|             if (args[0].equalsIgnoreCase("next")) { |             switch (args[0].toLowerCase()) { | ||||||
|                 ArrayList<Plot> plots = new ArrayList<>(PS.get().getBasePlots()); |                 case "next": { | ||||||
|                 Collections.sort(plots, new Comparator<Plot>() { |                     ArrayList<Plot> plots = new ArrayList<>(PS.get().getBasePlots()); | ||||||
|                     @Override |                     Collections.sort(plots, new Comparator<Plot>() { | ||||||
|                     public int compare(Plot p1, Plot p2) { |                         @Override | ||||||
|                         double v1 = 0; |                         public int compare(Plot p1, Plot p2) { | ||||||
|                         if (!p1.getRatings().isEmpty()) { |                             double v1 = 0; | ||||||
|                             for (Entry<UUID, Rating> entry : p1.getRatings().entrySet()) { |                             if (!p1.getRatings().isEmpty()) { | ||||||
|                                 v1 -= 11 - entry.getValue().getAverageRating(); |                                 for (Entry<UUID, Rating> entry : p1.getRatings().entrySet()) { | ||||||
|  |                                     v1 -= 11 - entry.getValue().getAverageRating(); | ||||||
|  |                                 } | ||||||
|                             } |                             } | ||||||
|                         } |                             double v2 = 0; | ||||||
|                         double v2 = 0; |                             if (!p2.getRatings().isEmpty()) { | ||||||
|                         if (!p2.getRatings().isEmpty()) { |                                 for (Entry<UUID, Rating> entry : p2.getRatings().entrySet()) { | ||||||
|                             for (Entry<UUID, Rating> entry : p2.getRatings().entrySet()) { |                                     v2 -= 11 - entry.getValue().getAverageRating(); | ||||||
|                                 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(); |         final Plot plot = player.getCurrentPlot(); | ||||||
|   | |||||||
| @@ -71,6 +71,7 @@ public enum C { | |||||||
|     PERMISSION_ADMIN_INTERACT_OTHER("plots.admin.interact.other", "static.permissions"), |     PERMISSION_ADMIN_INTERACT_OTHER("plots.admin.interact.other", "static.permissions"), | ||||||
|     PERMISSION_ADMIN_BUILD_HEIGHTLIMIT("plots.admin.build.heightlimit", "static.permissions"), |     PERMISSION_ADMIN_BUILD_HEIGHTLIMIT("plots.admin.build.heightlimit", "static.permissions"), | ||||||
|     PERMISSION_ADMIN_UPDATE("plots.admin.command.update", "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_ADMIN_COMMAND_TRUST("plots.admin.command.trust", "static.permissions"), | ||||||
|     PERMISSION_TRUST_EVERYONE("plots.trust.everyone", "static.permissions"), |     PERMISSION_TRUST_EVERYONE("plots.trust.everyone", "static.permissions"), | ||||||
|     PERMISSION_AREA_CREATE("plots.area.create", "static.permissions"), |     PERMISSION_AREA_CREATE("plots.area.create", "static.permissions"), | ||||||
| @@ -311,6 +312,7 @@ public enum C { | |||||||
|     /* |     /* | ||||||
|      * Ratings |      * Ratings | ||||||
|      */ |      */ | ||||||
|  |     RATINGS_PURGED("$2Purged ratings for this plot", "Ratings"), | ||||||
|     RATING_NOT_VALID("$2You need to specify a number between 1 and 10", "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_ALREADY_EXISTS("$2You have already rated plot $2%s", "Ratings"), | ||||||
|     RATING_APPLIED("$4You successfully rated plot $2%s", "Ratings"), |     RATING_APPLIED("$4You successfully rated plot $2%s", "Ratings"), | ||||||
|   | |||||||
| @@ -14,6 +14,10 @@ import java.util.HashMap; | |||||||
|  */ |  */ | ||||||
| public class Permissions { | 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). |      * Check if a player has a permission (C class helps keep track of permissions). | ||||||
|      * @param player |      * @param player | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Jesse Boyd
					Jesse Boyd