diff --git a/Core/src/main/java/com/plotsquared/core/location/BlockLoc.java b/Core/src/main/java/com/plotsquared/core/location/BlockLoc.java
index 78d2f781c..9c568b929 100644
--- a/Core/src/main/java/com/plotsquared/core/location/BlockLoc.java
+++ b/Core/src/main/java/com/plotsquared/core/location/BlockLoc.java
@@ -25,8 +25,14 @@
*/
package com.plotsquared.core.location;
+import com.plotsquared.core.util.StringMan;
+
public class BlockLoc {
+ public static final BlockLoc ZERO = new BlockLoc(0, 0, 0);
+ public static final BlockLoc MINY = new BlockLoc(0, Integer.MIN_VALUE, 0);
+ private static final BlockLoc MIDDLE = new BlockLoc(Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE);
+
private final int x;
private final int y;
private final int z;
@@ -34,6 +40,10 @@ public class BlockLoc {
private final float yaw;
private final float pitch;
+ public BlockLoc(int x, int y, int z) {
+ this(x, y, z, 0f, 0f);
+ }
+
public BlockLoc(int x, int y, int z, float yaw, float pitch) {
this.x = x;
this.y = y;
@@ -43,26 +53,31 @@ public class BlockLoc {
this.pitch = pitch;
}
- public BlockLoc(int x, int y, int z) {
- this(x, y, z, 0f, 0f);
- }
-
public static BlockLoc fromString(String string) {
- String[] parts = string.split(",");
-
- float yaw;
- float pitch;
- if (parts.length == 5) {
- yaw = Float.parseFloat(parts[3]);
- pitch = Float.parseFloat(parts[4]);
+ if (string == null || "side".equalsIgnoreCase(string)) {
+ return null;
+ } else if (StringMan.isEqualIgnoreCaseToAny(string, "center", "middle", "centre")) {
+ return MIDDLE;
} else {
- return new BlockLoc(0, 0, 0);
- }
- int x = Integer.parseInt(parts[0]);
- int y = Integer.parseInt(parts[1]);
- int z = Integer.parseInt(parts[2]);
+ String[] parts = string.split(",");
- return new BlockLoc(x, y, z, yaw, pitch);
+ float yaw;
+ float pitch;
+ if (parts.length == 5) {
+ yaw = Float.parseFloat(parts[3]);
+ pitch = Float.parseFloat(parts[4]);
+ } else if (parts.length == 3) {
+ yaw = 0;
+ pitch = 0;
+ } else {
+ return ZERO;
+ }
+ int x = Integer.parseInt(parts[0]);
+ int y = Integer.parseInt(parts[1]);
+ int z = Integer.parseInt(parts[2]);
+
+ return new BlockLoc(x, y, z, yaw, pitch);
+ }
}
@Override
@@ -88,12 +103,12 @@ public class BlockLoc {
}
BlockLoc other = (BlockLoc) obj;
return this.getX() == other.getX() && this.getY() == other.getY() && this.getZ() == other
- .getZ();
+ .getZ() && this.getYaw() == other.getYaw() && this.getPitch() == other.getPitch();
}
@Override
public String toString() {
- if (this.getX() == 0 && this.getY() == 0 && this.getZ() == 0) {
+ if (this.getX() == 0 && this.getY() == 0 && this.getZ() == 0 && this.getYaw() == 0 && this.getPitch() == 0) {
return "";
}
return this.getX() + "," + this.getY() + ',' + this.getZ() + ',' + this.getYaw() + ','
diff --git a/Core/src/main/java/com/plotsquared/core/plot/Plot.java b/Core/src/main/java/com/plotsquared/core/plot/Plot.java
index f3e6519d2..9982681be 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/Plot.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/Plot.java
@@ -1477,7 +1477,7 @@ public class Plot {
*/
public void setHome(BlockLoc location) {
Plot plot = this.getBasePlot(false);
- if (location != null && new BlockLoc(0, 0, 0).equals(location)) {
+ if (BlockLoc.ZERO.equals(location) || BlockLoc.MINY.equals(location)) {
return;
}
plot.getSettings().setPosition(location);
@@ -2149,8 +2149,9 @@ public class Plot {
}
/**
- * Gets the set home location or 0,0,0 if no location is set
+ * Gets the set home location or 0,Integer#MIN_VALUE,0 if no location is set
* - Does not take the default home location into account
+ * - PlotSquared will internally find the correct place to teleport to if y = Integer#MIN_VALUE when teleporting to the plot.
*
* @return home location
*/
diff --git a/Core/src/main/java/com/plotsquared/core/plot/PlotSettings.java b/Core/src/main/java/com/plotsquared/core/plot/PlotSettings.java
index 76e01047f..6c4667cc8 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/PlotSettings.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/PlotSettings.java
@@ -107,7 +107,7 @@ public class PlotSettings {
public BlockLoc getPosition() {
if (this.position == null) {
- return new BlockLoc(0, 0, 0);
+ return BlockLoc.MINY;
}
return this.position;
}