diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/Platform.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/Platform.java index b7eb33b83..9dfbf2ffb 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/Platform.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/Platform.java @@ -1,6 +1,6 @@ package com.github.intellectualsites.plotsquared.plot; public enum Platform { - Bukkit, Sponge, Spigot, Cauldron + Bukkit, Sponge, Spigot } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/ListCmd.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/ListCmd.java index 9df74d30b..c4b095f8d 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/ListCmd.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/ListCmd.java @@ -165,18 +165,16 @@ public class ListCmd extends SubCommand { plots.add(plot); } } - Collections.sort(plots, new Comparator() { - @Override public int compare(Plot a, Plot b) { - String va = "" + a.getFlags().get(Flags.DONE); - String vb = "" + b.getFlags().get(Flags.DONE); - if (MathMan.isInteger(va)) { - if (MathMan.isInteger(vb)) { - return Integer.parseInt(vb) - Integer.parseInt(va); - } - return -1; + plots.sort((a, b) -> { + String va = "" + a.getFlags().get(Flags.DONE); + String vb = "" + b.getFlags().get(Flags.DONE); + if (MathMan.isInteger(va)) { + if (MathMan.isInteger(vb)) { + return Integer.parseInt(vb) - Integer.parseInt(va); } - return 1; + return -1; } + return 1; }); sort = false; break; @@ -186,33 +184,30 @@ public class ListCmd extends SubCommand { return false; } plots = new ArrayList<>(PlotSquared.get().getPlots()); - Collections.sort(plots, new Comparator() { - @Override public int compare(Plot p1, Plot p2) { - double v1 = 0; - int p1s = p1.getSettings().getRatings().size(); - int p2s = p2.getRatings().size(); - if (!p1.getSettings().getRatings().isEmpty()) { - for (Entry entry : p1.getRatings().entrySet()) { - double av = entry.getValue().getAverageRating(); - v1 += av * av; - } - v1 /= p1s; - v1 += p1s; - } - double v2 = 0; - if (!p2.getSettings().getRatings().isEmpty()) { - for (Entry entry : p2.getRatings().entrySet()) { - double av = entry.getValue().getAverageRating(); - v2 += av * av; - } - v2 /= p2s; - v2 += p2s; - } - if (v2 == v1 && v2 != 0) { - return p2s - p1s; - } - return (int) Math.signum(v2 - v1); + plots.sort((p1, p2) -> { + double v1 = 0; + int p1s = p1.getSettings().getRatings().size(); + int p2s = p2.getRatings().size(); + if (!p1.getSettings().getRatings().isEmpty()) { + v1 = p1.getRatings().entrySet().stream() + .mapToDouble(entry -> entry.getValue().getAverageRating()) + .map(av -> av * av).sum(); + v1 /= p1s; + v1 += p1s; } + double v2 = 0; + if (!p2.getSettings().getRatings().isEmpty()) { + for (Entry entry : p2.getRatings().entrySet()) { + double av = entry.getValue().getAverageRating(); + v2 += av * av; + } + v2 /= p2s; + v2 += p2s; + } + if (v2 == v1 && v2 != 0) { + return p2s - p1s; + } + return (int) Math.signum(v2 - v1); }); sort = false; break; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Rate.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Rate.java index 7141df96e..59e2b2d43 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Rate.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Rate.java @@ -22,25 +22,23 @@ import java.util.Map.Entry; switch (args[0].toLowerCase()) { case "next": { ArrayList plots = new ArrayList<>(PlotSquared.get().getBasePlots()); - Collections.sort(plots, new Comparator() { - @Override public int compare(Plot p1, Plot p2) { - double v1 = 0; - if (!p1.getRatings().isEmpty()) { - for (Entry entry : p1.getRatings().entrySet()) { - v1 -= 11 - entry.getValue().getAverageRating(); - } + plots.sort((p1, p2) -> { + double v1 = 0; + if (!p1.getRatings().isEmpty()) { + for (Entry entry : p1.getRatings().entrySet()) { + v1 -= 11 - entry.getValue().getAverageRating(); } - double v2 = 0; - if (!p2.getRatings().isEmpty()) { - for (Entry entry : p2.getRatings().entrySet()) { - v2 -= 11 - entry.getValue().getAverageRating(); - } - } - if (v1 == v2) { - return -0; - } - return v2 > v1 ? 1 : -1; } + double v2 = 0; + if (!p2.getRatings().isEmpty()) { + for (Entry entry : p2.getRatings().entrySet()) { + v2 -= 11 - entry.getValue().getAverageRating(); + } + } + if (v1 == v2) { + return -0; + } + return v2 > v1 ? 1 : -1; }); UUID uuid = player.getUUID(); for (Plot p : plots) { @@ -137,11 +135,9 @@ import java.util.Map.Entry; }; if (plot.getSettings().ratings == null) { if (!Settings.Enabled_Components.RATING_CACHE) { - TaskManager.runTaskAsync(new Runnable() { - @Override public void run() { - plot.getSettings().ratings = DBFunc.getRatings(plot); - run.run(); - } + TaskManager.runTaskAsync(() -> { + plot.getSettings().ratings = DBFunc.getRatings(plot); + run.run(); }); return true; } @@ -167,26 +163,22 @@ import java.util.Map.Entry; return false; } final UUID uuid = player.getUUID(); - final Runnable run = new Runnable() { - @Override public void run() { - if (plot.getRatings().containsKey(uuid)) { - sendMessage(player, C.RATING_ALREADY_EXISTS, plot.getId().toString()); - return; - } - Rating result = EventUtil.manager.callRating(player, plot, new Rating(rating)); - if (result != null) { - plot.addRating(uuid, result); - sendMessage(player, C.RATING_APPLIED, plot.getId().toString()); - } + final Runnable run = () -> { + if (plot.getRatings().containsKey(uuid)) { + sendMessage(player, C.RATING_ALREADY_EXISTS, plot.getId().toString()); + return; + } + Rating result = EventUtil.manager.callRating(player, plot, new Rating(rating)); + if (result != null) { + plot.addRating(uuid, result); + sendMessage(player, C.RATING_APPLIED, plot.getId().toString()); } }; if (plot.getSettings().ratings == null) { if (!Settings.Enabled_Components.RATING_CACHE) { - TaskManager.runTaskAsync(new Runnable() { - @Override public void run() { - plot.getSettings().ratings = DBFunc.getRatings(plot); - run.run(); - } + TaskManager.runTaskAsync(() -> { + plot.getSettings().ratings = DBFunc.getRatings(plot); + run.run(); }); return true; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/database/MySQL.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/database/MySQL.java index 7e7df9124..d5943d1ac 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/database/MySQL.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/database/MySQL.java @@ -45,7 +45,7 @@ public class MySQL extends Database { return this.connection; } - @Override public Connection openConnection() throws SQLException, ClassNotFoundException { + @Override public Connection openConnection() throws SQLException { if (checkConnection()) { return this.connection; } @@ -69,7 +69,7 @@ public class MySQL extends Database { return true; } - @Override public ResultSet querySQL(String query) throws SQLException, ClassNotFoundException { + @Override public ResultSet querySQL(String query) throws SQLException { if (checkConnection()) { openConnection(); } @@ -78,7 +78,7 @@ public class MySQL extends Database { } } - @Override public int updateSQL(String query) throws SQLException, ClassNotFoundException { + @Override public int updateSQL(String query) throws SQLException { if (checkConnection()) { openConnection(); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/database/SQLManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/database/SQLManager.java index 1c3395b56..013b2c7ca 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/database/SQLManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/database/SQLManager.java @@ -2616,7 +2616,7 @@ import java.util.concurrent.atomic.AtomicInteger; } catch (Exception ignored) { } } - Integer m = resultSet.getInt("merged"); + int m = resultSet.getInt("merged"); boolean[] merged = new boolean[4]; for (int i = 0; i < 4; i++) { merged[3 - i] = (m & 1 << i) != 0; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java index a1ae29904..5fe7e27ee 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java @@ -696,6 +696,7 @@ public abstract class PlotArea { /** * Returns an ImmutableMap of PlotId's and Plots in this PlotArea. + * * @deprecated Use {@link #getPlotsMap()} */ //todo eventually remove diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotPlayer.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotPlayer.java index d535c625e..b8ad261ee 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotPlayer.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotPlayer.java @@ -168,11 +168,11 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer { return Integer.MAX_VALUE; } String[] nodes = stub.split("\\."); - StringBuilder n = new StringBuilder(); + StringBuilder builder = new StringBuilder(); for (int i = 0; i < (nodes.length - 1); i++) { - n.append(nodes[i]).append("."); - if (!stub.equals(n + C.PERMISSION_STAR.s())) { - if (hasPermission(n + C.PERMISSION_STAR.s())) { + builder.append(nodes[i]).append("."); + if (!stub.equals(builder + C.PERMISSION_STAR.s())) { + if (hasPermission(builder + C.PERMISSION_STAR.s())) { return Integer.MAX_VALUE; } } @@ -222,7 +222,6 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer { return getClusterCount(getLocation().getWorld()); } final AtomicInteger count = new AtomicInteger(0); - final UUID uuid = getUUID(); PlotSquared.get().foreachPlotArea(new RunnableVal() { @Override public void run(PlotArea value) { for (PlotCluster cluster : value.getClusters()) { @@ -510,14 +509,9 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer { * @return */ public int getPlayerClusterCount(String world) { - UUID uuid = getUUID(); - int count = 0; - for (PlotCluster cluster : PlotSquared.get().getClusters(world)) { - if (uuid.equals(cluster.owner)) { - count += cluster.getArea(); - } - } - return count; + return PlotSquared.get().getClusters(world).stream() + .filter(cluster -> getUUID().equals(cluster.owner)).mapToInt(PlotCluster::getArea) + .sum(); } /** @@ -580,31 +574,27 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer { final Location loc = new Location(plot.getWorldName(), x, y, z); if (plot.isLoaded()) { - TaskManager.runTask(new Runnable() { - @Override public void run() { - if (getMeta("teleportOnLogin", true)) { - teleport(loc); - sendMessage(C.TELEPORTED_TO_PLOT.f() - + " (quitLoc) (" + plotX + "," - + plotZ + ")"); - } + TaskManager.runTask(() -> { + if (getMeta("teleportOnLogin", true)) { + teleport(loc); + sendMessage(C.TELEPORTED_TO_PLOT.f() + + " (quitLoc) (" + plotX + "," + + plotZ + ")"); } }); } else if (!PlotSquared.get() .isMainThread(Thread.currentThread())) { if (getMeta("teleportOnLogin", true)) { if (plot.teleportPlayer(PlotPlayer.this)) { - TaskManager.runTask(new Runnable() { - @Override public void run() { - if (getMeta("teleportOnLogin", - true)) { - teleport(loc); - sendMessage( - C.TELEPORTED_TO_PLOT.f() - + " (quitLoc-unloaded) (" - + plotX + "," - + plotZ + ")"); - } + TaskManager.runTask(() -> { + if (getMeta("teleportOnLogin", + true)) { + teleport(loc); + sendMessage( + C.TELEPORTED_TO_PLOT.f() + + " (quitLoc-unloaded) (" + + plotX + "," + plotZ + + ")"); } }); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotSettings.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotSettings.java index f6c479471..86b41dc45 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotSettings.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotSettings.java @@ -6,6 +6,7 @@ import com.github.intellectualsites.plotsquared.plot.object.comment.PlotComment; import com.google.common.collect.ImmutableList; import java.util.*; +import java.util.stream.IntStream; /** * Generic settings class. @@ -63,7 +64,7 @@ public class PlotSettings { * Returns true if the plot is merged (i.e. if it's a mega plot) */ public boolean isMerged() { - return this.merged[0] || this.merged[1] || this.merged[2] || this.merged[3]; + return IntStream.of(0, 1, 2, 3).anyMatch(i -> this.merged[i]); } public boolean[] getMerged() { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/DefaultPlotAreaManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/DefaultPlotAreaManager.java index 989948f0c..0c2fea165 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/DefaultPlotAreaManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/DefaultPlotAreaManager.java @@ -10,7 +10,7 @@ import java.util.*; public class DefaultPlotAreaManager implements PlotAreaManager { - protected final PlotArea[] noPlotAreas = new PlotArea[0]; + final PlotArea[] noPlotAreas = new PlotArea[0]; // All plot areas mapped by world private final HashMap plotAreaMap = new HashMap<>(); // All plot areas mapped by position diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/ChunkManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/ChunkManager.java index e863e1302..380565b17 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/ChunkManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/ChunkManager.java @@ -239,20 +239,18 @@ public abstract class ChunkManager { public void deleteRegionFiles(final String world, final Collection chunks, final Runnable whenDone) { - TaskManager.runTaskAsync(new Runnable() { - @Override public void run() { - for (ChunkLoc loc : chunks) { - String directory = - world + File.separator + "region" + File.separator + "r." + loc.x + "." - + loc.z + ".mca"; - File file = new File(PlotSquared.get().IMP.getWorldContainer(), directory); - PlotSquared.log("&6 - Deleting file: " + file.getName() + " (max 1024 chunks)"); - if (file.exists()) { - file.delete(); - } + TaskManager.runTaskAsync(() -> { + for (ChunkLoc loc : chunks) { + String directory = + world + File.separator + "region" + File.separator + "r." + loc.x + "." + + loc.z + ".mca"; + File file = new File(PlotSquared.get().IMP.getWorldContainer(), directory); + PlotSquared.log("&6 - Deleting file: " + file.getName() + " (max 1024 chunks)"); + if (file.exists()) { + file.delete(); } - TaskManager.runTask(whenDone); } + TaskManager.runTask(whenDone); }); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/UUIDHandlerImplementation.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/UUIDHandlerImplementation.java index b5fbb8b65..347bc48e6 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/UUIDHandlerImplementation.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/UUIDHandlerImplementation.java @@ -15,12 +15,12 @@ import java.util.concurrent.ConcurrentHashMap; public abstract class UUIDHandlerImplementation { - public final ConcurrentHashMap players; + private final ConcurrentHashMap players; public final HashSet unknown = new HashSet<>(); - public UUIDWrapper uuidWrapper; + protected UUIDWrapper uuidWrapper; private boolean cached = false; private BiMap uuidMap = - HashBiMap.create(new HashMap()); + HashBiMap.create(new HashMap<>()); // private BiMap nameMap = uuidMap.inverse(); public UUIDHandlerImplementation(UUIDWrapper wrapper) { @@ -106,51 +106,47 @@ public abstract class UUIDHandlerImplementation { * PlotMe conversion */ if (!Settings.UUID.OFFLINE && !this.unknown.isEmpty()) { - TaskManager.runTaskAsync(new Runnable() { - @Override public void run() { - UUID offline = UUID.nameUUIDFromBytes( - ("OfflinePlayer:" + name.value).getBytes(Charsets.UTF_8)); - if (!UUIDHandlerImplementation.this.unknown.contains(offline) && !name.value - .equals(name.value.toLowerCase())) { - offline = UUID.nameUUIDFromBytes( - ("OfflinePlayer:" + name.value.toLowerCase()).getBytes(Charsets.UTF_8)); - if (!UUIDHandlerImplementation.this.unknown.contains(offline)) { - offline = null; - } + TaskManager.runTaskAsync(() -> { + UUID offline = UUID.nameUUIDFromBytes( + ("OfflinePlayer:" + name.value).getBytes(Charsets.UTF_8)); + if (!UUIDHandlerImplementation.this.unknown.contains(offline) && !name.value + .equals(name.value.toLowerCase())) { + offline = UUID.nameUUIDFromBytes( + ("OfflinePlayer:" + name.value.toLowerCase()).getBytes(Charsets.UTF_8)); + if (!UUIDHandlerImplementation.this.unknown.contains(offline)) { + offline = null; } - if (offline != null && !offline.equals(uuid)) { - UUIDHandlerImplementation.this.unknown.remove(offline); - Set plots = PlotSquared.get().getPlotsAbs(offline); - if (!plots.isEmpty()) { - for (Plot plot : plots) { - plot.owner = uuid; - } - DBFunc.replaceUUID(offline, uuid); - PlotSquared.debug("&cDetected invalid UUID stored for: " + name.value); - PlotSquared.debug( - "&7 - Did you recently switch to online-mode storage without running `uuidconvert`?"); - PlotSquared.debug("&6" + PlotSquared.imp().getPluginName() - + " will update incorrect entries when the user logs in, or you can reconstruct your database."); + } + if (offline != null && !offline.equals(uuid)) { + UUIDHandlerImplementation.this.unknown.remove(offline); + Set plots = PlotSquared.get().getPlotsAbs(offline); + if (!plots.isEmpty()) { + for (Plot plot : plots) { + plot.owner = uuid; } + DBFunc.replaceUUID(offline, uuid); + PlotSquared.debug("&cDetected invalid UUID stored for: " + name.value); + PlotSquared.debug( + "&7 - Did you recently switch to online-mode storage without running `uuidconvert`?"); + PlotSquared.debug("&6" + PlotSquared.imp().getPluginName() + + " will update incorrect entries when the user logs in, or you can reconstruct your database."); } } }); } else if (Settings.UUID.FORCE_LOWERCASE && !this.unknown.isEmpty() && !name.value .equals(name.value.toLowerCase())) { - TaskManager.runTaskAsync(new Runnable() { - @Override public void run() { - UUID offlineUpper = UUID.nameUUIDFromBytes( - ("OfflinePlayer:" + name.value).getBytes(Charsets.UTF_8)); - if (UUIDHandlerImplementation.this.unknown.contains(offlineUpper) - && !offlineUpper.equals(uuid)) { - UUIDHandlerImplementation.this.unknown.remove(offlineUpper); - Set plots = PlotSquared.get().getPlotsAbs(offlineUpper); - if (!plots.isEmpty()) { - for (Plot plot : plots) { - plot.owner = uuid; - } - replace(offlineUpper, uuid, name.value); + TaskManager.runTaskAsync(() -> { + UUID offlineUpper = UUID.nameUUIDFromBytes( + ("OfflinePlayer:" + name.value).getBytes(Charsets.UTF_8)); + if (UUIDHandlerImplementation.this.unknown.contains(offlineUpper) + && !offlineUpper.equals(uuid)) { + UUIDHandlerImplementation.this.unknown.remove(offlineUpper); + Set plots = PlotSquared.get().getPlotsAbs(offlineUpper); + if (!plots.isEmpty()) { + for (Plot plot : plots) { + plot.owner = uuid; } + replace(offlineUpper, uuid, name.value); } } }); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/expiry/ExpiryTask.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/expiry/ExpiryTask.java index df1244a12..dbf9d9fa9 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/expiry/ExpiryTask.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/expiry/ExpiryTask.java @@ -11,6 +11,7 @@ import java.util.Collections; import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; public class ExpiryTask { private final Settings.Auto_Clear settings; @@ -47,10 +48,9 @@ public class ExpiryTask { min = false; diff = settings.REQUIRED_PLOTS - plots.size(); } - List entireList = new ArrayList<>(); - for (Plot plot : plots) { - entireList.add(ExpireManager.IMP.getAge(plot)); - } + List entireList = + plots.stream().map(plot -> ExpireManager.IMP.getAge(plot)) + .collect(Collectors.toList()); List top = new ArrayList<>(diff + 1); if (diff > 1000) { Collections.sort(entireList);