diff --git a/Core/src/main/java/com/intellectualcrafters/plot/PS.java b/Core/src/main/java/com/intellectualcrafters/plot/PS.java index 8b2b47fc3..7ace1dc97 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/PS.java @@ -1098,7 +1098,7 @@ public class PS { } } } - ArrayList areas = new ArrayList<>(Arrays.asList(plotareas)); + List areas = Arrays.asList(plotareas); Collections.sort(areas, new Comparator() { @Override public int compare(final PlotArea a, final PlotArea b) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Rate.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Rate.java index b4fcd2f49..4c8eb861c 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Rate.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Rate.java @@ -20,13 +20,6 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Map.Entry; -import java.util.UUID; - import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; @@ -44,6 +37,13 @@ import com.intellectualcrafters.plot.util.TaskManager; import com.plotsquared.general.commands.Command; import com.plotsquared.general.commands.CommandDeclaration; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Map.Entry; +import java.util.UUID; + @CommandDeclaration( command = "rate", permission = "plots.rate", @@ -129,9 +129,7 @@ public class Rate extends SubCommand { close(); final int rV = rating.getValue(); final Rating result = EventUtil.manager.callRating(player, plot, new Rating(rV)); - plot.getSettings().ratings.put(player.getUUID(), result.getAggregate()); - DBFunc.setRating(plot, player.getUUID(), rV); - sendMessage(player, C.RATING_APPLIED, plot.getId().toString()); + plot.addRating(player.getUUID(), result); sendMessage(player, C.RATING_APPLIED, plot.getId().toString()); return false; } @@ -193,14 +191,12 @@ public class Rate extends SubCommand { final Runnable run = new Runnable() { @Override public void run() { - if (plot.getSettings().ratings.containsKey(uuid)) { + if (plot.getRatings().containsKey(uuid)) { sendMessage(player, C.RATING_ALREADY_EXISTS, plot.getId().toString()); return; } final Rating result = EventUtil.manager.callRating(player, plot, new Rating(rating)); - final int resultVal = result.getAggregate(); - plot.getSettings().ratings.put(uuid, resultVal); - DBFunc.setRating(plot, uuid, resultVal); + plot.addRating(uuid,result); sendMessage(player, C.RATING_APPLIED, plot.getId().toString()); } }; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/list.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/list.java index 7b37b720a..9bdfa1043 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/list.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/list.java @@ -140,7 +140,7 @@ public class list extends SubCommand { MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.shared"); return false; } - plots = new ArrayList(); + plots = new ArrayList<>(); for (final Plot plot : PS.get().getPlots()) { if (plot.getTrusted().contains(plr.getUUID()) || plot.getMembers().contains(plr.getUUID())) { plots.add(plot); @@ -177,7 +177,7 @@ public class list extends SubCommand { MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.world." + world); return false; } - plots = area == null ? new ArrayList() : new ArrayList(area.getPlots()); + plots = area == null ? new ArrayList() : new ArrayList<>(area.getPlots()); break; } case "all": { @@ -348,7 +348,7 @@ public class list extends SubCommand { } if (plots == null) { - sendMessage(plr, C.DID_YOU_MEAN, new StringComparison(args[0], new String[] { "mine", "shared", "world", "all" }).getBestMatch()); + sendMessage(plr, C.DID_YOU_MEAN, new StringComparison<>(args[0], new String[]{"mine", "shared", "world", "all"}).getBestMatch()); return false; } @@ -371,7 +371,7 @@ public class list extends SubCommand { if (sort) { plots = PS.get().sortPlots(plots, SortType.CREATION_DATE, area); } - this. paginate(player, plots, pageSize, page, new RunnableVal3() { + this.paginate(player, plots, pageSize, page, new RunnableVal3() { @Override public void run(Integer i, Plot plot, PlotMessage message) { String color; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index 095c09d38..a44be9779 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -1631,17 +1631,8 @@ public class SQLManager implements AbstractDB { user = UUID.fromString(o); uuids.put(o, user); } - Timestamp timestamp = null; - try { - timestamp = r.getTimestamp("timestamp"); - } catch (SQLException ignored) { - } - long time; - if (timestamp == null) { - time = plot_id.hashCode(); - } else { - time = timestamp.getTime(); - } + Timestamp timestamp = r.getTimestamp("timestamp"); + long time = timestamp.getTime(); Plot p = new Plot(plot_id, user, new HashSet(), new HashSet(), new HashSet(), "", null, null, null, new boolean[]{false, false, false, false}, time, id); HashMap map = newplots.get(areaid); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java b/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java index 5f0952587..a6b1a5513 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -1182,7 +1182,7 @@ public class Plot { public void clearRatings() { final Plot base = this.getBasePlot(false); final PlotSettings baseSettings = base.getSettings(); - if ((baseSettings.ratings != null) && !baseSettings.ratings.isEmpty()) { + if ((baseSettings.ratings != null) && !baseSettings.getRatings().isEmpty()) { DBFunc.deleteRatings(base); baseSettings.ratings = null; } @@ -1196,10 +1196,10 @@ public class Plot { public HashMap getRatings() { final Plot base = this.getBasePlot(false); final HashMap map = new HashMap<>(); - if (base.getSettings().ratings == null) { + if (!base.hasRatings()) { return map; } - for (final Entry entry : base.getSettings().ratings.entrySet()) { + for (final Entry entry : base.getSettings().getRatings().entrySet()) { map.put(entry.getKey(), new Rating(entry.getValue())); } return map; @@ -1207,7 +1207,11 @@ public class Plot { public boolean hasRatings() { Plot base = this.getBasePlot(false); - return base.settings != null && base.settings.ratings != null; + if (base.settings != null && base.settings.ratings != null) { + return true; + } else { + return false; + } } /** @@ -1946,6 +1950,8 @@ public class Plot { final int index = caption.indexOf("%plr%"); if (index == -1) { continue; + } else if (index < -1) { + PS.debug("This should NEVER happen. Seriously, it's impossible."); } final String name = lines[i - 1].substring(index); if (name.isEmpty()) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotAnalysis.java b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotAnalysis.java index 063af1a0e..3c34bdf13 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotAnalysis.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotAnalysis.java @@ -84,7 +84,7 @@ public class PlotAnalysis { PS.debug(" - $1Reducing " + plots.size() + " plots to those with sufficient data"); while (iter.hasNext()) { final Plot plot = iter.next(); - if ((plot.getSettings().ratings == null) || (plot.getSettings().ratings.isEmpty())) { + if ((plot.getSettings().ratings == null) || (plot.getSettings().getRatings().isEmpty())) { iter.remove(); } else { plot.addRunning(); @@ -125,7 +125,7 @@ public class PlotAnalysis { for (; mi.intValue() < plots.size(); mi.incrementAndGet()) { final int i = mi.intValue(); final Plot plot = plots.get(i); - ratings[i] = (int) ((plot.getAverageRating() + plot.getSettings().ratings.size()) * 100); + ratings[i] = (int) ((plot.getAverageRating() + plot.getSettings().getRatings().size()) * 100); PS.debug(" | " + plot + " (rating) " + (ratings[i])); } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/Rating.java b/Core/src/main/java/com/intellectualcrafters/plot/object/Rating.java index 270fa6def..d5b91df97 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/Rating.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/Rating.java @@ -1,12 +1,12 @@ package com.intellectualcrafters.plot.object; +import com.intellectualcrafters.plot.config.Settings; + 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 { /** @@ -22,15 +22,15 @@ public class Rating { ratingMap = new HashMap<>(); if ((Settings.RATING_CATEGORIES != null) && (Settings.RATING_CATEGORIES.size() > 1)) { if (value < 10) { - for (int i = 0; i < Settings.RATING_CATEGORIES.size(); i++) { - ratingMap.put(Settings.RATING_CATEGORIES.get(i), value); + for (String ratingCategory : Settings.RATING_CATEGORIES) { + ratingMap.put(ratingCategory, value); } changed = true; return; } - for (int i = 0; i < Settings.RATING_CATEGORIES.size(); i++) { - ratingMap.put(Settings.RATING_CATEGORIES.get(i), (value % 10) - 1); - value /= 10; + for (String ratingCategory : Settings.RATING_CATEGORIES) { + ratingMap.put(ratingCategory, (value % 10) - 1); + value = value / 10; } } else { ratingMap.put(null, value); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java b/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java index 984e49f92..9ded120a4 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java @@ -613,43 +613,7 @@ public class MainUtil { }); return true; } - - /** - * Get the average rating for a plot - * @see Plot#getAverageRating() - * @param plot - * @return - */ - public static double getAverageRating(final Plot plot) { - HashMap rating; - if (plot.getSettings().ratings != null) { - rating = plot.getSettings().ratings; - } else if (Settings.CACHE_RATINGS) { - rating = new HashMap<>(); - } else { - rating = DBFunc.getRatings(plot); - } - if (rating == null || rating.isEmpty()) { - return 0; - } - double val = 0; - int size = 0; - for (final Entry entry : rating.entrySet()) { - int current = entry.getValue(); - if (Settings.RATING_CATEGORIES == null || Settings.RATING_CATEGORIES.isEmpty()) { - val += current; - size++; - } else { - for (int i = 0; i < Settings.RATING_CATEGORIES.size(); i++) { - val += current % 10 - 1; - current /= 10; - size++; - } - } - } - return val / size; - } - + /** * If rating categories are enabled, get the average rating by category.
* - The index corresponds to the index of the category in the config @@ -755,7 +719,7 @@ public class MainUtil { } info = newInfo.replaceAll("%rating%", rating); } else { - info = newInfo.replaceAll("%rating%", String.format("%.1f", MainUtil.getAverageRating(plot)) + "/" + max); + info = newInfo.replaceAll("%rating%", String.format("%.1f", plot.getAverageRating()) + "/" + max); } whenDone.run(info); } diff --git a/Sponge/build.gradle b/Sponge/build.gradle index e2a444e92..a0300fd06 100644 --- a/Sponge/build.gradle +++ b/Sponge/build.gradle @@ -16,7 +16,7 @@ apply plugin: 'com.github.johnrengelman.shadow' dependencies { compile project(':Core') - compile 'org.spongepowered:spongeapi:3.1.0-SNAPSHOT' + compile 'org.spongepowered:spongeapi:4.0.3' } sourceCompatibility = 1.8 @@ -69,4 +69,4 @@ task deobfJar(type: Jar) { classifier = 'dev' } -build.dependsOn(shadowJar) \ No newline at end of file +build.dependsOn(shadowJar) diff --git a/Sponge/src/main/java/com/plotsquared/sponge/listener/MainListener.java b/Sponge/src/main/java/com/plotsquared/sponge/listener/MainListener.java index b285a4e82..d3d7e4c27 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/listener/MainListener.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/listener/MainListener.java @@ -94,7 +94,7 @@ public class MainListener { @Listener public void onChat(final MessageEvent event) { // TODO - Player player = SpongeUtil. getCause(event.getCause(), Player.class); + Player player = SpongeUtil.getCause(event.getCause(), Player.class); if (player == null) { return; } @@ -112,7 +112,7 @@ public class MainListener { if (plot == null) { return; } - final Text message = event.getMessage().orElse(Text.EMPTY); + final Text message = event.getMessage(); // TODO use display name rather than username // - Getting displayname currently causes NPE, so wait until sponge fixes that @@ -120,7 +120,7 @@ public class MainListener { final String sender = player.getName(); final PlotId id = plot.getId(); final String newMessage = StringMan.replaceAll(C.PLOT_CHAT_FORMAT.s(), "%plot_id%", id.x + ";" + id.y, "%sender%", sender); - final Text forcedMessage = event.getMessage().orElse(Text.EMPTY); + final Text forcedMessage = event.getMessage(); // String forcedMessage = StringMan.replaceAll(C.PLOT_CHAT_FORCED.s(), "%plot_id%", id.x + ";" + id.y, "%sender%", sender); for (Entry entry : UUIDHandler.getPlayers().entrySet()) { PlotPlayer user = entry.getValue(); @@ -146,7 +146,7 @@ public class MainListener { } ((SpongePlayer) user).player.sendMessage(Text.join(components)); } - event.setMessage(null); + event.clearMessage(); } @Listener @@ -321,7 +321,7 @@ public class MainListener { @Listener public void onInteract(InteractEvent event) throws Exception { - final Player player = SpongeUtil. getCause(event.getCause(), Player.class); + final Player player = SpongeUtil.getCause(event.getCause(), Player.class); if (player == null) { event.setCancelled(true); return; @@ -455,7 +455,7 @@ public class MainListener { @Listener public void onBlockBreak(final ChangeBlockEvent.Break event) { - Player player = SpongeUtil. getCause(event.getCause(), Player.class); + Player player = SpongeUtil.getCause(event.getCause(), Player.class); if (player == null) { // SpongeUtil.printCause("break", event.getCause()); return; @@ -539,7 +539,7 @@ public class MainListener { @Listener public void onBlockPlace(final ChangeBlockEvent.Place event) { - Player player = SpongeUtil. getCause(event.getCause(), Player.class); + Player player = SpongeUtil.getCause(event.getCause(), Player.class); if (player == null) { // SpongeUtil.printCause("place", event.getCause()); return; @@ -761,4 +761,4 @@ public class MainListener { } } } -} \ No newline at end of file +}