Make PlotLoc's immutable

This commit is contained in:
Sauilitired 2019-04-04 18:26:10 +02:00
parent 69b05932eb
commit 7e401a83cf
No known key found for this signature in database
GPG key ID: C0207FF7EA146678
3 changed files with 20 additions and 28 deletions

View file

@ -223,7 +223,7 @@ public class BukkitChunkManager extends ChunkManager {
for (int y = 0; y < blocks.length; y++) {
if (blocks[y] != null) {
BaseBlock block = blocks[y];
queue.setBlock(loc.x, y, loc.z, block);
queue.setBlock(loc.getX(), y, loc.getZ(), block);
}
}
}

View file

@ -1282,7 +1282,7 @@ public class Plot {
if (loc != null) {
int x;
int z;
if (loc.x == Integer.MAX_VALUE && loc.z == Integer.MAX_VALUE) {
if (loc.getX() == Integer.MAX_VALUE && loc.getZ() == Integer.MAX_VALUE) {
// center
RegionWrapper largest = plot.getLargestRegion();
x = (largest.maxX >> 1) - (largest.minX >> 1) + largest.minX;
@ -1290,12 +1290,12 @@ public class Plot {
} else {
// specific
Location bot = plot.getBottomAbs();
x = bot.getX() + loc.x;
z = bot.getZ() + loc.z;
x = bot.getX() + loc.getX();
z = bot.getZ() + loc.getZ();
}
int y = loc.y < 1 ?
int y = loc.getY() < 1 ?
(isLoaded() ? WorldUtil.IMP.getHighestBlock(plot.getWorldName(), x, z) + 1 : 63) :
loc.y;
loc.getY();
return new Location(plot.getWorldName(), x, y, z);
}
// Side

View file

@ -1,27 +1,22 @@
package com.github.intellectualsites.plotsquared.plot.object;
import com.github.intellectualsites.plotsquared.plot.util.StringMan;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.Nullable;
public class PlotLoc {
@Getter @RequiredArgsConstructor public class PlotLoc {
public int x;
public int y;
public int z;
private final int x;
private final int y;
private final int z;
public PlotLoc(int x, int z) {
this.x = x;
this.y = -1;
this.z = z;
this(x, -1, z);
}
public PlotLoc(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public static PlotLoc fromString(String input) {
if ("side".equalsIgnoreCase(input)) {
@Nullable public static PlotLoc fromString(final String input) {
if (input == null || "side".equalsIgnoreCase(input)) {
return null;
} else if (StringMan.isEqualIgnoreCaseToAny(input, "center", "middle")) {
return new PlotLoc(Integer.MAX_VALUE, Integer.MAX_VALUE);
@ -44,7 +39,7 @@ public class PlotLoc {
}
@Override public int hashCode() {
int prime = 31;
final int prime = 31;
int result = 1;
result = (prime * result) + this.x;
result = (prime * result) + this.y;
@ -59,17 +54,14 @@ public class PlotLoc {
return String.format("%d,%d,%d", x, y, z);
}
@Override public boolean equals(Object obj) {
@Override public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
if (obj == null || getClass() != obj.getClass()) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
PlotLoc other = (PlotLoc) obj;
final PlotLoc other = (PlotLoc) obj;
return (this.x == other.x) && (this.y == other.y) && (this.z == other.z);
}
}