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;
public enum Platform {
Bukkit, Sponge, Spigot, Cauldron
Bukkit, Sponge, Spigot
}

View file

@ -165,18 +165,16 @@ public class ListCmd extends SubCommand {
plots.add(plot);
}
}
Collections.sort(plots, new Comparator<Plot>() {
@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<Plot>() {
@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<UUID, Rating> 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<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);
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<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;
break;

View file

@ -22,25 +22,23 @@ import java.util.Map.Entry;
switch (args[0].toLowerCase()) {
case "next": {
ArrayList<Plot> plots = new ArrayList<>(PlotSquared.get().getBasePlots());
Collections.sort(plots, new Comparator<Plot>() {
@Override public int compare(Plot p1, Plot p2) {
double v1 = 0;
if (!p1.getRatings().isEmpty()) {
for (Entry<UUID, Rating> entry : p1.getRatings().entrySet()) {
v1 -= 11 - entry.getValue().getAverageRating();
}
plots.sort((p1, p2) -> {
double v1 = 0;
if (!p1.getRatings().isEmpty()) {
for (Entry<UUID, Rating> entry : p1.getRatings().entrySet()) {
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();
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;
}

View file

@ -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();
}

View file

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

View file

@ -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

View file

@ -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<PlotArea>() {
@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
+ ")");
}
});
}

View file

@ -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() {

View file

@ -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<String, PlotArea[]> plotAreaMap = new HashMap<>();
// 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,
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);
});
}

View file

@ -15,12 +15,12 @@ import java.util.concurrent.ConcurrentHashMap;
public abstract class UUIDHandlerImplementation {
public final ConcurrentHashMap<String, PlotPlayer> players;
private final ConcurrentHashMap<String, PlotPlayer> players;
public final HashSet<UUID> unknown = new HashSet<>();
public UUIDWrapper uuidWrapper;
protected UUIDWrapper uuidWrapper;
private boolean cached = false;
private BiMap<StringWrapper, UUID> uuidMap =
HashBiMap.create(new HashMap<StringWrapper, UUID>());
HashBiMap.create(new HashMap<>());
// private BiMap<UUID, StringWrapper> 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<Plot> 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<Plot> 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<Plot> 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<Plot> plots = PlotSquared.get().getPlotsAbs(offlineUpper);
if (!plots.isEmpty()) {
for (Plot plot : plots) {
plot.owner = uuid;
}
replace(offlineUpper, uuid, name.value);
}
}
});

View file

@ -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<Long> entireList = new ArrayList<>();
for (Plot plot : plots) {
entireList.add(ExpireManager.IMP.getAge(plot));
}
List<Long> entireList =
plots.stream().map(plot -> ExpireManager.IMP.getAge(plot))
.collect(Collectors.toList());
List<Long> top = new ArrayList<>(diff + 1);
if (diff > 1000) {
Collections.sort(entireList);