Signed-off-by: matt <4009945+MattBDev@users.noreply.github.com>
This commit is contained in:
matt
2019-02-13 12:05:28 -05:00
parent d0994f1b4b
commit 35493662da
37 changed files with 239 additions and 393 deletions

View File

@ -114,12 +114,7 @@ public abstract class Command {
public List<Command> getCommands(CommandCategory cat, PlotPlayer player) {
List<Command> commands = getCommands(player);
if (cat != null) {
Iterator<Command> iterator = commands.iterator();
while (iterator.hasNext()) {
if (iterator.next().category != cat) {
iterator.remove();
}
}
commands.removeIf(command -> command.category != cat);
}
return commands;
}
@ -306,11 +301,8 @@ public abstract class Command {
.sendMessage(player, C.DID_YOU_MEAN, MainCommand.getInstance().help.getUsage());
return;
}
HashSet<String> setargs = new HashSet<>(args.length);
for (String arg : args) {
setargs.add(arg.toLowerCase());
}
String[] allargs = setargs.toArray(new String[setargs.size()]);
String[] allargs =
Arrays.stream(args).map(String::toLowerCase).distinct().toArray(String[]::new);
int best = 0;
for (Command current : commands) {
int match = getMatch(allargs, current);
@ -360,14 +352,10 @@ public abstract class Command {
}
public int getMatch(String[] args, Command cmd) {
int count = 0;
String perm = cmd.getPermission();
HashSet<String> desc = new HashSet<>();
for (String alias : cmd.getAliases()) {
if (alias.startsWith(args[0])) {
count += 5;
}
}
int count = cmd.getAliases().stream().filter(alias -> alias.startsWith(args[0]))
.mapToInt(alias -> 5).sum();
Collections.addAll(desc, cmd.getDescription().split(" "));
for (String arg : args) {
if (perm.startsWith(arg)) {

View File

@ -6,6 +6,7 @@ import com.github.intellectualsites.plotsquared.configuration.MemoryConfiguratio
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.stream.Collectors;
/**
* This is a base class for all File based implementations of {@link
@ -103,20 +104,16 @@ public abstract class FileConfiguration extends MemoryConfiguration {
*/
public void load(Reader reader) throws IOException, InvalidConfigurationException {
StringBuilder builder = new StringBuilder();
String builder;
try (BufferedReader input = reader instanceof BufferedReader ?
(BufferedReader) reader :
new BufferedReader(reader)) {
String line;
while ((line = input.readLine()) != null) {
builder.append(line);
builder.append('\n');
}
builder = input.lines().map(line -> line + '\n').collect(Collectors.joining());
}
loadFromString(builder.toString());
loadFromString(builder);
}
/**

View File

@ -9,6 +9,7 @@ import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.*;
import java.util.Map.Entry;
import java.util.stream.IntStream;
/**
* A JSONObject is an unordered collection of name/value pairs. Its external form is a string wrapped in curly braces
@ -296,11 +297,7 @@ public class JSONObject {
if (length == 0) {
return null;
}
String[] names = new String[length];
for (int i = 0; i < length; i += 1) {
names[i] = fields[i].getName();
}
return names;
return IntStream.range(0, length).mapToObj(i -> fields[i].getName()).toArray(String[]::new);
}
/**

View File

@ -1305,12 +1305,9 @@ import java.util.zip.ZipInputStream;
"w=", "wall=", "b=", "border=");
// Calculate the number of expected arguments
int expected = 0;
for (final String validArgument : validArguments) {
if (args.toLowerCase(Locale.ENGLISH).contains(validArgument)) {
expected += 1;
}
}
int expected = (int) validArguments.stream()
.filter(validArgument -> args.toLowerCase(Locale.ENGLISH).contains(validArgument))
.count();
String[] split = args.toLowerCase(Locale.ENGLISH).split(",");

View File

@ -127,11 +127,8 @@ public class Auto extends SubCommand {
}
whenDone.value = plot;
plot.owner = player.getUUID();
DBFunc.createPlotSafe(plot, whenDone, new Runnable() {
@Override public void run() {
autoClaimFromDatabase(player, area, plot.getId(), whenDone);
}
});
DBFunc.createPlotSafe(plot, whenDone,
() -> autoClaimFromDatabase(player, area, plot.getId(), whenDone));
}
@Override public boolean onCommand(final PlotPlayer player, String[] args) {

View File

@ -18,11 +18,8 @@ import java.util.HashSet;
import java.util.Map.Entry;
import java.util.UUID;
@CommandDeclaration(
usage = "/plot purge world:<world> area:<area> id:<id> owner:<owner> shared:<shared> unknown:[true|false]",
command = "purge", permission = "plots.admin", description = "Purge all plots for a world",
category = CommandCategory.ADMINISTRATION, requiredType = RequiredType.CONSOLE,
confirmation = true) public class Purge extends SubCommand {
@CommandDeclaration(usage = "/plot purge world:<world> area:<area> id:<id> owner:<owner> shared:<shared> unknown:[true|false]", command = "purge", permission = "plots.admin", description = "Purge all plots for a world", category = CommandCategory.ADMINISTRATION, requiredType = RequiredType.CONSOLE, confirmation = true)
public class Purge extends SubCommand {
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
if (args.length == 0) {
@ -109,9 +106,7 @@ import java.util.UUID;
if (unknown && UUIDHandler.getName(plot.owner) != null) {
continue;
}
for (Plot current : plot.getConnectedPlots()) {
toDelete.add(current);
}
toDelete.addAll(plot.getConnectedPlots());
}
if (PlotSquared.get().plots_tmp != null) {
for (Entry<String, HashMap<PlotId, Plot>> entry : PlotSquared.get().plots_tmp
@ -144,23 +139,21 @@ import java.util.UUID;
}
String cmd =
"/plot purge " + StringMan.join(args, " ") + " (" + toDelete.size() + " plots)";
Runnable run = new Runnable() {
@Override public void run() {
PlotSquared.debug("Calculating plots to purge, please wait...");
HashSet<Integer> ids = new HashSet<>();
for (Plot plot : toDelete) {
if (plot.temp != Integer.MAX_VALUE) {
ids.add(plot.temp);
plot.getArea().removePlot(plot.getId());
for (PlotPlayer pp : plot.getPlayersInPlot()) {
PlotListener.plotEntry(pp, plot);
}
plot.removeSign();
Runnable run = () -> {
PlotSquared.debug("Calculating plots to purge, please wait...");
HashSet<Integer> ids = new HashSet<>();
for (Plot plot : toDelete) {
if (plot.temp != Integer.MAX_VALUE) {
ids.add(plot.temp);
plot.getArea().removePlot(plot.getId());
for (PlotPlayer pp : plot.getPlayersInPlot()) {
PlotListener.plotEntry(pp, plot);
}
plot.removeSign();
}
DBFunc.purgeIds(ids);
C.PURGE_SUCCESS.send(player, ids.size() + "/" + toDelete.size());
}
DBFunc.purgeIds(ids);
C.PURGE_SUCCESS.send(player, ids.size() + "/" + toDelete.size());
};
if (hasConfirmation(player)) {
CmdConfirm.addPending(player, cmd, run);

View File

@ -4,6 +4,8 @@ import com.github.intellectualsites.plotsquared.plot.util.StringMan;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public abstract class StmtMod<T> {
@ -19,12 +21,9 @@ public abstract class StmtMod<T> {
}
public String getCreateSQLite(int size, String query, int params) {
StringBuilder statement = new StringBuilder(query);
String modParams = StringMan.repeat(",?", params).substring(1);
for (int i = 0; i < size - 1; i++) {
statement.append("UNION SELECT ").append(modParams).append(' ');
}
return statement.toString();
return IntStream.range(0, size - 1).mapToObj(i -> "UNION SELECT " + modParams + ' ')
.collect(Collectors.joining("", query, ""));
}
public abstract String getCreateSQLite(int size);

View File

@ -97,13 +97,8 @@ public abstract class HybridUtils {
for (int x = x1; x <= x2; x++) {
for (int z = z1; z <= z2; z++) {
PlotBlock block = queue.getBlock(x, y, z);
boolean same = false;
for (PlotBlock p : blocks) {
if (WorldUtil.IMP.isBlockSame(block, p)) {
same = true;
break;
}
}
boolean same =
Arrays.stream(blocks).anyMatch(p -> WorldUtil.IMP.isBlockSame(block, p));
if (!same) {
count++;
}

View File

@ -31,6 +31,7 @@ import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
/**
* The plot class<br>
@ -2166,11 +2167,9 @@ public class Plot {
return false;
}
HashSet<Plot> visited = new HashSet<>();
HashSet<PlotId> merged = new HashSet<>();
HashSet<PlotId> merged;
Set<Plot> connected = this.getConnectedPlots();
for (Plot current : connected) {
merged.add(current.getId());
}
merged = connected.stream().map(Plot::getId).collect(Collectors.toCollection(HashSet::new));
ArrayDeque<Plot> frontier = new ArrayDeque<>(connected);
Plot current;
boolean toReturn = false;
@ -2554,9 +2553,7 @@ public class Plot {
}
Location gtopabs = this.area.getPlotAbs(top).getTopAbs();
Location gbotabs = this.area.getPlotAbs(bot).getBottomAbs();
for (PlotId id : MainUtil.getPlotSelectionIds(bot, top)) {
visited.add(id);
}
visited.addAll(MainUtil.getPlotSelectionIds(bot, top));
for (int x = bot.x; x <= top.x; x++) {
Plot plot = this.area.getPlotAbs(new PlotId(x, top.y));
if (plot.getMerged(2)) {

View File

@ -542,13 +542,8 @@ public abstract class PlotArea {
public int getPlotCount(@Nonnull final UUID uuid) {
if (!Settings.Done.COUNTS_TOWARDS_LIMIT) {
int count = 0;
for (Plot plot : getPlotsAbs(uuid)) {
if (!plot.hasFlag(Flags.DONE)) {
count++;
}
}
return count;
return (int) getPlotsAbs(uuid).stream().filter(plot -> !plot.hasFlag(Flags.DONE))
.count();
}
return getPlotsAbs(uuid).size();
}
@ -563,11 +558,7 @@ public abstract class PlotArea {
}
public boolean hasPlot(@Nonnull final UUID uuid) {
for (Entry<PlotId, Plot> entry : this.plots.entrySet()) {
if (entry.getValue().isOwner(uuid))
return true;
}
return false;
return this.plots.entrySet().stream().anyMatch(entry -> entry.getValue().isOwner(uuid));
}
public int getPlotCount(@Nullable final PlotPlayer player) {

View File

@ -18,6 +18,7 @@ import java.nio.ByteBuffer;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
/**
* The abstract class supporting {@code BukkitPlayer} and {@code SpongePlayer}.
@ -245,11 +246,8 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
int count = 0;
for (PlotArea area : PlotSquared.get().getPlotAreas(world)) {
if (!Settings.Done.COUNTS_TOWARDS_LIMIT) {
for (Plot plot : area.getPlotsAbs(uuid)) {
if (!plot.getFlag(Flags.DONE).isPresent()) {
count++;
}
}
count += area.getPlotsAbs(uuid).stream()
.filter(plot -> !plot.getFlag(Flags.DONE).isPresent()).count();
} else {
count += area.getPlotsAbs(uuid).size();
}
@ -537,13 +535,8 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
*/
public Set<Plot> getPlots(String world) {
UUID uuid = getUUID();
HashSet<Plot> plots = new HashSet<>();
for (Plot plot : PlotSquared.get().getPlots(world)) {
if (plot.isOwner(uuid)) {
plots.add(plot);
}
}
return plots;
return PlotSquared.get().getPlots(world).stream().filter(plot -> plot.isOwner(uuid))
.collect(Collectors.toCollection(HashSet::new));
}
public void populatePersistentMetaMap() {

View File

@ -6,6 +6,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.stream.IntStream;
public class Rating {
/**
@ -43,10 +44,7 @@ public class Rating {
}
public double getAverageRating() {
double total = 0;
for (Entry<String, Integer> entry : this.ratingMap.entrySet()) {
total += entry.getValue();
}
double total = this.ratingMap.entrySet().stream().mapToDouble(Entry::getValue).sum();
return total / this.ratingMap.size();
}
@ -67,12 +65,9 @@ public class Rating {
return this.initial;
}
if (Settings.Ratings.CATEGORIES != null && Settings.Ratings.CATEGORIES.size() > 1) {
int val = 0;
for (int i = 0; i < Settings.Ratings.CATEGORIES.size(); i++) {
val +=
(i + 1) * Math.pow(10, this.ratingMap.get(Settings.Ratings.CATEGORIES.get(i)));
}
return val;
return IntStream.range(0, Settings.Ratings.CATEGORIES.size()).map(
i -> (int) ((i + 1) * Math
.pow(10, this.ratingMap.get(Settings.Ratings.CATEGORIES.get(i))))).sum();
} else {
return this.ratingMap.get(null);
}

View File

@ -88,9 +88,8 @@ public class DefaultPlotAreaManager implements PlotAreaManager {
HashSet<PlotArea> globalAreas = new HashSet<>(Arrays.asList(plotAreas));
localAreas.add(plotArea);
globalAreas.add(plotArea);
this.plotAreas = globalAreas.toArray(new PlotArea[globalAreas.size()]);
this.plotAreaMap
.put(plotArea.worldname, localAreas.toArray(new PlotArea[localAreas.size()]));
this.plotAreas = globalAreas.toArray(new PlotArea[0]);
this.plotAreaMap.put(plotArea.worldname, localAreas.toArray(new PlotArea[0]));
QuadMap<PlotArea> map = this.plotAreaGrid.get(plotArea.worldname);
if (map == null) {
map = new QuadMap<PlotArea>(Integer.MAX_VALUE, 0, 0) {
@ -104,15 +103,14 @@ public class DefaultPlotAreaManager implements PlotAreaManager {
}
@Override public void removePlotArea(PlotArea area) {
ArrayList<PlotArea> globalAreas = new ArrayList<PlotArea>(Arrays.asList(plotAreas));
ArrayList<PlotArea> globalAreas = new ArrayList<>(Arrays.asList(plotAreas));
globalAreas.remove(area);
this.plotAreas = globalAreas.toArray(new PlotArea[globalAreas.size()]);
this.plotAreas = globalAreas.toArray(new PlotArea[0]);
if (globalAreas.isEmpty()) {
this.plotAreaMap.remove(area.worldname);
this.plotAreaGrid.remove(area.worldname);
} else {
this.plotAreaMap
.put(area.worldname, globalAreas.toArray(new PlotArea[globalAreas.size()]));
this.plotAreaMap.put(area.worldname, globalAreas.toArray(new PlotArea[0]));
this.plotAreaGrid.get(area.worldname).remove(area);
}
}
@ -206,7 +204,7 @@ public class DefaultPlotAreaManager implements PlotAreaManager {
return noPlotAreas;
} else {
Set<PlotArea> found = areas.get(region);
return found.toArray(new PlotArea[found.size()]);
return found.toArray(new PlotArea[0]);
}
}
@ -217,14 +215,14 @@ public class DefaultPlotAreaManager implements PlotAreaManager {
Set<String> tmp = new LinkedHashSet<>();
Collections.addAll(tmp, worlds);
tmp.add(worldName);
worlds = tmp.toArray(new String[tmp.size()]);
worlds = tmp.toArray(new String[0]);
}
@Override public void removeWorld(String worldName) {
Set<String> tmp = new LinkedHashSet<>();
Collections.addAll(tmp, worlds);
tmp.remove(worldName);
worlds = tmp.toArray(new String[tmp.size()]);
worlds = tmp.toArray(new String[0]);
}
@Override public String[] getAllWorlds() {

View File

@ -5,24 +5,24 @@ import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
import com.github.intellectualsites.plotsquared.plot.object.RegionWrapper;
public interface PlotAreaManager {
public PlotArea getApplicablePlotArea(Location location);
PlotArea getApplicablePlotArea(Location location);
public PlotArea getPlotArea(Location location);
PlotArea getPlotArea(Location location);
public PlotArea getPlotArea(String world, String id);
PlotArea getPlotArea(String world, String id);
public PlotArea[] getPlotAreas(String world, RegionWrapper region);
PlotArea[] getPlotAreas(String world, RegionWrapper region);
public PlotArea[] getAllPlotAreas();
PlotArea[] getAllPlotAreas();
public String[] getAllWorlds();
String[] getAllWorlds();
public void addPlotArea(PlotArea area);
void addPlotArea(PlotArea area);
public void removePlotArea(PlotArea area);
void removePlotArea(PlotArea area);
public void addWorld(String worldName);
void addWorld(String worldName);
public void removeWorld(String worldName);
void removeWorld(String worldName);
}

View File

@ -76,11 +76,8 @@ import java.util.Map;
}
private PlotBlock[] splitBlockList(@NonNull final List<String> list) {
final PlotBlock[] entries = new PlotBlock[list.size()];
for (int i = 0; i < list.size(); i++) {
entries[i] = WorldUtil.IMP.getClosestBlock(list.get(i)).best;
}
return entries;
return list.stream().map(s -> WorldUtil.IMP.getClosestBlock(s).best)
.toArray(PlotBlock[]::new);
}
private void convertBlock(@NonNull final ConfigurationSection section,

View File

@ -825,11 +825,8 @@ public class MainUtil {
if (l.size() < 1) {
return C.NONE.s();
}
List<String> users = new ArrayList<>();
for (UUID u : l) {
users.add(getName(u));
}
Collections.sort(users);
List<String> users =
l.stream().map(MainUtil::getName).sorted().collect(Collectors.toList());
String c = C.PLOT_USER_LIST.s();
StringBuilder list = new StringBuilder();
for (int x = 0; x < users.size(); x++) {

View File

@ -106,7 +106,7 @@ public class GlobalBlockQueue {
if (PARALLEL_THREADS <= 1) {
SET_TASK.run();
} else {
ArrayList<Thread> threads = new ArrayList<Thread>();
ArrayList<Thread> threads = new ArrayList<>();
for (int i = 0; i < PARALLEL_THREADS; i++) {
threads.add(new Thread(SET_TASK));
}
@ -168,7 +168,7 @@ public class GlobalBlockQueue {
public List<LocalBlockQueue> getAllQueues() {
ArrayList<LocalBlockQueue> list =
new ArrayList<LocalBlockQueue>(activeQueues.size() + inactiveQueues.size());
new ArrayList<>(activeQueues.size() + inactiveQueues.size());
list.addAll(inactiveQueues);
list.addAll(activeQueues);
return list;
@ -197,7 +197,7 @@ public class GlobalBlockQueue {
if (PARALLEL_THREADS <= 1) {
SET_TASK.run();
} else {
ArrayList<Thread> threads = new ArrayList<Thread>();
ArrayList<Thread> threads = new ArrayList<>();
for (int i = 0; i < PARALLEL_THREADS; i++) {
threads.add(new Thread(SET_TASK));
}

View File

@ -414,11 +414,7 @@ public class PlotAnalysis {
* @return
*/
public static int sum(int[] array) {
int sum = 0;
for (int value : array) {
sum += value;
}
return sum;
return Arrays.stream(array).sum();
}
/**