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++) { for (int y = 0; y < blocks.length; y++) {
if (blocks[y] != null) { if (blocks[y] != null) {
BaseBlock block = blocks[y]; 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) { if (loc != null) {
int x; int x;
int z; 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 // center
RegionWrapper largest = plot.getLargestRegion(); RegionWrapper largest = plot.getLargestRegion();
x = (largest.maxX >> 1) - (largest.minX >> 1) + largest.minX; x = (largest.maxX >> 1) - (largest.minX >> 1) + largest.minX;
@ -1290,12 +1290,12 @@ public class Plot {
} else { } else {
// specific // specific
Location bot = plot.getBottomAbs(); Location bot = plot.getBottomAbs();
x = bot.getX() + loc.x; x = bot.getX() + loc.getX();
z = bot.getZ() + loc.z; 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) : (isLoaded() ? WorldUtil.IMP.getHighestBlock(plot.getWorldName(), x, z) + 1 : 63) :
loc.y; loc.getY();
return new Location(plot.getWorldName(), x, y, z); return new Location(plot.getWorldName(), x, y, z);
} }
// Side // Side

View File

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