This commit is contained in:
Jesse Boyd 2016-11-30 16:07:16 +11:00
parent 2e23ae0811
commit 7c6c19ba63
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
3 changed files with 50 additions and 30 deletions

View File

@ -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<Plot> plots = new ArrayList<>(PS.get().getBasePlots());
Collections.sort(plots, new Comparator<Plot>() {
@Override
public int compare(Plot p1, Plot p2) {
double v1 = 0;
if (!p1.getRatings().isEmpty()) {
for (Entry<UUID, Rating> entry : p1.getRatings().entrySet()) {
v1 -= 11 - entry.getValue().getAverageRating();
switch (args[0].toLowerCase()) {
case "next": {
ArrayList<Plot> plots = new ArrayList<>(PS.get().getBasePlots());
Collections.sort(plots, new Comparator<Plot>() {
@Override
public int compare(Plot p1, Plot p2) {
double v1 = 0;
if (!p1.getRatings().isEmpty()) {
for (Entry<UUID, Rating> entry : p1.getRatings().entrySet()) {
v1 -= 11 - entry.getValue().getAverageRating();
}
}
}
double v2 = 0;
if (!p2.getRatings().isEmpty()) {
for (Entry<UUID, Rating> entry : p2.getRatings().entrySet()) {
v2 -= 11 - entry.getValue().getAverageRating();
double v2 = 0;
if (!p2.getRatings().isEmpty()) {
for (Entry<UUID, Rating> 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();

View File

@ -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"),

View File

@ -13,7 +13,11 @@ import java.util.HashMap;
* - Checking the PlotPlayer class directly will not take the above into account<br>
*/
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