mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 13:16:45 +01:00
Make PlotQuery iterable
This commit is contained in:
parent
e80ade65c7
commit
39fdaa367c
@ -454,7 +454,7 @@ public class Cluster extends SubCommand {
|
||||
cluster.getName());
|
||||
}
|
||||
for (final Plot plot : PlotQuery.newQuery().inWorld(player2.getLocation()
|
||||
.getWorldName()).ownedBy(uuid).asCollection()) {
|
||||
.getWorldName()).ownedBy(uuid)) {
|
||||
PlotCluster current = plot.getCluster();
|
||||
if (current != null && current.equals(cluster)) {
|
||||
plot.unclaim();
|
||||
@ -513,7 +513,7 @@ public class Cluster extends SubCommand {
|
||||
DBFunc.removeInvited(cluster, uuid);
|
||||
MainUtil.sendMessage(player, Captions.CLUSTER_REMOVED, cluster.getName());
|
||||
for (final Plot plot : PlotQuery.newQuery().inWorld(player.getLocation().getWorldName())
|
||||
.ownedBy(uuid).asCollection()) {
|
||||
.ownedBy(uuid)) {
|
||||
PlotCluster current = plot.getCluster();
|
||||
if (current != null && current.equals(cluster)) {
|
||||
plot.unclaim();
|
||||
|
@ -58,7 +58,7 @@ public class Target extends SubCommand {
|
||||
Plot target = null;
|
||||
if (StringMan.isEqualIgnoreCaseToAny(args[0], "near", "nearest")) {
|
||||
int distance = Integer.MAX_VALUE;
|
||||
for (Plot plot : PlotQuery.newQuery().inWorld(location.getWorldName()).asCollection()) {
|
||||
for (Plot plot : PlotQuery.newQuery().inWorld(location.getWorldName())) {
|
||||
double current = plot.getCenterSynchronous().getEuclideanDistanceSquared(location);
|
||||
if (current < distance) {
|
||||
distance = (int) current;
|
||||
|
@ -173,7 +173,7 @@ public class Trim extends SubCommand {
|
||||
int bz = cbz << 4;
|
||||
CuboidRegion region =
|
||||
RegionUtil.createRegion(bx, bx + 511, bz, bz + 511);
|
||||
for (Plot plot : PlotQuery.newQuery().inWorld(world).asCollection()) {
|
||||
for (Plot plot : PlotQuery.newQuery().inWorld(world)) {
|
||||
Location bot = plot.getBottomAbs();
|
||||
Location top = plot.getExtendedTopAbs();
|
||||
CuboidRegion plotReg = RegionUtil
|
||||
|
@ -493,7 +493,7 @@ public class MainUtil {
|
||||
|
||||
PlotArea area = null;
|
||||
String alias = null;
|
||||
for (Plot plot : PlotQuery.newQuery().allPlots().asList()) {
|
||||
for (Plot plot : PlotQuery.newQuery().allPlots()) {
|
||||
int count = 0;
|
||||
if (!uuids.isEmpty()) {
|
||||
for (UUID uuid : uuids) {
|
||||
|
@ -34,19 +34,20 @@ import com.plotsquared.core.plot.Rating;
|
||||
import com.plotsquared.core.plot.flag.implementations.DoneFlag;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.util.MathMan;
|
||||
import javax.annotation.Nonnull;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@ -57,7 +58,7 @@ import java.util.stream.Stream;
|
||||
* The queries can be reused as no results are stored
|
||||
* in the query itself
|
||||
*/
|
||||
public final class PlotQuery {
|
||||
public final class PlotQuery implements Iterable<Plot> {
|
||||
|
||||
private final Collection<PlotFilter> filters = new LinkedList<>();
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
@ -381,16 +382,6 @@ public final class PlotQuery {
|
||||
return this.asList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform an action on each plot returned by the query
|
||||
*
|
||||
* @param consumer Plot consumer
|
||||
*/
|
||||
public void forEach(@Nonnull final Consumer<Plot> consumer) {
|
||||
Preconditions.checkNotNull(consumer, "Consumer may not be null");
|
||||
this.asCollection().forEach(consumer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the amount of plots contained in the query result
|
||||
*
|
||||
@ -429,5 +420,8 @@ public final class PlotQuery {
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull @Override public Iterator<Plot> iterator() {
|
||||
return this.asCollection().iterator();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user