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,18 +165,16 @@ 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)) { if (MathMan.isInteger(vb)) {
if (MathMan.isInteger(vb)) { return Integer.parseInt(vb) - Integer.parseInt(va);
return Integer.parseInt(vb) - Integer.parseInt(va);
}
return -1;
} }
return 1; return -1;
} }
return 1;
}); });
sort = false; sort = false;
break; break;
@ -186,33 +184,30 @@ 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()) { v1 = p1.getRatings().entrySet().stream()
for (Entry<UUID, Rating> entry : p1.getRatings().entrySet()) { .mapToDouble(entry -> entry.getValue().getAverageRating())
double av = entry.getValue().getAverageRating(); .map(av -> av * av).sum();
v1 += av * av; v1 /= p1s;
} v1 += p1s;
v1 /= p1s;
v1 += p1s;
}
double v2 = 0;
if (!p2.getSettings().getRatings().isEmpty()) {
for (Entry<UUID, Rating> 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);
} }
double v2 = 0;
if (!p2.getSettings().getRatings().isEmpty()) {
for (Entry<UUID, Rating> 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; sort = false;
break; break;

View file

@ -22,25 +22,23 @@ 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()) { v1 -= 11 - entry.getValue().getAverageRating();
v1 -= 11 - entry.getValue().getAverageRating();
}
} }
double v2 = 0;
if (!p2.getRatings().isEmpty()) {
for (Entry<UUID, Rating> 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<UUID, Rating> entry : p2.getRatings().entrySet()) {
v2 -= 11 - entry.getValue().getAverageRating();
}
}
if (v1 == v2) {
return -0;
}
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,26 +163,22 @@ 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; }
} Rating result = EventUtil.manager.callRating(player, plot, new Rating(rating));
Rating result = EventUtil.manager.callRating(player, plot, new Rating(rating)); if (result != null) {
if (result != null) { 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 + "," + plotZ
+ plotX + "," + ")");
+ 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,20 +239,18 @@ 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 + "." + loc.z + ".mca";
+ loc.z + ".mca"; File file = new File(PlotSquared.get().IMP.getWorldContainer(), directory);
File file = new File(PlotSquared.get().IMP.getWorldContainer(), directory); PlotSquared.log("&6 - Deleting file: " + file.getName() + " (max 1024 chunks)");
PlotSquared.log("&6 - Deleting file: " + file.getName() + " (max 1024 chunks)"); if (file.exists()) {
if (file.exists()) { file.delete();
file.delete();
}
} }
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,51 +106,47 @@ 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 .equals(name.value.toLowerCase())) {
.equals(name.value.toLowerCase())) { offline = UUID.nameUUIDFromBytes(
offline = UUID.nameUUIDFromBytes( ("OfflinePlayer:" + name.value.toLowerCase()).getBytes(Charsets.UTF_8));
("OfflinePlayer:" + name.value.toLowerCase()).getBytes(Charsets.UTF_8)); if (!UUIDHandlerImplementation.this.unknown.contains(offline)) {
if (!UUIDHandlerImplementation.this.unknown.contains(offline)) { offline = null;
offline = null;
}
} }
if (offline != null && !offline.equals(uuid)) { }
UUIDHandlerImplementation.this.unknown.remove(offline); if (offline != null && !offline.equals(uuid)) {
Set<Plot> plots = PlotSquared.get().getPlotsAbs(offline); UUIDHandlerImplementation.this.unknown.remove(offline);
if (!plots.isEmpty()) { Set<Plot> plots = PlotSquared.get().getPlotsAbs(offline);
for (Plot plot : plots) { if (!plots.isEmpty()) {
plot.owner = uuid; 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.");
} }
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 } 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) && !offlineUpper.equals(uuid)) {
&& !offlineUpper.equals(uuid)) { UUIDHandlerImplementation.this.unknown.remove(offlineUpper);
UUIDHandlerImplementation.this.unknown.remove(offlineUpper); Set<Plot> plots = PlotSquared.get().getPlotsAbs(offlineUpper);
Set<Plot> plots = PlotSquared.get().getPlotsAbs(offlineUpper); if (!plots.isEmpty()) {
if (!plots.isEmpty()) { for (Plot plot : plots) {
for (Plot plot : plots) { plot.owner = uuid;
plot.owner = uuid;
}
replace(offlineUpper, uuid, name.value);
} }
replace(offlineUpper, uuid, name.value);
} }
} }
}); });

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);