ratings api
misc-cap
other tweakes
This commit is contained in:
Jesse Boyd
2015-10-27 10:57:34 +11:00
parent 2e79f3d0f8
commit 95feaed870
18 changed files with 504 additions and 163 deletions

View File

@ -1607,7 +1607,7 @@ public class PS {
"no-worldedit", "redstone", "keep");
final List<String> intervalFlags = Arrays.asList("feed", "heal");
final List<String> stringFlags = Arrays.asList("greeting", "farewell");
final List<String> intFlags = Arrays.asList("entity-cap", "mob-cap", "animal-cap", "hostile-cap", "vehicle-cap", "music");
final List<String> intFlags = Arrays.asList("misc-cap", "entity-cap", "mob-cap", "animal-cap", "hostile-cap", "vehicle-cap", "music");
for (final String flag : stringFlags) {
FlagManager.addFlag(new AbstractFlag(flag));
}

View File

@ -80,8 +80,8 @@ public class MainCommand extends CommandManager<PlotPlayer> {
createCommand(new DebugAllowUnsafe());
createCommand(new RegenAllRoads());
createCommand(new Claim());
createCommand(new Auto());
createCommand(new Auto());
createCommand(new Visit());
createCommand(new Home());
createCommand(new TP());
createCommand(new Set());
@ -171,47 +171,6 @@ public class MainCommand extends CommandManager<PlotPlayer> {
}
return commands;
}
//// public static List<String> helpMenu(final PlotPlayer player, final CommandCategory category, int page) {
// List<Command<PlotPlayer>> commands;
// // commands = getCommands(category, player);
// // final int totalPages = ((int) Math.ceil(12 * (commands.size()) /
// // 100));
// final int perPage = 5;
// // final int totalPages = (commands.size() / perPage) + (commands.size() % perPage == 0 ? 0 : 1);
// // if (page > totalPages) {
// // page = totalPages;
// // }
// int max = (page * perPage) + perPage;
// // if (max > commands.size()) {
// // max = commands.size();
// // }
// final List<String> help = new ArrayList<>();
// help.add(C.HELP_HEADER.s());
// // HELP_PAGE_HEADER("&cCategory: &6%category%&c, Page: %current%&c/&6%max%&c, Displaying: &6%dis%&c/&6%total%"),
// // help.add(C.HELP_PAGE_HEADER.s().replace("%category%", category == null ? "All" : category.toString()).replace("%current%", "" + (page + 1)).replace("%max%", "" + (totalPages)).replace("%dis%", "" + perPage).replace("%total%", "" + commands.size()));
// Command cmd;
// // HELP_CATEGORY("&cCategory: &6%category%&c, Page: %current%&c/&6%max%&c, Displaying: &6%dis%&c/&6%total%"),
// // help.add(C.HELP_CATEGORY.s().replace("%category%", category == null ? "All" : category.toString()).replace("%current%", "" + (page + 1)).replace("%max%", "" + (totalPages)).replace("%dis%", "" + perPage).replace("%total%", "" + commands.size()));
// // Command<PlotPlayer> cmd;
// final int start = page * perPage;
// for (int x = start; x < max; x++) {
// // cmd = commands.get(x);
// String s = C.HELP_ITEM.s();
// if (cmd.getAliases().size() > 0) {
// s = s.replace("%alias%", StringMan.join(cmd.getAliases(), "|"));
// }
// else {
// s = s.replace("%alias%", "");
// }
// s = s.replace("%usage%", cmd.getUsage().contains("plot") ? cmd.getUsage() : "/plot " + cmd.getUsage()).replace("%cmd%", cmd.getCommand()).replace("%desc%", cmd.getDescription()).replace("[]", "");
// help.add(s);
// }
// if (help.size() < 2) {
// help.add(C.NO_COMMANDS.s());
// }
// return help;
// }
public static void displayHelp(final PlotPlayer player, String cat, int page, final String label) {
CommandCategory catEnum = null;
@ -322,6 +281,11 @@ public class MainCommand extends CommandManager<PlotPlayer> {
public int getMatch(String[] args, Command<PlotPlayer> cmd) {
int count = 0;
String perm = cmd.getPermission();
HashSet<String> desc = new HashSet<String>();
for (String alias : cmd.getAliases()) {
if (alias.startsWith(args[0])) {
count += 5;
}
}
for (String word : cmd.getDescription().split(" ")) {
desc.add(word);

View File

@ -61,7 +61,7 @@ public class Rate extends SubCommand {
public boolean onCommand(final PlotPlayer player, final String[] args) {
if (args.length == 1) {
if (args[0].equalsIgnoreCase("next")) {
final ArrayList<Plot> plots = new ArrayList<>(PS.get().getPlots());
final ArrayList<Plot> plots = new ArrayList<>(PS.get().getBasePlots());
Collections.sort(plots, new Comparator<Plot>() {
@Override
public int compare(final Plot p1, final Plot p2) {
@ -96,7 +96,7 @@ public class Rate extends SubCommand {
}
}
final Location loc = player.getLocation();
final Plot plot = MainUtil.getPlotAbs(loc);
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(player, C.NOT_IN_PLOT);
}

View File

@ -26,11 +26,9 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.PS.SortType;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
@ -45,7 +43,7 @@ import com.plotsquared.general.commands.CommandDeclaration;
command = "visit",
permission = "plots.visit",
description = "Visit someones plot",
usage = "/plot visit <player|alias|world|id> [#]",
usage = "/plot visit [player|alias|world|id] [#]",
aliases = { "v" },
requiredType = RequiredType.NONE,
category = CommandCategory.TELEPORT)

View File

@ -46,7 +46,13 @@ import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(command = "list", aliases = { "l" }, description = "List plots", permission = "plots.list", category = CommandCategory.INFO)
@CommandDeclaration(
command = "list",
aliases = { "l" },
description = "List plots",
permission = "plots.list",
category = CommandCategory.INFO,
usage = "/plot list <forsale|mine|shared|world|top|all|unowned|unknown|player|world|done> [#]")
public class list extends SubCommand {
private String[] getArgumentList(final PlotPlayer player) {

View File

@ -84,6 +84,18 @@ public interface AbstractDB {
*
* @param plot Plot that should be deleted
*/
void delete(final Plot plot);
void deleteSettings(Plot plot);
void deleteHelpers(Plot plot);
void deleteTrusted(Plot plot);
void deleteDenied(Plot plot);
void deleteComments(Plot plot);
void deleteRatings(Plot plot);
void delete(final PlotCluster cluster);

View File

@ -40,8 +40,8 @@ import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.comment.PlotComment;
/**
* DB Functions
*
* Database Functions
* - These functions do not update the local plot objects and only make changes to the DB
*/
public class DBFunc {
/**
@ -154,6 +154,76 @@ public class DBFunc {
plot.temp = -1;
}
/**
* Delete the ratings for a plot
* @param plot
*/
public static void deleteRatings(final Plot plot) {
if (plot.temp == -1) {
return;
}
dbManager.deleteRatings(plot);
}
/**
* Delete the trusted list for a plot
* @param plot
*/
public static void deleteTrusted(final Plot plot) {
if (plot.temp == -1) {
return;
}
dbManager.deleteHelpers(plot);
}
/**
* Delete the members list for a plot
* @param plot
*/
public static void deleteMembers(final Plot plot) {
if (plot.temp == -1) {
return;
}
dbManager.deleteTrusted(plot);
}
/**
* Delete the denied list for a plot
* @param plot
*/
public static void deleteDenied(final Plot plot) {
if (plot.temp == -1) {
return;
}
dbManager.deleteDenied(plot);
}
/**
* Delete the comments in a plot
* @param plot
*/
public static void deleteComments(final Plot plot) {
if (plot.temp == -1) {
return;
}
dbManager.deleteComments(plot);
}
/**
* Deleting settings will
* 1) Delete any settings (flags and such) associated with the plot
* 2) Prevent any local changes to the plot from saving properly to the db
*
* This shouldn't ever be needed
* @param plot
*/
public static void deleteSettings(final Plot plot) {
if (plot.temp == -1) {
return;
}
dbManager.deleteSettings(plot);
}
public static void delete(final PlotCluster toDelete) {
dbManager.delete(toDelete);
}

View File

@ -1191,14 +1191,8 @@ public class SQLManager implements AbstractDB {
stmt.clearBatch();
stmt.close();
}
/**
* Delete a plot
*
* @param plot
@Override
public void delete(final Plot plot) {
@Override
public void deleteSettings(final Plot plot) {
addPlotTask(plot, new UniqueStatement("delete_plot_settings") {
@Override
@ -1210,6 +1204,13 @@ public class SQLManager implements AbstractDB {
public PreparedStatement get() throws SQLException {
return connection.prepareStatement("DELETE FROM `" + prefix + "plot_settings` WHERE `plot_plot_id` = ?");
}
});
}
@Override
public void deleteHelpers(final Plot plot) {
if (plot.getTrusted().size() == 0) {
return;
}
addPlotTask(plot, new UniqueStatement("delete_plot_helpers") {
@Override
@ -1221,6 +1222,13 @@ public class SQLManager implements AbstractDB {
public PreparedStatement get() throws SQLException {
return connection.prepareStatement("DELETE FROM `" + prefix + "plot_helpers` WHERE `plot_plot_id` = ?");
}
});
}
@Override
public void deleteTrusted(final Plot plot) {
if (plot.getMembers().size() == 0) {
return;
}
addPlotTask(plot, new UniqueStatement("delete_plot_trusted") {
@Override
@ -1232,6 +1240,13 @@ public class SQLManager implements AbstractDB {
public PreparedStatement get() throws SQLException {
return connection.prepareStatement("DELETE FROM `" + prefix + "plot_trusted` WHERE `plot_plot_id` = ?");
}
});
}
@Override
public void deleteDenied(final Plot plot) {
if (plot.getDenied().size() == 0) {
return;
}
addPlotTask(plot, new UniqueStatement("delete_plot_denied") {
@Override
@ -1243,6 +1258,10 @@ public class SQLManager implements AbstractDB {
public PreparedStatement get() throws SQLException {
return connection.prepareStatement("DELETE FROM `" + prefix + "plot_denied` WHERE `plot_plot_id` = ?");
}
});
}
@Override
public void deleteComments(final Plot plot) {
addPlotTask(plot, new UniqueStatement("delete_plot_comments") {
@Override
@ -1255,6 +1274,40 @@ public class SQLManager implements AbstractDB {
public PreparedStatement get() throws SQLException {
return connection.prepareStatement("DELETE FROM `" + prefix + "plot_comments` WHERE `world` = ? AND `hashcode` = ?");
}
});
}
@Override
public void deleteRatings(final Plot plot) {
if (Settings.CACHE_RATINGS && plot.getSettings().getRatings().size() == 0) {
return;
}
addPlotTask(plot, new UniqueStatement("delete_plot_ratings") {
@Override
public void set(final PreparedStatement stmt) throws SQLException {
stmt.setInt(1, getId(plot));
}
@Override
public PreparedStatement get() throws SQLException {
return connection.prepareStatement("DELETE FROM `" + prefix + "plot_rating` WHERE `plot_plot_id` = ?");
}
});
}
/**
* Delete a plot
*
* @param plot
*/
@Override
public void delete(final Plot plot) {
PS.get().removePlot(plot.world, plot.id, false);
deleteSettings(plot);
deleteDenied(plot);
deleteHelpers(plot);
deleteTrusted(plot);
deleteComments(plot);
deleteRatings(plot);
addPlotTask(plot, new UniqueStatement("delete_plot") {
@Override

View File

@ -721,24 +721,55 @@ public class Plot {
* Get the average rating of the plot. This is the value displayed in /plot info
* @return average rating as double
*/
public double getAverageRating() {
public double getAverageRating() {
double sum = 0;
final Collection<Rating> ratings = getBasePlot(false).getRatings().values();
for (final Rating rating : ratings) {
sum += rating.getAverageRating();
}
return (sum / ratings.size());
}
/**
* Set a rating for a user<br>
* - If the user has already rated, the following will return false
* @param uuid
* @param rating
* @return
*/
public boolean addRating(UUID uuid, Rating rating) {
Plot base = getBasePlot(false);
PlotSettings baseSettings = base.getSettings();
if (baseSettings.getRatings().containsKey(uuid)) {
return false;
}
baseSettings.getRatings().put(uuid, rating.getAggregate());
DBFunc.setRating(base, uuid, temp);
return true;
}
/**
* Clear the ratings for this plot
*/
public void clearRatings() {
Plot base = getBasePlot(false);
PlotSettings baseSettings = base.getSettings();
if (baseSettings.ratings != null && baseSettings.ratings.size() > 0) {
DBFunc.deleteRatings(base);
baseSettings.ratings = null;
}
}
/**
* Get the ratings associated with a plot<br>
* - The rating object may contain multiple categories
* @return Map of user who rated to the rating
*/
public HashMap<UUID, Rating> getRatings() {
public HashMap<UUID, Rating> getRatings() {
Plot base = getBasePlot(false);
final HashMap<UUID, Rating> map = new HashMap<UUID, Rating>();
if (base.getSettings().ratings == null) {
return map;
return map;
}
for (final Entry<UUID, Integer> entry : base.getSettings().ratings.entrySet()) {
map.put(entry.getKey(), new Rating(entry.getValue()));
@ -980,6 +1011,13 @@ public class Plot {
* Remove a denied player (use DBFunc as well)
*
* @param uuid
*/
public boolean removeDenied(final UUID uuid) {
if (uuid == DBFunc.everyone) {
boolean result = false;
for (UUID other : getDenied()) {
result = result || PlotHandler.removeDenied(this, other);
}
return result;
}
return PlotHandler.removeDenied(this, uuid);
@ -989,6 +1027,13 @@ public class Plot {
* Remove a helper (use DBFunc as well)
*
* @param uuid
*/
public boolean removeTrusted(final UUID uuid) {
if (uuid == DBFunc.everyone) {
boolean result = false;
for (UUID other : getTrusted()) {
result = result || PlotHandler.removeTrusted(this, other);
}
return result;
}
return PlotHandler.removeTrusted(this, uuid);
@ -998,6 +1043,13 @@ public class Plot {
* Remove a trusted user (use DBFunc as well)
*
* @param uuid
*/
public boolean removeMember(final UUID uuid) {
if (uuid == DBFunc.everyone) {
boolean result = false;
for (UUID other : getMembers()) {
result = result || PlotHandler.removeMember(this, other);
}
return result;
}
return PlotHandler.removeMember(this, uuid);

View File

@ -23,6 +23,7 @@ package com.intellectualcrafters.plot.object;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import com.intellectualcrafters.plot.flag.Flag;
@ -30,35 +31,48 @@ import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.comment.PlotComment;
/**
* plot settings
*
* Generic settings class
* - Does not keep a reference to a parent class
* - Direct changes here will not occur in the db (Use the parent plot object for that)
*/
public class PlotSettings {
/**
* merged plots
* @deprecated Raw access
*/
@Deprecated
public boolean[] merged = new boolean[] { false, false, false, false };
/**
* plot alias
* @deprecated Raw access
*/
@Deprecated
public String alias = "";
/**
* Comments
* @deprecated Raw access
*/
@Deprecated
public List<PlotComment> comments = null;
/**
* The ratings for a plot
* @deprecated Raw access
*/
@Deprecated
public HashMap<UUID, Integer> ratings;
/**
* Flags
* @deprecated Raw access
*/
@Deprecated
public HashMap<String, Flag> flags;
/**
* Home Position
* @deprecated Raw access
*/
@Deprecated
private BlockLoc position;
/**
@ -96,6 +110,10 @@ public class PlotSettings {
this.merged = merged;
}
public Map<UUID, Integer> getRatings() {
return ratings == null ? new HashMap<UUID, Integer>() : ratings;
}
public boolean setMerged(final int direction, final boolean merged) {
if (this.merged[direction] != merged) {
this.merged[direction] = merged;

View File

@ -524,6 +524,7 @@ public class MainUtil {
final boolean result = EventUtil.manager.callUnlink(plot.world, ids);
if (!result) {
return false;
}
plot.clearRatings();
if (createSign) {
plot.removeSign();
@ -1010,6 +1011,8 @@ public class MainUtil {
lesserPlot = greaterPlot;
greaterPlot = tmp;
}
if (!lesserPlot.getMerged(2)) {
lesserPlot.clearRatings();
greaterPlot.clearRatings();
lesserPlot.setMerged(2, true);
greaterPlot.setMerged(0, true);
@ -1032,6 +1035,8 @@ public class MainUtil {
lesserPlot = greaterPlot;
greaterPlot = tmp;
}
if (!lesserPlot.getMerged(1)) {
lesserPlot.clearRatings();
greaterPlot.clearRatings();
lesserPlot.setMerged(1, true);
greaterPlot.setMerged(3, true);
@ -1379,7 +1384,7 @@ public class MainUtil {
return true;
}
public static int[] countEntities(Plot plot) {
public static int[] countEntities(Plot plot) {
int[] count = new int[6];
for (Plot current : getConnectedPlots(plot)) {
int[] result = ChunkManager.manager.countEntities(current);
@ -1387,6 +1392,7 @@ public class MainUtil {
count[1] += result[1];
count[2] += result[2];
count[3] += result[3];
count[4] += result[4];
count[5] += result[5];
}
return count;