mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 11:55:38 +01:00
Add plot like/dislikes
This commit is contained in:
parent
0f8b7cd588
commit
6323fb0041
@ -0,0 +1,14 @@
|
|||||||
|
package com.github.intellectualsites.plotsquared.plot.commands;
|
||||||
|
|
||||||
|
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||||
|
|
||||||
|
@CommandDeclaration(command = "dislike", permission = "plots.dislike", description = "Dislike the plot",
|
||||||
|
usage = "/plot dislike [next|purge]", category = CommandCategory.INFO, requiredType = RequiredType.PLAYER)
|
||||||
|
public class Dislike extends SubCommand {
|
||||||
|
|
||||||
|
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||||
|
return Like.handleLike(player, args, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -2,6 +2,7 @@ package com.github.intellectualsites.plotsquared.plot.commands;
|
|||||||
|
|
||||||
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
|
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
|
||||||
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||||
import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
|
import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
|
||||||
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
||||||
import com.github.intellectualsites.plotsquared.plot.object.*;
|
import com.github.intellectualsites.plotsquared.plot.object.*;
|
||||||
@ -32,6 +33,7 @@ import java.util.UUID;
|
|||||||
case "seen":
|
case "seen":
|
||||||
case "owner":
|
case "owner":
|
||||||
case "rating":
|
case "rating":
|
||||||
|
case "likes":
|
||||||
plot = MainUtil.getPlotFromString(player, null, false);
|
plot = MainUtil.getPlotFromString(player, null, false);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -130,7 +132,7 @@ import java.util.UUID;
|
|||||||
if (info == null) {
|
if (info == null) {
|
||||||
MainUtil.sendMessage(player,
|
MainUtil.sendMessage(player,
|
||||||
"&6Categories&7: &amembers&7, &aalias&7, &abiome&7, &aseen&7, &adenied&7, &aflags&7, &aid&7, &asize&7, &atrusted&7, "
|
"&6Categories&7: &amembers&7, &aalias&7, &abiome&7, &aseen&7, &adenied&7, &aflags&7, &aid&7, &asize&7, &atrusted&7, "
|
||||||
+ "&aowner&7, &arating");
|
+ "&aowner&7, " + (Settings.Ratings.USE_LIKES ? " &alikes" : " &arating"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
full = true;
|
full = true;
|
||||||
@ -169,6 +171,8 @@ import java.util.UUID;
|
|||||||
return Captions.PLOT_INFO_OWNER.s();
|
return Captions.PLOT_INFO_OWNER.s();
|
||||||
case "rating":
|
case "rating":
|
||||||
return Captions.PLOT_INFO_RATING.s();
|
return Captions.PLOT_INFO_RATING.s();
|
||||||
|
case "likes":
|
||||||
|
return Captions.PLOT_INFO_LIKES.s();
|
||||||
case "seen":
|
case "seen":
|
||||||
return Captions.PLOT_INFO_SEEN.s();
|
return Captions.PLOT_INFO_SEEN.s();
|
||||||
default:
|
default:
|
||||||
|
@ -0,0 +1,143 @@
|
|||||||
|
package com.github.intellectualsites.plotsquared.plot.commands;
|
||||||
|
|
||||||
|
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.Rating;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.EventUtil;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.Permissions;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
@CommandDeclaration(command = "like", permission = "plots.like", description = "Like the plot",
|
||||||
|
usage = "/plot like [next|purge]", category = CommandCategory.INFO, requiredType = RequiredType.PLAYER)
|
||||||
|
public class Like extends SubCommand {
|
||||||
|
|
||||||
|
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||||
|
return handleLike(player, args, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static boolean handleLike(final PlotPlayer player, String[] args, final boolean like) {
|
||||||
|
final UUID uuid = player.getUUID();
|
||||||
|
if (args.length == 1) {
|
||||||
|
switch (args[0].toLowerCase()) {
|
||||||
|
case "next": {
|
||||||
|
final List<Plot> plots = new ArrayList<>(PlotSquared.get().getBasePlots());
|
||||||
|
plots.sort((p1, p2) -> {
|
||||||
|
double v1 = getLikesPercentage(p1);
|
||||||
|
double v2 = getLikesPercentage(p2);
|
||||||
|
if (v1 == v2) {
|
||||||
|
return -0;
|
||||||
|
}
|
||||||
|
return v2 > v1 ? 1 : -1;
|
||||||
|
});
|
||||||
|
for (final Plot plot : plots) {
|
||||||
|
if ((!Settings.Done.REQUIRED_FOR_RATINGS || plot.hasFlag(Flags.DONE))
|
||||||
|
&& plot.isBasePlot() && (!plot.getLikes().containsKey(uuid))) {
|
||||||
|
plot.teleportPlayer(player);
|
||||||
|
MainUtil.sendMessage(player, Captions.RATE_THIS);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MainUtil.sendMessage(player, Captions.FOUND_NO_PLOTS);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case "purge": {
|
||||||
|
final Plot plot = player.getCurrentPlot();
|
||||||
|
if (plot == null) {
|
||||||
|
return !sendMessage(player, Captions.NOT_IN_PLOT);
|
||||||
|
}
|
||||||
|
if (!Permissions
|
||||||
|
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_RATE, true)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
plot.clearRatings();
|
||||||
|
Captions.RATINGS_PURGED.send(player);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
final Plot plot = player.getCurrentPlot();
|
||||||
|
if (plot == null) {
|
||||||
|
return !sendMessage(player, Captions.NOT_IN_PLOT);
|
||||||
|
}
|
||||||
|
if (!plot.hasOwner()) {
|
||||||
|
sendMessage(player, Captions.RATING_NOT_OWNED);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (plot.isOwner(player.getUUID())) {
|
||||||
|
sendMessage(player, Captions.RATING_NOT_YOUR_OWN);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (Settings.Done.REQUIRED_FOR_RATINGS && !plot.hasFlag(Flags.DONE)) {
|
||||||
|
sendMessage(player, Captions.RATING_NOT_DONE);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final Runnable run = () -> {
|
||||||
|
final Boolean oldRating = plot.getLikes().get(uuid);
|
||||||
|
if (oldRating != null) {
|
||||||
|
sendMessage(player, Captions.RATING_ALREADY_EXISTS, plot.getId().toString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final int rating;
|
||||||
|
if (like) {
|
||||||
|
rating = 10;
|
||||||
|
} else {
|
||||||
|
rating = 1;
|
||||||
|
}
|
||||||
|
plot.addRating(uuid, new Rating(rating));
|
||||||
|
final Rating result = EventUtil.manager.callRating(player, plot, new Rating(rating));
|
||||||
|
if (result != null) {
|
||||||
|
plot.addRating(uuid, result);
|
||||||
|
sendMessage(player, like ? Captions.RATING_LIKED : Captions.RATING_DISLIKED,
|
||||||
|
plot.getId().toString());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (plot.getSettings().ratings == null) {
|
||||||
|
if (!Settings.Enabled_Components.RATING_CACHE) {
|
||||||
|
TaskManager.runTaskAsync(() -> {
|
||||||
|
plot.getSettings().ratings = DBFunc.getRatings(plot);
|
||||||
|
run.run();
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
plot.getSettings().ratings = new HashMap<>();
|
||||||
|
}
|
||||||
|
run.run();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the likes to dislike ratio of a plot as a percentage (in decimal form)
|
||||||
|
*
|
||||||
|
* @return likes to dislike ratio, returns zero if the plot has no likes
|
||||||
|
*/
|
||||||
|
public static double getLikesPercentage(final Plot plot) {
|
||||||
|
if (!plot.hasRatings()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
final Collection<Boolean> reactions = plot.getLikes().values();
|
||||||
|
double numLikes = 0, numDislikes = 0;
|
||||||
|
for (final boolean reaction : reactions) {
|
||||||
|
if (reaction) {
|
||||||
|
numLikes += 1;
|
||||||
|
} else {
|
||||||
|
numDislikes += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (numLikes == 0 && numDislikes == 0) {
|
||||||
|
return 0D;
|
||||||
|
} else if (numDislikes == 0) {
|
||||||
|
return 1.0D;
|
||||||
|
}
|
||||||
|
return numLikes / (numLikes + numDislikes);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -4,6 +4,7 @@ import com.github.intellectualsites.plotsquared.commands.Command;
|
|||||||
import com.github.intellectualsites.plotsquared.commands.CommandCaller;
|
import com.github.intellectualsites.plotsquared.commands.CommandCaller;
|
||||||
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
|
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
|
||||||
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||||
import com.github.intellectualsites.plotsquared.plot.object.*;
|
import com.github.intellectualsites.plotsquared.plot.object.*;
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.CmdConfirm;
|
import com.github.intellectualsites.plotsquared.plot.util.CmdConfirm;
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.EconHandler;
|
import com.github.intellectualsites.plotsquared.plot.util.EconHandler;
|
||||||
@ -68,7 +69,6 @@ public class MainCommand extends Command {
|
|||||||
new DebugPaste();
|
new DebugPaste();
|
||||||
new Unlink();
|
new Unlink();
|
||||||
new Kick();
|
new Kick();
|
||||||
new Rate();
|
|
||||||
new DebugClaimTest();
|
new DebugClaimTest();
|
||||||
new Inbox();
|
new Inbox();
|
||||||
new Comment();
|
new Comment();
|
||||||
@ -98,6 +98,14 @@ public class MainCommand extends Command {
|
|||||||
new SetHome();
|
new SetHome();
|
||||||
new Cluster();
|
new Cluster();
|
||||||
new DebugImportWorlds();
|
new DebugImportWorlds();
|
||||||
|
|
||||||
|
if (Settings.Ratings.USE_LIKES) {
|
||||||
|
new Like();
|
||||||
|
new Dislike();
|
||||||
|
} else {
|
||||||
|
new Rate();
|
||||||
|
}
|
||||||
|
|
||||||
// Referenced commands
|
// Referenced commands
|
||||||
instance.toggle = new Toggle();
|
instance.toggle = new Toggle();
|
||||||
instance.help = new Help(instance);
|
instance.help = new Help(instance);
|
||||||
|
@ -32,7 +32,7 @@ public abstract class SubCommand extends Command {
|
|||||||
|
|
||||||
public abstract boolean onCommand(PlotPlayer player, String[] args);
|
public abstract boolean onCommand(PlotPlayer player, String[] args);
|
||||||
|
|
||||||
public boolean sendMessage(PlotPlayer player, Captions message, Object... args) {
|
public static boolean sendMessage(PlotPlayer player, Captions message, Object... args) {
|
||||||
message.send(player, args);
|
message.send(player, args);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -378,6 +378,9 @@ public enum Captions {
|
|||||||
RATING_ALREADY_EXISTS("$2You have already rated plot $2%s", "Ratings"), RATING_APPLIED(
|
RATING_ALREADY_EXISTS("$2You have already rated plot $2%s", "Ratings"), RATING_APPLIED(
|
||||||
"$4You successfully rated plot $2%s", "Ratings"),
|
"$4You successfully rated plot $2%s", "Ratings"),
|
||||||
|
|
||||||
|
RATING_DISLIKED("$4You successfully disliked plot $2%s", "Ratings"),
|
||||||
|
RATING_LIKED("$4You successfully liked plot $2%s", "Ratings"),
|
||||||
|
|
||||||
RATING_NOT_YOUR_OWN("$2You cannot rate your own plot", "Ratings"), RATING_NOT_DONE(
|
RATING_NOT_YOUR_OWN("$2You cannot rate your own plot", "Ratings"), RATING_NOT_DONE(
|
||||||
"$2You can only rate finished plots.", "Ratings"),
|
"$2You can only rate finished plots.", "Ratings"),
|
||||||
|
|
||||||
@ -693,6 +696,8 @@ public enum Captions {
|
|||||||
|
|
||||||
PLOT_INFO_BIOME("$1Biome:$2 %biome%", "Info"), PLOT_INFO_RATING("$1Rating:$2 %rating%", "Info"),
|
PLOT_INFO_BIOME("$1Biome:$2 %biome%", "Info"), PLOT_INFO_RATING("$1Rating:$2 %rating%", "Info"),
|
||||||
|
|
||||||
|
PLOT_INFO_LIKES("$1Like Ratio:$2 %likes%%", "Info"),
|
||||||
|
|
||||||
PLOT_INFO_OWNER("$1Owner:$2 %owner%", "Info"), PLOT_INFO_ID("$1ID:$2 %id%", "Info"),
|
PLOT_INFO_OWNER("$1Owner:$2 %owner%", "Info"), PLOT_INFO_ID("$1ID:$2 %id%", "Info"),
|
||||||
|
|
||||||
PLOT_INFO_ALIAS("$1Alias:$2 %alias%", "Info"), PLOT_INFO_SIZE("$1Size:$2 %size%", "Info"),
|
PLOT_INFO_ALIAS("$1Alias:$2 %alias%", "Info"), PLOT_INFO_SIZE("$1Size:$2 %size%", "Info"),
|
||||||
|
@ -315,6 +315,9 @@ public class Settings extends Config {
|
|||||||
|
|
||||||
|
|
||||||
public static final class Ratings {
|
public static final class Ratings {
|
||||||
|
@Comment("Replace the rating system with a like system. Will add /plot like/dislike,"
|
||||||
|
+ " and remove the rating command") public static boolean USE_LIKES = false;
|
||||||
|
@Comment("Rating categories")
|
||||||
public static List<String> CATEGORIES = new ArrayList<>();
|
public static List<String> CATEGORIES = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1344,7 +1344,7 @@ public class Plot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear the ratings for this plot
|
* Clear the ratings/likes for this plot
|
||||||
*/
|
*/
|
||||||
public void clearRatings() {
|
public void clearRatings() {
|
||||||
Plot base = this.getBasePlot(false);
|
Plot base = this.getBasePlot(false);
|
||||||
@ -1355,6 +1355,15 @@ public class Plot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<UUID, Boolean> getLikes() {
|
||||||
|
final Map<UUID, Boolean> map = new HashMap<>();
|
||||||
|
final Map<UUID, Rating> ratings = this.getRatings();
|
||||||
|
ratings.forEach((uuid, rating) -> {
|
||||||
|
map.put(uuid, rating.getLike());
|
||||||
|
});
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the ratings associated with a plot<br>
|
* Gets the ratings associated with a plot<br>
|
||||||
* - The rating object may contain multiple categories
|
* - The rating object may contain multiple categories
|
||||||
|
@ -9,6 +9,9 @@ import java.util.Map.Entry;
|
|||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
public class Rating {
|
public class Rating {
|
||||||
|
|
||||||
|
private static final String LIKE_INTERNAL = "__LIKES__";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a map of the rating category to the rating value
|
* This is a map of the rating category to the rating value
|
||||||
*/
|
*/
|
||||||
@ -17,8 +20,12 @@ public class Rating {
|
|||||||
private boolean changed;
|
private boolean changed;
|
||||||
|
|
||||||
public Rating(int value) {
|
public Rating(int value) {
|
||||||
this.initial = value;
|
|
||||||
this.ratingMap = new HashMap<>();
|
this.ratingMap = new HashMap<>();
|
||||||
|
if (Settings.Ratings.USE_LIKES) {
|
||||||
|
this.initial = value == 10 ? 10 : 1;
|
||||||
|
this.ratingMap.put(LIKE_INTERNAL, this.initial == 10 ? 10 : 1);
|
||||||
|
} else {
|
||||||
|
this.initial = value;
|
||||||
if (Settings.Ratings.CATEGORIES != null && Settings.Ratings.CATEGORIES.size() > 1) {
|
if (Settings.Ratings.CATEGORIES != null && Settings.Ratings.CATEGORIES.size() > 1) {
|
||||||
if (value < 10) {
|
if (value < 10) {
|
||||||
for (String ratingCategory : Settings.Ratings.CATEGORIES) {
|
for (String ratingCategory : Settings.Ratings.CATEGORIES) {
|
||||||
@ -35,6 +42,7 @@ public class Rating {
|
|||||||
this.ratingMap.put(null, value);
|
this.ratingMap.put(null, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public List<String> getCategories() {
|
public List<String> getCategories() {
|
||||||
if (this.ratingMap.size() == 1) {
|
if (this.ratingMap.size() == 1) {
|
||||||
@ -44,10 +52,18 @@ public class Rating {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public double getAverageRating() {
|
public double getAverageRating() {
|
||||||
|
if (Settings.Ratings.USE_LIKES) {
|
||||||
|
return getLike() ? 10 : 1;
|
||||||
|
}
|
||||||
double total = this.ratingMap.entrySet().stream().mapToDouble(Entry::getValue).sum();
|
double total = this.ratingMap.entrySet().stream().mapToDouble(Entry::getValue).sum();
|
||||||
return total / this.ratingMap.size();
|
return total / this.ratingMap.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getLike() {
|
||||||
|
final Integer rating = this.getRating(LIKE_INTERNAL);
|
||||||
|
return rating != null && rating == 10;
|
||||||
|
}
|
||||||
|
|
||||||
public Integer getRating(String category) {
|
public Integer getRating(String category) {
|
||||||
return this.ratingMap.get(category);
|
return this.ratingMap.get(category);
|
||||||
}
|
}
|
||||||
@ -64,6 +80,9 @@ public class Rating {
|
|||||||
if (!this.changed) {
|
if (!this.changed) {
|
||||||
return this.initial;
|
return this.initial;
|
||||||
}
|
}
|
||||||
|
if (Settings.Ratings.USE_LIKES) {
|
||||||
|
return this.ratingMap.get(LIKE_INTERNAL);
|
||||||
|
}
|
||||||
if (Settings.Ratings.CATEGORIES != null && Settings.Ratings.CATEGORIES.size() > 1) {
|
if (Settings.Ratings.CATEGORIES != null && Settings.Ratings.CATEGORIES.size() > 1) {
|
||||||
return IntStream.range(0, Settings.Ratings.CATEGORIES.size()).map(
|
return IntStream.range(0, Settings.Ratings.CATEGORIES.size()).map(
|
||||||
i -> (int) ((i + 1) * Math
|
i -> (int) ((i + 1) * Math
|
||||||
|
@ -2,6 +2,7 @@ package com.github.intellectualsites.plotsquared.plot.util;
|
|||||||
|
|
||||||
import com.github.intellectualsites.plotsquared.commands.CommandCaller;
|
import com.github.intellectualsites.plotsquared.commands.CommandCaller;
|
||||||
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.commands.Like;
|
||||||
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||||
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||||
import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
|
import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
|
||||||
@ -776,11 +777,14 @@ public class MainUtil {
|
|||||||
if (info.contains("%rating%")) {
|
if (info.contains("%rating%")) {
|
||||||
final String newInfo = info;
|
final String newInfo = info;
|
||||||
TaskManager.runTaskAsync(() -> {
|
TaskManager.runTaskAsync(() -> {
|
||||||
|
String info1;
|
||||||
|
if (Settings.Ratings.USE_LIKES) {
|
||||||
|
info1 = newInfo.replaceAll("%rating%", String.format("%.0f%%", Like.getLikesPercentage(plot) * 100D));
|
||||||
|
} else {
|
||||||
int max = 10;
|
int max = 10;
|
||||||
if (Settings.Ratings.CATEGORIES != null && !Settings.Ratings.CATEGORIES.isEmpty()) {
|
if (Settings.Ratings.CATEGORIES != null && !Settings.Ratings.CATEGORIES.isEmpty()) {
|
||||||
max = 8;
|
max = 8;
|
||||||
}
|
}
|
||||||
String info1;
|
|
||||||
if (full && Settings.Ratings.CATEGORIES != null
|
if (full && Settings.Ratings.CATEGORIES != null
|
||||||
&& Settings.Ratings.CATEGORIES.size() > 1) {
|
&& Settings.Ratings.CATEGORIES.size() > 1) {
|
||||||
double[] ratings = MainUtil.getAverageRatings(plot);
|
double[] ratings = MainUtil.getAverageRatings(plot);
|
||||||
@ -796,6 +800,7 @@ public class MainUtil {
|
|||||||
info1 = newInfo.replaceAll("%rating%",
|
info1 = newInfo.replaceAll("%rating%",
|
||||||
String.format("%.1f", plot.getAverageRating()) + '/' + max);
|
String.format("%.1f", plot.getAverageRating()) + '/' + max);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
whenDone.run(info1);
|
whenDone.run(info1);
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
|
@ -245,10 +245,12 @@ public class StringMan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isEqual(String a, String b) {
|
public static boolean isEqual(String a, String b) {
|
||||||
return (a == b) || ((a != null) && (b != null) && (a.length() == b.length()) && (
|
if ((a == null && b != null) || (a != null && b == null)) {
|
||||||
a.hashCode() == b.hashCode()) && a.equals(b));
|
return false;
|
||||||
// return a.equals(b) || b != null && a.length() == b.length() && a.hashCode() == b.hashCode()
|
} else if (a == null /* implies that b is null */) {
|
||||||
// && a.equals(b);
|
return false;
|
||||||
|
}
|
||||||
|
return a.equals(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isEqualIgnoreCase(String a, String b) {
|
public static boolean isEqualIgnoreCase(String a, String b) {
|
||||||
|
Loading…
Reference in New Issue
Block a user