mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-27 19:24:43 +02:00
Fix PlotRangeIterator
This commit is contained in:

committed by
Alexander Söderberg

parent
b4ea230ff1
commit
14ec7fb816
@ -2299,12 +2299,13 @@ public class Plot {
|
||||
continue;
|
||||
}
|
||||
boolean merge = true;
|
||||
PlotId bot = PlotId.of(current.getId().getX(), current.getId().getY());
|
||||
PlotId top = PlotId.of(current.getId().getX(), current.getId().getY());
|
||||
PlotId bot = current.getId();
|
||||
PlotId top = current.getId();
|
||||
while (merge) {
|
||||
merge = false;
|
||||
List<PlotId> ids = Lists.newArrayList((Iterable<? extends PlotId>) PlotId.PlotRangeIterator
|
||||
.range(PlotId.of(bot.getX(), bot.getY() - 1), PlotId.of(top.getX(), bot.getY() - 1)));
|
||||
Iterable<PlotId> ids = PlotId.PlotRangeIterator.range(
|
||||
PlotId.of(bot.getX(), bot.getY() - 1),
|
||||
PlotId.of(top.getX(), bot.getY() - 1));
|
||||
boolean tmp = true;
|
||||
for (PlotId id : ids) {
|
||||
Plot plot = this.area.getPlotAbs(id);
|
||||
@ -2316,8 +2317,9 @@ public class Plot {
|
||||
merge = true;
|
||||
bot = PlotId.of(bot.getX(), bot.getY() - 1);
|
||||
}
|
||||
ids = Lists.newArrayList((Iterable<? extends PlotId>) PlotId.PlotRangeIterator
|
||||
.range(PlotId.of(top.getX() + 1, bot.getY()), PlotId.of(top.getX() + 1, top.getY())));
|
||||
ids = PlotId.PlotRangeIterator.range(
|
||||
PlotId.of(top.getX() + 1, bot.getY()),
|
||||
PlotId.of(top.getX() + 1, top.getY()));
|
||||
tmp = true;
|
||||
for (PlotId id : ids) {
|
||||
Plot plot = this.area.getPlotAbs(id);
|
||||
@ -2329,8 +2331,9 @@ public class Plot {
|
||||
merge = true;
|
||||
top = PlotId.of(top.getX() + 1, top.getY());
|
||||
}
|
||||
ids = Lists.newArrayList((Iterable<? extends PlotId>) PlotId.PlotRangeIterator
|
||||
.range(PlotId.of(bot.getX(), top.getY() + 1), PlotId.of(top.getX(), top.getY() + 1)));
|
||||
ids = PlotId.PlotRangeIterator.range(
|
||||
PlotId.of(bot.getX(), top.getY() + 1),
|
||||
PlotId.of(top.getX(), top.getY() + 1));
|
||||
tmp = true;
|
||||
for (PlotId id : ids) {
|
||||
Plot plot = this.area.getPlotAbs(id);
|
||||
@ -2342,8 +2345,9 @@ public class Plot {
|
||||
merge = true;
|
||||
top = PlotId.of(top.getX(), top.getY() + 1);
|
||||
}
|
||||
ids = Lists.newArrayList((Iterable<? extends PlotId>) PlotId.PlotRangeIterator
|
||||
.range(PlotId.of(bot.getX() - 1, bot.getY()), PlotId.of(bot.getX() - 1, top.getY())));
|
||||
ids = PlotId.PlotRangeIterator.range(
|
||||
PlotId.of(bot.getX() - 1, bot.getY()),
|
||||
PlotId.of(bot.getX() - 1, top.getY()));
|
||||
tmp = true;
|
||||
for (PlotId id : ids) {
|
||||
Plot plot = this.area.getPlotAbs(id);
|
||||
|
@ -30,6 +30,7 @@ import com.plotsquared.core.location.Direction;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
/**
|
||||
* Plot (X,Y) tuples for plot locations
|
||||
@ -265,26 +266,25 @@ public final class PlotId {
|
||||
}
|
||||
|
||||
@Override public boolean hasNext() {
|
||||
if (this.x < this.end.getX()) {
|
||||
return true;
|
||||
} else if (this.x == this.end.getX()) {
|
||||
return this.y < this.end.getY();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
// end is fully included
|
||||
return this.x <= this.end.getX() && this.y <= this.end.getY();
|
||||
}
|
||||
|
||||
@Override public PlotId next() {
|
||||
if (!hasNext()) {
|
||||
throw new IndexOutOfBoundsException("The iterator has no more entries");
|
||||
throw new NoSuchElementException("The iterator has no more entries");
|
||||
}
|
||||
// increment *after* getting the result to include the minimum
|
||||
// the id to return
|
||||
PlotId result = PlotId.of(this.x, this.y);
|
||||
// first increase y, then x
|
||||
if (this.y == this.end.getY()) {
|
||||
this.x++;
|
||||
this.y = 0;
|
||||
} else {
|
||||
this.y++;
|
||||
}
|
||||
return PlotId.of(this.start.getX() + this.x, this.start.getY() + this.y);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nonnull @Override public Iterator<PlotId> iterator() {
|
||||
|
Reference in New Issue
Block a user