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

@ -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;