mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-01-03 18:38:32 +01:00
Add plot.getRatings() and fixed /plot list top for 1.7.10
This commit is contained in:
parent
f3639b61e3
commit
7f5eaa83fd
@ -1351,7 +1351,7 @@ public class PS {
|
||||
log(C.PREFIX.s() + "&6Debug Mode Enabled (Default). Edit the config to turn this off.");
|
||||
}
|
||||
Settings.CONSOLE_COLOR = config.getBoolean("console.color");
|
||||
if (!config.getBoolean("chat.fancy") || !IMP.checkVersion(1, 7, 0)) {
|
||||
if (!config.getBoolean("chat.fancy") || !IMP.checkVersion(1, 8, 0)) {
|
||||
Settings.FANCY_CHAT = false;
|
||||
}
|
||||
Settings.METRICS = config.getBoolean("metrics");
|
||||
|
@ -38,6 +38,7 @@ import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotInventory;
|
||||
import com.intellectualcrafters.plot.object.PlotItemStack;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.Rating;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
@ -58,19 +59,19 @@ public class Rate extends SubCommand {
|
||||
Collections.sort(plots, new Comparator<Plot>() {
|
||||
@Override
|
||||
public int compare(Plot p1, Plot p2) {
|
||||
int v1 = 0;
|
||||
int v2 = 0;
|
||||
double v1 = 0;
|
||||
double v2 = 0;
|
||||
if (p1.settings.ratings != null) {
|
||||
for (Entry<UUID, Integer> entry : p1.settings.ratings.entrySet()) {
|
||||
v1 -= 11 - entry.getValue();
|
||||
for (Entry<UUID, Rating> entry : p1.getRatings().entrySet()) {
|
||||
v1 -= 11 - entry.getValue().getAverageRating();
|
||||
}
|
||||
}
|
||||
if (p2.settings.ratings != null) {
|
||||
for (Entry<UUID, Integer> entry : p2.settings.ratings.entrySet()) {
|
||||
v2 -= 11 - entry.getValue();
|
||||
for (Entry<UUID, Rating> entry : p2.getRatings().entrySet()) {
|
||||
v2 -= 11 - entry.getValue().getAverageRating();
|
||||
}
|
||||
}
|
||||
return v2 - v1;
|
||||
return v2 > v1 ? 1 : -1;
|
||||
}
|
||||
});
|
||||
UUID uuid = player.getUUID();
|
||||
|
@ -39,6 +39,7 @@ import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.object.BukkitPlayer;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.Rating;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Perm;
|
||||
@ -177,15 +178,17 @@ public class list extends SubCommand {
|
||||
double v1 = 0;
|
||||
double v2 = 0;
|
||||
if (p1.settings.ratings != null && p1.settings.ratings.size() > 0) {
|
||||
for (Entry<UUID, Integer> entry : p1.settings.ratings.entrySet()) {
|
||||
v1 += entry.getValue() * entry.getValue();
|
||||
for (Entry<UUID, Rating> entry : p1.getRatings().entrySet()) {
|
||||
double av = entry.getValue().getAverageRating();
|
||||
v1 += av * av;
|
||||
}
|
||||
v1 /= p1.settings.ratings.size();
|
||||
v2 += p2.settings.ratings.size();
|
||||
}
|
||||
if (p2.settings.ratings != null && p2.settings.ratings.size() > 0) {
|
||||
for (Entry<UUID, Integer> entry : p2.settings.ratings.entrySet()) {
|
||||
v2 += entry.getValue() * entry.getValue();
|
||||
for (Entry<UUID, Rating> entry : p2.getRatings().entrySet()) {
|
||||
double av = entry.getValue().getAverageRating();
|
||||
v2 += av * av;
|
||||
}
|
||||
v2 /= p2.settings.ratings.size();
|
||||
v2 += p2.settings.ratings.size();
|
||||
|
@ -22,7 +22,9 @@ package com.intellectualcrafters.plot.object;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
@ -64,7 +66,9 @@ public class Plot implements Cloneable {
|
||||
*/
|
||||
public ArrayList<UUID> denied;
|
||||
/**
|
||||
* External settings class
|
||||
* External settings class<br>
|
||||
* - Please favor the methods over direct access to this class<br>
|
||||
* - The methods are more likely to be left unchanged from version changes<br>
|
||||
*/
|
||||
public PlotSettings settings;
|
||||
/**
|
||||
@ -297,6 +301,19 @@ public class Plot implements Cloneable {
|
||||
return MainUtil.getPlotHome(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
HashMap<UUID, Rating> map = new HashMap<UUID, Rating>();
|
||||
for (Entry<UUID, Integer> entry : settings.ratings.entrySet()) {
|
||||
map.put(entry.getKey(), new Rating(entry.getValue()));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the home location
|
||||
* @param loc
|
||||
|
@ -0,0 +1,49 @@
|
||||
package com.intellectualcrafters.plot.object;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
|
||||
public class Rating {
|
||||
|
||||
/**
|
||||
* This is a map of the rating category to the rating value
|
||||
*/
|
||||
private HashMap<String, Integer> ratingMap;
|
||||
|
||||
public Rating(int value) {
|
||||
if (Settings.RATING_CATEGORIES != null && Settings.RATING_CATEGORIES.size() > 1) {
|
||||
for (int i = 0 ; i < Settings.RATING_CATEGORIES.size(); i++) {
|
||||
ratingMap.put(Settings.RATING_CATEGORIES.get(i), (value % 10) - 1);
|
||||
value /= 10;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ratingMap.put(null, value);
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getCategories() {
|
||||
if (ratingMap.size() == 1) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return new ArrayList<>(ratingMap.keySet());
|
||||
}
|
||||
|
||||
public double getAverageRating() {
|
||||
double total = 0;
|
||||
for (Entry<String, Integer> entry : ratingMap.entrySet()) {
|
||||
total += entry.getValue();
|
||||
}
|
||||
return total / (double) ratingMap.size();
|
||||
}
|
||||
|
||||
public Integer getRating(String category) {
|
||||
return ratingMap.get(category);
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user