mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 21:26:45 +01:00
Cleaning and scope changes
Signed-off-by: matt <4009945+MattBDev@users.noreply.github.com>
This commit is contained in:
parent
b39ea1b68b
commit
e891873d28
@ -1,6 +1,6 @@
|
||||
package com.github.intellectualsites.plotsquared.plot;
|
||||
|
||||
public enum Platform {
|
||||
Bukkit, Sponge, Spigot, Cauldron
|
||||
Bukkit, Sponge, Spigot
|
||||
|
||||
}
|
||||
|
@ -165,8 +165,7 @@ public class ListCmd extends SubCommand {
|
||||
plots.add(plot);
|
||||
}
|
||||
}
|
||||
Collections.sort(plots, new Comparator<Plot>() {
|
||||
@Override public int compare(Plot a, Plot b) {
|
||||
plots.sort((a, b) -> {
|
||||
String va = "" + a.getFlags().get(Flags.DONE);
|
||||
String vb = "" + b.getFlags().get(Flags.DONE);
|
||||
if (MathMan.isInteger(va)) {
|
||||
@ -176,7 +175,6 @@ public class ListCmd extends SubCommand {
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
sort = false;
|
||||
break;
|
||||
@ -186,16 +184,14 @@ 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) {
|
||||
plots.sort((p1, 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 = p1.getRatings().entrySet().stream()
|
||||
.mapToDouble(entry -> entry.getValue().getAverageRating())
|
||||
.map(av -> av * av).sum();
|
||||
v1 /= p1s;
|
||||
v1 += p1s;
|
||||
}
|
||||
@ -212,7 +208,6 @@ public class ListCmd extends SubCommand {
|
||||
return p2s - p1s;
|
||||
}
|
||||
return (int) Math.signum(v2 - v1);
|
||||
}
|
||||
});
|
||||
sort = false;
|
||||
break;
|
||||
|
@ -22,8 +22,7 @@ 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) {
|
||||
plots.sort((p1, p2) -> {
|
||||
double v1 = 0;
|
||||
if (!p1.getRatings().isEmpty()) {
|
||||
for (Entry<UUID, Rating> entry : p1.getRatings().entrySet()) {
|
||||
@ -40,7 +39,6 @@ import java.util.Map.Entry;
|
||||
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() {
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
plot.getSettings().ratings = DBFunc.getRatings(plot);
|
||||
run.run();
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
@ -167,8 +163,7 @@ import java.util.Map.Entry;
|
||||
return false;
|
||||
}
|
||||
final UUID uuid = player.getUUID();
|
||||
final Runnable run = new Runnable() {
|
||||
@Override public void run() {
|
||||
final Runnable run = () -> {
|
||||
if (plot.getRatings().containsKey(uuid)) {
|
||||
sendMessage(player, C.RATING_ALREADY_EXISTS, plot.getId().toString());
|
||||
return;
|
||||
@ -178,15 +173,12 @@ import java.util.Map.Entry;
|
||||
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() {
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
plot.getSettings().ratings = DBFunc.getRatings(plot);
|
||||
run.run();
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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() {
|
||||
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() {
|
||||
TaskManager.runTask(() -> {
|
||||
if (getMeta("teleportOnLogin",
|
||||
true)) {
|
||||
teleport(loc);
|
||||
sendMessage(
|
||||
C.TELEPORTED_TO_PLOT.f()
|
||||
+ " (quitLoc-unloaded) ("
|
||||
+ plotX + ","
|
||||
+ plotZ + ")");
|
||||
}
|
||||
+ plotX + "," + plotZ
|
||||
+ ")");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -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
|
||||
|
@ -239,8 +239,7 @@ 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() {
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
for (ChunkLoc loc : chunks) {
|
||||
String directory =
|
||||
world + File.separator + "region" + File.separator + "r." + loc.x + "."
|
||||
@ -252,7 +251,6 @@ public abstract class ChunkManager {
|
||||
}
|
||||
}
|
||||
TaskManager.runTask(whenDone);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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,8 +106,7 @@ public abstract class UUIDHandlerImplementation {
|
||||
* PlotMe conversion
|
||||
*/
|
||||
if (!Settings.UUID.OFFLINE && !this.unknown.isEmpty()) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override public void run() {
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
UUID offline = UUID.nameUUIDFromBytes(
|
||||
("OfflinePlayer:" + name.value).getBytes(Charsets.UTF_8));
|
||||
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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
} else if (Settings.UUID.FORCE_LOWERCASE && !this.unknown.isEmpty() && !name.value
|
||||
.equals(name.value.toLowerCase())) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override public void run() {
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
UUID offlineUpper = UUID.nameUUIDFromBytes(
|
||||
("OfflinePlayer:" + name.value).getBytes(Charsets.UTF_8));
|
||||
if (UUIDHandlerImplementation.this.unknown.contains(offlineUpper)
|
||||
@ -152,7 +149,6 @@ public abstract class UUIDHandlerImplementation {
|
||||
replace(offlineUpper, uuid, name.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
try {
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user