mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 05:06:44 +01:00
Add PlotRangeIterator for the many places where it'll be used. All one of them, in fact. This was not a waste of time. I am very happy I did this. This was worthwhile. Yup.
This commit is contained in:
parent
39fdaa367c
commit
5360df6012
@ -154,7 +154,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
|||||||
case "ITEM_FRAME":
|
case "ITEM_FRAME":
|
||||||
this.x = Math.floor(this.getX());
|
this.x = Math.floor(this.getX());
|
||||||
this.y = Math.floor(this.getY());
|
this.y = Math.floor(this.getY());
|
||||||
this.z = Math.floor(this.z);
|
this.z = Math.floor(this.getZ());
|
||||||
ItemFrame itemFrame = (ItemFrame) entity;
|
ItemFrame itemFrame = (ItemFrame) entity;
|
||||||
this.dataByte = getOrdinal(Rotation.values(), itemFrame.getRotation());
|
this.dataByte = getOrdinal(Rotation.values(), itemFrame.getRotation());
|
||||||
this.stack = itemFrame.getItem().clone();
|
this.stack = itemFrame.getItem().clone();
|
||||||
@ -162,7 +162,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
|||||||
case "PAINTING":
|
case "PAINTING":
|
||||||
this.x = Math.floor(this.getX());
|
this.x = Math.floor(this.getX());
|
||||||
this.y = Math.floor(this.getY());
|
this.y = Math.floor(this.getY());
|
||||||
this.z = Math.floor(this.z);
|
this.z = Math.floor(this.getZ());
|
||||||
Painting painting = (Painting) entity;
|
Painting painting = (Painting) entity;
|
||||||
Art art = painting.getArt();
|
Art art = painting.getArt();
|
||||||
this.dataByte = getOrdinal(BlockFace.values(), painting.getFacing());
|
this.dataByte = getOrdinal(BlockFace.values(), painting.getFacing());
|
||||||
@ -409,7 +409,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
|||||||
Location location = lived.getLeashHolder().getLocation();
|
Location location = lived.getLeashHolder().getLocation();
|
||||||
this.lived.leashX = (short) (this.getX() - location.getBlockX());
|
this.lived.leashX = (short) (this.getX() - location.getBlockX());
|
||||||
this.lived.leashY = (short) (this.getY() - location.getBlockY());
|
this.lived.leashY = (short) (this.getY() - location.getBlockY());
|
||||||
this.lived.leashZ = (short) (this.z - location.getBlockZ());
|
this.lived.leashZ = (short) (this.getZ() - location.getBlockZ());
|
||||||
}
|
}
|
||||||
EntityEquipment equipment = lived.getEquipment();
|
EntityEquipment equipment = lived.getEquipment();
|
||||||
this.lived.equipped = equipment != null;
|
this.lived.equipped = equipment != null;
|
||||||
|
@ -69,7 +69,7 @@ public class TeleportEntityWrapper extends EntityWrapper {
|
|||||||
this.oldLocation = oldLocation.clone();
|
this.oldLocation = oldLocation.clone();
|
||||||
this.oldLocation.setX(this.getX());
|
this.oldLocation.setX(this.getX());
|
||||||
this.oldLocation.setY(this.getY());
|
this.oldLocation.setY(this.getY());
|
||||||
this.oldLocation.setZ(this.z);
|
this.oldLocation.setZ(this.getZ());
|
||||||
|
|
||||||
this.gravityOld = this.getEntity().hasGravity();
|
this.gravityOld = this.getEntity().hasGravity();
|
||||||
this.getEntity().setGravity(false);
|
this.getEntity().setGravity(false);
|
||||||
|
@ -298,16 +298,15 @@ public class Auto extends SubCommand {
|
|||||||
PlotId end = PlotId.of(start.getX() + size_x - 1, start.getY() + size_z - 1);
|
PlotId end = PlotId.of(start.getX() + size_x - 1, start.getY() + size_z - 1);
|
||||||
if (plotarea.canClaim(player, start, end)) {
|
if (plotarea.canClaim(player, start, end)) {
|
||||||
plotarea.setMeta("lastPlot", start);
|
plotarea.setMeta("lastPlot", start);
|
||||||
for (int i = start.getX(); i <= end.getX(); i++) {
|
|
||||||
for (int j = start.getY(); j <= end.getY(); j++) {
|
for (final PlotId plotId : PlotId.PlotRangeIterator.range(start, end)) {
|
||||||
Plot plot = plotarea.getPlotAbs(PlotId.of(i, j));
|
final Plot plot = plotarea.getPlot(plotId);
|
||||||
boolean teleport = i == end.getX() && j == end.getY();
|
if (plot == null) {
|
||||||
if (plot == null) {
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
plot.claim(player, teleport, null);
|
|
||||||
}
|
}
|
||||||
|
plot.claim(player, plotId.equals(end), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<PlotId> plotIds = MainUtil.getPlotSelectionIds(start, end);
|
ArrayList<PlotId> plotIds = MainUtil.getPlotSelectionIds(start, end);
|
||||||
final PlotId pos1 = plotIds.get(0);
|
final PlotId pos1 = plotIds.get(0);
|
||||||
final PlotAutoMergeEvent mergeEvent = this.eventDispatcher
|
final PlotAutoMergeEvent mergeEvent = this.eventDispatcher
|
||||||
|
@ -92,7 +92,7 @@ public final class PlotLoc {
|
|||||||
int result = 1;
|
int result = 1;
|
||||||
result = (prime * result) + this.getX();
|
result = (prime * result) + this.getX();
|
||||||
result = (prime * result) + this.getY();
|
result = (prime * result) + this.getY();
|
||||||
result = (prime * result) + this.z;
|
result = (prime * result) + this.getZ();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,6 +111,7 @@ public final class PlotLoc {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final PlotLoc other = (PlotLoc) obj;
|
final PlotLoc other = (PlotLoc) obj;
|
||||||
return (this.getX() == other.getX()) && (this.getY() == other.getY()) && (this.z == other.z);
|
return (this.getX() == other.getX()) && (this.getY() ==
|
||||||
|
other.getY()) && (this.getZ() == other.getZ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plot (X,Y) tuples for plot locations
|
* Plot (X,Y) tuples for plot locations
|
||||||
@ -242,4 +243,53 @@ public class PlotId {
|
|||||||
return this.hash;
|
return this.hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static final class PlotRangeIterator implements Iterator<PlotId>, Iterable<PlotId> {
|
||||||
|
|
||||||
|
private final PlotId start;
|
||||||
|
private final PlotId end;
|
||||||
|
|
||||||
|
private int x;
|
||||||
|
private int y;
|
||||||
|
|
||||||
|
private PlotRangeIterator(@Nonnull final PlotId start, @Nonnull final PlotId end) {
|
||||||
|
this.start = start;
|
||||||
|
this.end = end;
|
||||||
|
this.x = this.start.getX();
|
||||||
|
this.y = this.start.getY();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PlotRangeIterator range(@Nonnull final PlotId start, @Nonnull final PlotId end) {
|
||||||
|
return new PlotRangeIterator(start, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public PlotId next() {
|
||||||
|
if (!hasNext()) {
|
||||||
|
throw new IndexOutOfBoundsException("The iterator has no more entries");
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull @Override public Iterator<PlotId> iterator() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user