Cleaning and scope changes

Signed-off-by: matt <4009945+MattBDev@users.noreply.github.com>
This commit is contained in:
matt 2019-02-08 11:21:53 -05:00
parent b39ea1b68b
commit e891873d28
12 changed files with 142 additions and 169 deletions

View File

@ -1,6 +1,6 @@
package com.github.intellectualsites.plotsquared.plot; package com.github.intellectualsites.plotsquared.plot;
public enum Platform { public enum Platform {
Bukkit, Sponge, Spigot, Cauldron Bukkit, Sponge, Spigot
} }

View File

@ -165,8 +165,7 @@ public class ListCmd extends SubCommand {
plots.add(plot); plots.add(plot);
} }
} }
Collections.sort(plots, new Comparator<Plot>() { plots.sort((a, b) -> {
@Override public int compare(Plot a, Plot b) {
String va = "" + a.getFlags().get(Flags.DONE); String va = "" + a.getFlags().get(Flags.DONE);
String vb = "" + b.getFlags().get(Flags.DONE); String vb = "" + b.getFlags().get(Flags.DONE);
if (MathMan.isInteger(va)) { if (MathMan.isInteger(va)) {
@ -176,7 +175,6 @@ public class ListCmd extends SubCommand {
return -1; return -1;
} }
return 1; return 1;
}
}); });
sort = false; sort = false;
break; break;
@ -186,16 +184,14 @@ public class ListCmd extends SubCommand {
return false; return false;
} }
plots = new ArrayList<>(PlotSquared.get().getPlots()); plots = new ArrayList<>(PlotSquared.get().getPlots());
Collections.sort(plots, new Comparator<Plot>() { plots.sort((p1, p2) -> {
@Override public int compare(Plot p1, Plot p2) {
double v1 = 0; double v1 = 0;
int p1s = p1.getSettings().getRatings().size(); int p1s = p1.getSettings().getRatings().size();
int p2s = p2.getRatings().size(); int p2s = p2.getRatings().size();
if (!p1.getSettings().getRatings().isEmpty()) { if (!p1.getSettings().getRatings().isEmpty()) {
for (Entry<UUID, Rating> entry : p1.getRatings().entrySet()) { v1 = p1.getRatings().entrySet().stream()
double av = entry.getValue().getAverageRating(); .mapToDouble(entry -> entry.getValue().getAverageRating())
v1 += av * av; .map(av -> av * av).sum();
}
v1 /= p1s; v1 /= p1s;
v1 += p1s; v1 += p1s;
} }
@ -212,7 +208,6 @@ public class ListCmd extends SubCommand {
return p2s - p1s; return p2s - p1s;
} }
return (int) Math.signum(v2 - v1); return (int) Math.signum(v2 - v1);
}
}); });
sort = false; sort = false;
break; break;

View File

@ -22,8 +22,7 @@ import java.util.Map.Entry;
switch (args[0].toLowerCase()) { switch (args[0].toLowerCase()) {
case "next": { case "next": {
ArrayList<Plot> plots = new ArrayList<>(PlotSquared.get().getBasePlots()); ArrayList<Plot> plots = new ArrayList<>(PlotSquared.get().getBasePlots());
Collections.sort(plots, new Comparator<Plot>() { plots.sort((p1, p2) -> {
@Override public int compare(Plot p1, Plot p2) {
double v1 = 0; double v1 = 0;
if (!p1.getRatings().isEmpty()) { if (!p1.getRatings().isEmpty()) {
for (Entry<UUID, Rating> entry : p1.getRatings().entrySet()) { for (Entry<UUID, Rating> entry : p1.getRatings().entrySet()) {
@ -40,7 +39,6 @@ import java.util.Map.Entry;
return -0; return -0;
} }
return v2 > v1 ? 1 : -1; return v2 > v1 ? 1 : -1;
}
}); });
UUID uuid = player.getUUID(); UUID uuid = player.getUUID();
for (Plot p : plots) { for (Plot p : plots) {
@ -137,11 +135,9 @@ import java.util.Map.Entry;
}; };
if (plot.getSettings().ratings == null) { if (plot.getSettings().ratings == null) {
if (!Settings.Enabled_Components.RATING_CACHE) { if (!Settings.Enabled_Components.RATING_CACHE) {
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(() -> {
@Override public void run() {
plot.getSettings().ratings = DBFunc.getRatings(plot); plot.getSettings().ratings = DBFunc.getRatings(plot);
run.run(); run.run();
}
}); });
return true; return true;
} }
@ -167,8 +163,7 @@ import java.util.Map.Entry;
return false; return false;
} }
final UUID uuid = player.getUUID(); final UUID uuid = player.getUUID();
final Runnable run = new Runnable() { final Runnable run = () -> {
@Override public void run() {
if (plot.getRatings().containsKey(uuid)) { if (plot.getRatings().containsKey(uuid)) {
sendMessage(player, C.RATING_ALREADY_EXISTS, plot.getId().toString()); sendMessage(player, C.RATING_ALREADY_EXISTS, plot.getId().toString());
return; return;
@ -178,15 +173,12 @@ import java.util.Map.Entry;
plot.addRating(uuid, result); plot.addRating(uuid, result);
sendMessage(player, C.RATING_APPLIED, plot.getId().toString()); sendMessage(player, C.RATING_APPLIED, plot.getId().toString());
} }
}
}; };
if (plot.getSettings().ratings == null) { if (plot.getSettings().ratings == null) {
if (!Settings.Enabled_Components.RATING_CACHE) { if (!Settings.Enabled_Components.RATING_CACHE) {
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(() -> {
@Override public void run() {
plot.getSettings().ratings = DBFunc.getRatings(plot); plot.getSettings().ratings = DBFunc.getRatings(plot);
run.run(); run.run();
}
}); });
return true; return true;
} }

View File

@ -45,7 +45,7 @@ public class MySQL extends Database {
return this.connection; return this.connection;
} }
@Override public Connection openConnection() throws SQLException, ClassNotFoundException { @Override public Connection openConnection() throws SQLException {
if (checkConnection()) { if (checkConnection()) {
return this.connection; return this.connection;
} }
@ -69,7 +69,7 @@ public class MySQL extends Database {
return true; return true;
} }
@Override public ResultSet querySQL(String query) throws SQLException, ClassNotFoundException { @Override public ResultSet querySQL(String query) throws SQLException {
if (checkConnection()) { if (checkConnection()) {
openConnection(); 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()) { if (checkConnection()) {
openConnection(); openConnection();
} }

View File

@ -2616,7 +2616,7 @@ import java.util.concurrent.atomic.AtomicInteger;
} catch (Exception ignored) { } catch (Exception ignored) {
} }
} }
Integer m = resultSet.getInt("merged"); int m = resultSet.getInt("merged");
boolean[] merged = new boolean[4]; boolean[] merged = new boolean[4];
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
merged[3 - i] = (m & 1 << i) != 0; merged[3 - i] = (m & 1 << i) != 0;

View File

@ -696,6 +696,7 @@ public abstract class PlotArea {
/** /**
* Returns an ImmutableMap of PlotId's and Plots in this PlotArea. * Returns an ImmutableMap of PlotId's and Plots in this PlotArea.
*
* @deprecated Use {@link #getPlotsMap()} * @deprecated Use {@link #getPlotsMap()}
*/ */
//todo eventually remove //todo eventually remove

View File

@ -168,11 +168,11 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
return Integer.MAX_VALUE; return Integer.MAX_VALUE;
} }
String[] nodes = stub.split("\\."); String[] nodes = stub.split("\\.");
StringBuilder n = new StringBuilder(); StringBuilder builder = new StringBuilder();
for (int i = 0; i < (nodes.length - 1); i++) { for (int i = 0; i < (nodes.length - 1); i++) {
n.append(nodes[i]).append("."); builder.append(nodes[i]).append(".");
if (!stub.equals(n + C.PERMISSION_STAR.s())) { if (!stub.equals(builder + C.PERMISSION_STAR.s())) {
if (hasPermission(n + C.PERMISSION_STAR.s())) { if (hasPermission(builder + C.PERMISSION_STAR.s())) {
return Integer.MAX_VALUE; return Integer.MAX_VALUE;
} }
} }
@ -222,7 +222,6 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
return getClusterCount(getLocation().getWorld()); return getClusterCount(getLocation().getWorld());
} }
final AtomicInteger count = new AtomicInteger(0); final AtomicInteger count = new AtomicInteger(0);
final UUID uuid = getUUID();
PlotSquared.get().foreachPlotArea(new RunnableVal<PlotArea>() { PlotSquared.get().foreachPlotArea(new RunnableVal<PlotArea>() {
@Override public void run(PlotArea value) { @Override public void run(PlotArea value) {
for (PlotCluster cluster : value.getClusters()) { for (PlotCluster cluster : value.getClusters()) {
@ -510,14 +509,9 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
* @return * @return
*/ */
public int getPlayerClusterCount(String world) { public int getPlayerClusterCount(String world) {
UUID uuid = getUUID(); return PlotSquared.get().getClusters(world).stream()
int count = 0; .filter(cluster -> getUUID().equals(cluster.owner)).mapToInt(PlotCluster::getArea)
for (PlotCluster cluster : PlotSquared.get().getClusters(world)) { .sum();
if (uuid.equals(cluster.owner)) {
count += cluster.getArea();
}
}
return count;
} }
/** /**
@ -580,31 +574,27 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
final Location loc = final Location loc =
new Location(plot.getWorldName(), x, y, z); new Location(plot.getWorldName(), x, y, z);
if (plot.isLoaded()) { if (plot.isLoaded()) {
TaskManager.runTask(new Runnable() { TaskManager.runTask(() -> {
@Override public void run() {
if (getMeta("teleportOnLogin", true)) { if (getMeta("teleportOnLogin", true)) {
teleport(loc); teleport(loc);
sendMessage(C.TELEPORTED_TO_PLOT.f() sendMessage(C.TELEPORTED_TO_PLOT.f()
+ " (quitLoc) (" + plotX + "," + " (quitLoc) (" + plotX + ","
+ plotZ + ")"); + plotZ + ")");
} }
}
}); });
} else if (!PlotSquared.get() } else if (!PlotSquared.get()
.isMainThread(Thread.currentThread())) { .isMainThread(Thread.currentThread())) {
if (getMeta("teleportOnLogin", true)) { if (getMeta("teleportOnLogin", true)) {
if (plot.teleportPlayer(PlotPlayer.this)) { if (plot.teleportPlayer(PlotPlayer.this)) {
TaskManager.runTask(new Runnable() { TaskManager.runTask(() -> {
@Override public void run() {
if (getMeta("teleportOnLogin", if (getMeta("teleportOnLogin",
true)) { true)) {
teleport(loc); teleport(loc);
sendMessage( sendMessage(
C.TELEPORTED_TO_PLOT.f() C.TELEPORTED_TO_PLOT.f()
+ " (quitLoc-unloaded) (" + " (quitLoc-unloaded) ("
+ plotX + "," + plotX + "," + plotZ
+ plotZ + ")"); + ")");
}
} }
}); });
} }

View File

@ -6,6 +6,7 @@ import com.github.intellectualsites.plotsquared.plot.object.comment.PlotComment;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import java.util.*; import java.util.*;
import java.util.stream.IntStream;
/** /**
* Generic settings class. * 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) * Returns true if the plot is merged (i.e. if it's a mega plot)
*/ */
public boolean isMerged() { 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() { public boolean[] getMerged() {

View File

@ -10,7 +10,7 @@ import java.util.*;
public class DefaultPlotAreaManager implements PlotAreaManager { public class DefaultPlotAreaManager implements PlotAreaManager {
protected final PlotArea[] noPlotAreas = new PlotArea[0]; final PlotArea[] noPlotAreas = new PlotArea[0];
// All plot areas mapped by world // All plot areas mapped by world
private final HashMap<String, PlotArea[]> plotAreaMap = new HashMap<>(); private final HashMap<String, PlotArea[]> plotAreaMap = new HashMap<>();
// All plot areas mapped by position // All plot areas mapped by position

View File

@ -239,8 +239,7 @@ public abstract class ChunkManager {
public void deleteRegionFiles(final String world, final Collection<ChunkLoc> chunks, public void deleteRegionFiles(final String world, final Collection<ChunkLoc> chunks,
final Runnable whenDone) { final Runnable whenDone) {
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(() -> {
@Override public void run() {
for (ChunkLoc loc : chunks) { for (ChunkLoc loc : chunks) {
String directory = String directory =
world + File.separator + "region" + File.separator + "r." + loc.x + "." world + File.separator + "region" + File.separator + "r." + loc.x + "."
@ -252,7 +251,6 @@ public abstract class ChunkManager {
} }
} }
TaskManager.runTask(whenDone); TaskManager.runTask(whenDone);
}
}); });
} }

View File

@ -15,12 +15,12 @@ import java.util.concurrent.ConcurrentHashMap;
public abstract class UUIDHandlerImplementation { public abstract class UUIDHandlerImplementation {
public final ConcurrentHashMap<String, PlotPlayer> players; private final ConcurrentHashMap<String, PlotPlayer> players;
public final HashSet<UUID> unknown = new HashSet<>(); public final HashSet<UUID> unknown = new HashSet<>();
public UUIDWrapper uuidWrapper; protected UUIDWrapper uuidWrapper;
private boolean cached = false; private boolean cached = false;
private BiMap<StringWrapper, UUID> uuidMap = private BiMap<StringWrapper, UUID> uuidMap =
HashBiMap.create(new HashMap<StringWrapper, UUID>()); HashBiMap.create(new HashMap<>());
// private BiMap<UUID, StringWrapper> nameMap = uuidMap.inverse(); // private BiMap<UUID, StringWrapper> nameMap = uuidMap.inverse();
public UUIDHandlerImplementation(UUIDWrapper wrapper) { public UUIDHandlerImplementation(UUIDWrapper wrapper) {
@ -106,8 +106,7 @@ public abstract class UUIDHandlerImplementation {
* PlotMe conversion * PlotMe conversion
*/ */
if (!Settings.UUID.OFFLINE && !this.unknown.isEmpty()) { if (!Settings.UUID.OFFLINE && !this.unknown.isEmpty()) {
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(() -> {
@Override public void run() {
UUID offline = UUID.nameUUIDFromBytes( UUID offline = UUID.nameUUIDFromBytes(
("OfflinePlayer:" + name.value).getBytes(Charsets.UTF_8)); ("OfflinePlayer:" + name.value).getBytes(Charsets.UTF_8));
if (!UUIDHandlerImplementation.this.unknown.contains(offline) && !name.value if (!UUIDHandlerImplementation.this.unknown.contains(offline) && !name.value
@ -133,12 +132,10 @@ public abstract class UUIDHandlerImplementation {
+ " will update incorrect entries when the user logs in, or you can reconstruct your database."); + " 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 } else if (Settings.UUID.FORCE_LOWERCASE && !this.unknown.isEmpty() && !name.value
.equals(name.value.toLowerCase())) { .equals(name.value.toLowerCase())) {
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(() -> {
@Override public void run() {
UUID offlineUpper = UUID.nameUUIDFromBytes( UUID offlineUpper = UUID.nameUUIDFromBytes(
("OfflinePlayer:" + name.value).getBytes(Charsets.UTF_8)); ("OfflinePlayer:" + name.value).getBytes(Charsets.UTF_8));
if (UUIDHandlerImplementation.this.unknown.contains(offlineUpper) if (UUIDHandlerImplementation.this.unknown.contains(offlineUpper)
@ -152,7 +149,6 @@ public abstract class UUIDHandlerImplementation {
replace(offlineUpper, uuid, name.value); replace(offlineUpper, uuid, name.value);
} }
} }
}
}); });
} }
try { try {

View File

@ -11,6 +11,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
public class ExpiryTask { public class ExpiryTask {
private final Settings.Auto_Clear settings; private final Settings.Auto_Clear settings;
@ -47,10 +48,9 @@ public class ExpiryTask {
min = false; min = false;
diff = settings.REQUIRED_PLOTS - plots.size(); diff = settings.REQUIRED_PLOTS - plots.size();
} }
List<Long> entireList = new ArrayList<>(); List<Long> entireList =
for (Plot plot : plots) { plots.stream().map(plot -> ExpireManager.IMP.getAge(plot))
entireList.add(ExpireManager.IMP.getAge(plot)); .collect(Collectors.toList());
}
List<Long> top = new ArrayList<>(diff + 1); List<Long> top = new ArrayList<>(diff + 1);
if (diff > 1000) { if (diff > 1000) {
Collections.sort(entireList); Collections.sort(entireList);